【问题标题】:Issues connecting Google Data Studio to BigQuery with window function使用窗口函数将 Google Data Studio 连接到 BigQuery 的问题
【发布时间】:2022-11-03 22:43:23
【问题描述】:

我有一个复杂的 BigQuery 视图,它从各种连接的 Google 表格中提取数据以及 BigQuery 中的计算数据。我正在尝试在 Data Studio 中的视图之上创建一个仪表板。

我在让我的数据显示在 Data Studio 中并将其隔离到 BigQuery 基础视图的特定部分时遇到问题。

我有一个较早的问题,this question 已回答。

我正在有效地运行该帖子中的查询,保存为视图,然后连接到 Data Studio。

SELECT order_id, order_date,
  ARRAY_AGG(line_item) AS line_items
FROM (
  SELECT order_id, order_date,
      STRUCT(item_sku,
      item_quantity,
      item_subtotal,
      cost.product_cost) AS line_item
  FROM `order_data_table`, UNNEST(line_items) AS items
  JOIN `price_history_table` AS cost
  ON items.item_sku = cost.sku AND effective_date < order_date 
  QUALIFY 1 = ROW_NUMBER() OVER(PARTITION BY order_id, order_date, item_sku ORDER BY effective_date DESC)
)
GROUP BY order_id, order_date   

此查询使用窗口函数,正是这导致了我的问题。每当我尝试连接到数据时,我都会得到这个。

随着细节

数据洞察无法连接到您的数据集。

无法从底层数据集中获取数据

从查询中删除以下行可以解决问题,但是我没有所需的数据。

QUALIFY 1 = ROW_NUMBER() OVER(PARTITION BY order_id, order_date, item_sku ORDER BY effective_date DESC)

这是否会破坏 Data Studio?我可以避免吗?我可以用不使用窗口函数的不同方式解决原始问题吗?

更新

好像有一个issue in Data Studio where it does not support the QUALIFY function.

关于如何在不使用 QUALIFY 的情况下重写此查询的任何建议?

【问题讨论】:

  • 如果您直接在 BigQuery 上运行查询,它是否有效?您是否检查过 BigQuery 中的查询历史记录是否有任何错误?
  • 是的,在 BigQuery 中一切正常。从 Data Studio 连接时也没有记录错误。

标签: google-bigquery google-data-studio


【解决方案1】:

我已经通过删除 QUALIFY 函数并将我的查询重写为这个来解决这个问题

SELECT order_id, order_date,
  ARRAY_AGG(line_item) AS line_items
FROM (
  SELECT order_id, order_date,
      STRUCT(item_sku,
      item_quantity,
      item_subtotal,
      cost.product_cost,
      ROW_NUMBER() OVER(PARTITION BY order_id, order_date, item_sku ORDER BY effective_date DESC) AS row_num) AS line_item
  FROM `order_data_table`, UNNEST(line_items) AS items
  JOIN `price_history_table` AS cost
  ON items.item_sku = cost.sku AND effective_date < order_date 
)
WHERE line_item.row_num = 1
GROUP BY order_id, order_date 

【讨论】:

    【解决方案2】:

    the issue 中所述,解决方法是始终包含 WHERE 子句.没有它,Data Studio 会感到困惑并失败。

    我遇到了同样的问题,将WHERE TRUE 添加到我的查询中修复了它,而无需任何其他重写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 2019-03-16
      • 2022-08-02
      • 2021-10-19
      • 1970-01-01
      • 2017-01-07
      • 1970-01-01
      相关资源
      最近更新 更多