BigQuery: SPLIT() returns only one value

前端 未结 5 1244
时光说笑
时光说笑 2020-12-05 11:35

I have a page URL column components of which are delimited by /. I tried to run the SPLIT() function in BigQuery but it only gives the first value.

5条回答
  •  有刺的猬
    2020-12-05 12:25

    in standard sql, you can use the following functions:

    array[OFFSET(zero_based_offset)]
    array[ORDINAL(one_based_ordinal)]
    

    so

    SELECT SPLIT(path, '/')[OFFSET(1)] part2,
           SPLIT(path, '/')[ORDINAL(2)] part2_again,
           SPLIT(path, '/')[ORDINAL(3)] part3
    FROM (SELECT "/a/b/aaaa?c" path)
    
    part2   part2_again part3    
    a       a           b
    

    part1 in this case, is empty string (before the first slash)

提交回复
热议问题