google-bigquery - 使用窗口函数将 Google Data Studio 连接到 BigQuery 时出现问题

标签 google-bigquery looker-studio

我有一个复杂的 BigQuery View ,它从各种连接的 Google 表格中提取数据,并从 BigQuery 中计算出数据。我正在尝试在 Data Studio 中的 View 顶部创建一个仪表板。

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

我之前遇到了一个问题,this question 已回答该问题.

我正在有效地运行该帖子中的查询,保存为 View ,然后连接到 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   

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

Data Set Configuration Error

详情如下

Data Studio cannot connect to your data set.

Failed to fetch data from the underlying data set

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

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 的情况下重写此查询的任何建议?

最佳答案

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

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

关于google-bigquery - 使用窗口函数将 Google Data Studio 连接到 BigQuery 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73637505/

相关文章:

Google Data Studio 中的 REGEX RE2 提取 - REGEX_EXTRACT

google-maps - 为什么 Google map 不使用 Google Data Studio 从 Google 表格填充所有邮政编码?

looker-studio - 连接器 list 未在 DataStudio 中验证

python - 如何从仪表板调用 python 函数?

java - Bigquery 流 API 返回 "unsupported content with type"

google-bigquery - 如何使用 StackDriver API v2 查询 BigQuery 使用情况?

google-bigquery - 从查询创建表,同时保留原始架构

google-bigquery - 哎呀!使用保留字来命名列

regex - 使用 Google RE2 Regexp for Data Studio 从 URL 中提取域名

sql - 在bigquery sql中查找最新日期的数据总和