Google BigQuery - Updating a nested repeated field

后端 未结 2 544
误落风尘
误落风尘 2020-12-20 06:46

I am trying to update the hits.page.pagePath field in the Google Analytics export in BigQuery, however i\'m unable to unnest the field using the method outlined in the docum

相关标签:
2条回答
  • 2020-12-20 07:07

    This should help get you started. You need to include everything else from hits in order to perform the update, including the nested page.

    UPDATE `you_dataset.tablename`
    SET hits = ARRAY(
      SELECT AS STRUCT * REPLACE (
        (SELECT AS STRUCT page.* REPLACE ('foo' AS pagePath)) AS page
      )
      FROM UNNEST(hits) as pagePath
    )
    WHERE fullVisitorID like "%1%"
    
    0 讨论(0)
  • 2020-12-20 07:21

    Below is for BigQuery Standard SQL

    UPDATE `project-name.datasetId.ga_sessions_yyyymmdd`
    SET hits =  ARRAY(
        SELECT AS STRUCT * REPLACE(
          (SELECT AS STRUCT * 
            REPLACE('Your New pagePath' AS pagePath) 
            FROM UNNEST([page])
          ) AS page) 
        FROM UNNEST(hits)
      ) 
    WHERE fullVisitorID like "%1%"    
    

    As you can see in above example you would replace pagePath with string 'Your New pagePath'
    Of course in reality you would want to have some logic here - so replace that part to whatever logic you need - like for example you would need to UPPER whole string - you would use something like below

            REPLACE(UPPER(pagePath) AS pagePath) 
    
    0 讨论(0)
提交回复
热议问题