无法识别的名称:在 BigQuery 中使用 UNNEST WHERE 时
Unrecognised name: when using UNNEST WHERE in BigQuery
我正在尝试按照 this blog 在 BigQuery 中的 unnest 期间进行过滤,但我无法使模式正常工作。
博客中的可重现示例效果非常好。
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"
当我自己尝试这个时 table 我收到错误 Unrecognised name:
。我试图在玩具 table、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
... elements of some_numbers can be extracted so that I can unnest a nested array without increasing the number of rows.
考虑下面的“修复”
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
有输出
我正在尝试按照 this blog 在 BigQuery 中的 unnest 期间进行过滤,但我无法使模式正常工作。
博客中的可重现示例效果非常好。
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"
当我自己尝试这个时 table 我收到错误 Unrecognised name:
。我试图在玩具 table、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 |
... elements of some_numbers can be extracted so that I can unnest a nested array without increasing the number of rows.
考虑下面的“修复”
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
有输出