[英]BigQuery query doesn't work with UNNEST()
I'm trying to search on StackOverflow data through BigQuery by letting this query match a string pattern on answers and by filtering relevant question answers by tags.我正在尝试通过 BigQuery 搜索 StackOverflow 数据,方法是让此查询与答案中的字符串模式相匹配,并通过标签过滤相关问题的答案。
WITH question_answers_join AS (
SELECT *
FROM (
SELECT id, creation_date, title
, (SELECT AS STRUCT body b
FROM `bigquery-public-data.stackoverflow.posts_answers`
WHERE a.id=parent_id
) answers
, SPLIT(tags, '|') tags
FROM `bigquery-public-data.stackoverflow.posts_questions` a
)
)SELECT *
FROM question_answers_join
WHERE 'google-bigquery' IN UNNEST(tags)
AND REGEXP_CONTAINS(answers.b, r"hello")
ORDER BY RAND()
LIMIT 100
however, I get this error:但是,我收到此错误:
Scalar subquery produced more than one element
标量子查询产生了不止一个元素
what is it referring to?它指的是什么? How can I fix this?
我怎样才能解决这个问题?
Below is for BigQuery Standard SQL以下是 BigQuery 标准 SQL
#standardSQL
WITH question_answers_join AS (
SELECT *
FROM (
SELECT id, creation_date, title
, ARRAY(SELECT body /* this line was the reason for error */
FROM `bigquery-public-data.stackoverflow.posts_answers`
WHERE a.id=parent_id
) answers
, SPLIT(tags, '|') tags
FROM `bigquery-public-data.stackoverflow.posts_questions` a
)
)
SELECT *
FROM question_answers_join
WHERE 'google-bigquery' IN UNNEST(tags)
AND EXISTS (
SELECT 1
FROM UNNEST(answers) answer
WHERE REGEXP_CONTAINS(answer, r"hello")
)
ORDER BY RAND()
LIMIT 100
I think, it is easy to just compare above with your original query to see the differences (hint: there are just two of them).我认为,只需将上面的内容与您的原始查询进行比较就可以很容易地看到差异(提示:只有两个)。 First difference is the actual reason for the error you saw.
第一个区别是您看到的错误的实际原因。 Second difference is to reflect changes introduced by first one
第二个区别是反映第一个引入的变化
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.