无法识别的名称:在 BigQuery 中使用 UNNEST WHERE 时
Posted
技术标签:
【中文标题】无法识别的名称:在 BigQuery 中使用 UNNEST WHERE 时【英文标题】:Unrecognised name: when using UNNEST WHERE in BigQuery 【发布时间】:2021-02-26 17:49:54 【问题描述】:我正在尝试在 BigQuery 中按照 this blog 进行过滤,但我无法使该模式正常工作。
博客中的可重现示例效果非常好。
SELECT event_name, event_timestamp, user_pseudo_id,
event_params
FROM `firebase-public-project.analytics_153293282.events_20181003`
WHERE event_name = "level_complete_quickplay"
SELECT event_name, event_timestamp, user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params)
WHERE key = "value") AS score
FROM `firebase-public-project.analytics_153293282.events_20181003`
WHERE event_name = "level_complete_quickplay"
当我在自己的桌子上尝试此操作时,我收到错误 Unrecognised name:
。我试图在玩具桌nested_seq
中重现错误。
WITH sequences AS (
SELECT
[0, 1, 1, 2, 3, 5] AS some_numbers
UNION ALL SELECT [2, 4, 8, 16, 32] AS some_numbers
UNION ALL SELECT [5, 10] AS some_numbers
),
-- table containing repeated record
nested_seq AS (
SELECT
some_numbers,
some_numbers[OFFSET(1)] AS offset_1,
some_numbers[ORDINAL(1)] AS ordinal_1
FROM sequences
)
-- transformation to extract single value from array
SELECT *
FROM nested_seq
LEFT JOIN (SELECT
some_numbers
FROM UNNEST(some_numbers)
WHERE some_numbers = 2)
-- Unrecognized name: some_numbers at [21:19]
我期望some_numbers
的元素可以被提取,这样我就可以在不增加行数的情况下取消嵌套数组。
Row | some_numbers | offset_1 | ordinal_1 |
---|---|---|---|
1 | 2 | 1 | 0 |
2 | 2 | 4 | 2 |
3 | null | 10 | 5 |
【问题讨论】:
【参考方案1】:... some_numbers 的元素可以被提取出来,这样我就可以在不增加行数的情况下取消嵌套数组。
考虑下面的“修复”
WITH sequences AS (
SELECT
[0, 1, 1, 2, 3, 5] AS some_numbers
UNION ALL SELECT [2, 4, 8, 16, 32] AS some_numbers
UNION ALL SELECT [5, 10] AS some_numbers
)
SELECT # some_numbers,
(SELECT some_number
FROM t.some_numbers some_number
WHERE some_number = 2
) some_number,
some_numbers[OFFSET(1)] AS offset_1,
some_numbers[ORDINAL(1)] AS ordinal_1
FROM sequences t
有输出
【讨论】:
以上是关于无法识别的名称:在 BigQuery 中使用 UNNEST WHERE 时的主要内容,如果未能解决你的问题,请参考以下文章
无法识别的名称:使用 bigquery 标准 sql 进行嵌套查询时出错
在将 Google BigQuery 作为源数据库的 Metabase 中使用字段过滤器时出现无法识别的名称
BigQuery 中出现“无法识别的名称:m01_order_datetime_gmt0”错误