【问题标题】:BigQuery: Querying repeated fieldsBigQuery:查询重复字段
【发布时间】:2017-09-25 00:40:37
【问题描述】:

我正在尝试使用以下查询来获取事件名称等于的行:EventGamePlayed、EventGetUserBasicInfos 或 EventGetUserCompleteInfos

select *
from [com_test_testapp_ANDROID.app_events_20170426]
where event_dim.name in ("EventGamePlayed", "EventGetUserBasicInfos", "EventGetUserCompleteInfos");

我收到以下错误:无法查询重复字段 event_dim.name 和 user_dim.user_properties.value.index 的叉积。

是否可以通过没有扁平化的结果来使其工作? 另外,我不确定为什么错误是在谈论“user_dim.user_properties.value.index”字段。

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    错误是由于SELECT * 引起的,其中包括所有列。与其使用旧版 SQL,不如尝试使用 standard SQL,它不会出现重复字段交叉产品的问题:

    #standardSQL
    SELECT *
    FROM com_test_testapp_ANDROID.app_events_20170426
    CROSS JOIN UNNEST(event_dim) AS event_dim
    WHERE event_dim.name IN ("EventGamePlayed", "EventGetUserBasicInfos", "EventGetUserCompleteInfos");
    

    您可以在Working with Arrays topic 中阅读有关使用重复字段/数组的更多信息。如果您习惯使用旧版 SQL,可以在 migration guide 中了解 BigQuery 中旧版 SQL 和标准 SQL 之间的区别。

    【讨论】:

    • 这将为数组的每个元素返回一行。把它想象成一个for 循环遍历每一行的数组,例如CROSS JOIN UNNEST(event_dim) AS x 就像 for (x : event_dim) { ... }
    猜你喜欢
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多