将ORDER BY语句添加到查询而不展平结果会导致“无法查询重复字段的叉积”

时间:2014-12-17 21:14:33

标签: google-bigquery

Query: 
    "SELECT * FROM [table] ORDER BY id DESC LIMIT 10"
    AllowLargeResults = true
    FlattenResults = false

table schema:
    [
        {
            "name": "id",
            "type": "STRING",
            "mode": "NULLABLE"
        },
        {
            "name": "repeated_field_1",
            "type": "STRING",
            "mode": "REPEATED"
        },
        {
            "name": "repeated_field_2",
            "type": "STRING",
            "mode": "REPEATED"
        }
    ]

查询" SELECT * FROM [table] LIMIT 10"工作得很好。当我添加order by子句时,我收到此错误,即使order by没有提到重复字段。

有没有办法让这项工作?

1 个答案:

答案 0 :(得分:2)

ORDER BY子句会导致BigQuery自动展平查询的输出,导致您的查询尝试生成repeated_field_1和repeated_field_2的叉积。

如果您不关心保留字段的重复性,则可以明确FLATTEN这两个字段,这将导致您的查询生成原始查询抱怨的交叉产品。< / p>

SELECT *
FROM FLATTEN(FLATTEN([table], repeated_field_1), repeated_field_2)
ORDER BY id DESC
LIMIT 10

除此之外,我对ORDER BY的查询都没有很好的解决方法,也输出重复的字段。

另请参阅:BigQuery flattens result when selecting into table with GROUP BY even with “noflatten_results” flag on