【问题标题】:Unexpected behavior nested fields Big Query - Data Studio意外行为嵌套字段 Big Query - 数据洞察
【发布时间】:2020-05-14 23:56:36
【问题描述】:

我在 BigQuery 视图中有以下数据:

当我想将此数据显示到 datastudio 时,我遇到了问题(可能是由于嵌套字段):

  • 数据以不同的价格/指数日期出现两次
  • 索引日期未正确显示时间 (HH:MM) 但卡住了 00:00

我。我想将每个项目的一行、价格和 index_date 和 index_date 显示为列,并包含第一行、每个字段的第一个数据、第二行第二个数据等。

   Subject     Price    Index_date
1. Maison      95000    2019-10-28 
2. Maison      80000    2019-12-27

二。我希望 index_date 与 BigQuery 中的数据一致(具有相同的 hh:mm)

谢谢!

编辑:查询结果的架构

[
  {
    "user_id": "6c65bb12-2441-465d-975c-81ba2b1a8d23",
    "type": "private",
    "zipcode": "69870",
    "city": "Poule-les-Echarmeaux",
    "region_name": "Rhône-Alpes",
    "department_name": "Rhône",
    "price": [
      "95000",
      "80000"
    ],
    "index_date": [
      "2019-10-28 21:46:00 UTC",
      "2019-12-27 22:12:47 UTC"
    ],
    "subject": "Maison de campagne",
    "body": "text",
    "list_id": "81711968"
  }
]

【问题讨论】:

  • 您能分享一下您的表的架构吗?在不知道架构的情况下很难构造查询。

标签: nested google-bigquery google-data-studio


【解决方案1】:

据我所知,您有 2 个不同的数组,分别称为 price 和 index_date。 实际上,它们应该在一个结构中,并且应该只有 1 个数组。这是一个适用于您的用例的查询:

SELECT subject, index_date, price
FROM table,
UNNEST(price) as price_item WITH OFFSET price_offset
UNNEST(index_date) as date WITH OFFSET date_offset
WHERE price_offset = date_offset

这里有一个带有示例数据的示例解决方案:

with table as (
  select 'a' subject, [1,2] price, [3,4] date union all
  select 'b', [5,6], [7,8]
)
select subject, price_item, date_item
from table,
unnest(price) as price_item with offset price_offset,
unnest(date) as date_item with offset date_offset
where price_offset = date_offset

输入表:

这是输出:

对于日期问题,您应该在 DataStudio 中修复它。您应该单击 index_date 列附近的日期图标并将其更改为 datetime from date。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-09
    • 2017-10-23
    • 2019-11-15
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多