我在BigQuery中擁有數百萬行的表,並且我想將adx_catg_id列拆分爲多個新列。請注意,adx_catg_id列包含以空格分隔的任意數量的單詞。將字符串拆分爲具有bigquery的多列
下面的查詢示例可以將adx_catg_id拆分爲多個列,如果該字符串只包含少於五個單詞的話。我可以擴展它來支持更多的單詞,但我需要自動化它。
SELECT
TS, str0, str2, str4, str6, str7
from
(select REGEXP_EXTRACT(str5, r'^(.*) .*') as str7
from
(select SUBSTR (str5, LENGTH(REGEXP_EXTRACT(str5, r'^(.*) .*')) + 2, LENGTH(str5)) as str6
from
(select REGEXP_EXTRACT(str3, r'^(.*) .*') as str5
from
(select SUBSTR (str3, LENGTH(REGEXP_EXTRACT(str3, r'^(.*) .*')) + 2, LENGTH(str3)) as str4
from
(select REGEXP_EXTRACT(str1, r'^(.*) .*') as str3
from
(select SUBSTR (str1, LENGTH(REGEXP_EXTRACT(str1, r'^(.*) .*')) + 2, LENGTH(str1)) as str2
from
(select REGEXP_EXTRACT(TS, r'^(.*) .*') as str1
from
(select SUBSTR(TS, LENGTH(REGEXP_EXTRACT(TS, r'^(.*) .*')) + 2,LENGTH(TS)) as str0
from
(select adx_catg_id TS from [mydataset.conversions])
))))))))
如何循環上述查詢以根據字符串長度生成新列中的所有單詞?
的可能的複製[BigQuery的:SPLIT()返回只有一個值(https://stackoverflow.com/questions/27060396/bigquery-split-returns-only-one-value) – marengaz