BigQuery: SPLIT() returns only one value

前端 未结 5 1289
时光说笑
时光说笑 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:18

    2018 standardSQL update:

    #standardSQL
    SELECT SPLIT(path, '/')[OFFSET(0)] part1,
           SPLIT(path, '/')[OFFSET(1)] part2,
           SPLIT(path, '/')[OFFSET(2)] part3
    FROM (SELECT "/a/b/aaaa?c" path)
    

    Now I understand you want them in different columns.

    An alternative to the query you provided:

    SELECT FIRST(SPLIT(path, '/')) part1,
           NTH(2, SPLIT(path, '/')) part2,
           NTH(3, SPLIT(path, '/')) part3
    FROM (SELECT "/a/b/aaaa?c" path)
    

    NTH(X, SPLIT(s)) will provide the Xth value from the SPLIT. FIRST(s) is the same as NTH(1, s)

提交回复
热议问题