计算嵌套字段而不丢失BigQuery中的导出架构

时间:2019-06-10 21:12:25

标签: google-analytics google-bigquery enhanced-ecommerce

对字段进行计算会导致BigQuery中原始导出模式的丢失。

我有一个标准的增强型电子商务模式,并且想要将transactionRevenue更改为其他货币。我想保留一般的导出架构结构。计算的字段“ transactionRevenueNewCurrency”应位于hits.transaction.transactionRevenueNewCurrency中。

#standardSQL
SELECT
s.*,
ARRAY(SELECT  COALESCE( x.transaction.transactionRevenue*1.17,0)
        FROM UNNEST(hits) AS x) AS transactionRevenueNewCurrency
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*` as s , UNNEST(hits) as h
WHERE
_TABLE_SUFFIX BETWEEN '20160801' AND '20160831'
AND transaction.transactionRevenue >0
LIMIT 10000

新字段将附加到会话中,而不是每次匹配。

1 个答案:

答案 0 :(得分:2)

以下是用于BigQuery标准SQL

#standardSQL
SELECT * REPLACE(
  ARRAY(
    SELECT AS STRUCT * REPLACE(
      (SELECT AS STRUCT * REPLACE(
        COALESCE(CAST(transactionRevenue * 1.17 AS INT64), 0
        ) AS transactionRevenue)
       FROM UNNEST([transaction])
      ) AS transaction)
    FROM UNNEST(hits) hit
  ) AS hits)
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*` 
WHERE _TABLE_SUFFIX BETWEEN '20160801' AND '20160831'