从 Google Ads BigQuery 数据传输中提取/取消嵌套数组

Posted

技术标签:

【中文标题】从 Google Ads BigQuery 数据传输中提取/取消嵌套数组【英文标题】:Extract/ Unnest Arrays from Google Ads BigQuery Data Transfer 【发布时间】:2021-08-12 09:31:51 【问题描述】:

我正在尝试提取 Google Ads 通过 BigQuery 数据传输发送的 JSON 数组中包含的 Unnest 数据。不幸的是,我被卡在了中间。

BigQuery 表中的原始数据:

CreativeId ResponsiveSearchAdDescriptions
487067671679 ["assetText":"SearchAds Description Text 1","assetId":12443453594,"pinnedField":"DESCRIPTION_1","assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED","assetText":"SearchAds Description Text 2","assetId":12443453165,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED","assetText":"SearchAds Description Text 3","assetId":12443453168,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED","assetText":"SearchAds Description Text 4","assetId":12443419160,"assetPerformanceLabel":"PENDING","assetApprovalStatus":"APPROVED"]

期望的结果:

CreativeId ResponsiveSearchAdDescriptions_assetText ResponsiveSearchAdDescriptions_assetId ResponsiveSearchAdDescriptions_pinnedField ResponsiveSearchAdDescriptions_assetPerformanceLabel ResponsiveSearchAdDescriptions_assetApprovalStatus
487067671679 SearchAds Description Text 1 12443453594 DESCRIPTION_1 PENDING APPROVED
487067671679 SearchAds Description Text 2 12443453165 --- PENDING APPROVED
487067671679 SearchAds Description Text 3 12443453168 --- PENDING APPROVED
487067671679 SearchAds Description Text 4 12443419160 --- PENDING APPROVED

这是最接近我但仍显示 JSON 的查询。

SELECT
  CreativeId,
  JSON_QUERY_ARRAY(ResponsiveSearchAdDescriptions) AS Ads
FROM
  `priXXXXXX.sandbox.Ad_XXXXXXX`
WHERE
  ResponsiveSearchAdDescriptions IS NOT NULL
LIMIT
  100

查询应该能够包含这个条件ResponsiveSearchAdDescriptions IS NOT NULL

一些想法?

【问题讨论】:

【参考方案1】:

使用下面的方法

select Creativeld, 
  json_extract_scalar(el, '$.assetText') as assetText,
  json_extract_scalar(el, '$.assetId') as assetId,
  json_extract_scalar(el, '$.pinnedField') as pinnedField,
  json_extract_scalar(el, '$.assetPerformanceLabel') as assetPerformanceLabel,
  json_extract_scalar(el, '$.assetApprovalStatus') as assetApprovalStatus
from `priXXXXXX.sandbox.Ad_XXXXXXX`,
unnest(json_extract_array(ResponsiveSearchAdDescriptions, '$')) el          

如果应用于您问题中的样本数据 - 输出是

【讨论】:

以上是关于从 Google Ads BigQuery 数据传输中提取/取消嵌套数组的主要内容,如果未能解决你的问题,请参考以下文章

无法将 Google Ads 连接到 BigQuery

如何在 BigQuery 中合并 Google Ads 和 Firebase 数据 [关闭]

BigQuery:Google Ads 报告转换:地理绩效报告:GeoStats 表为空

Google BigQuery Google Ads 数据传输表中的重复数据

来自 Google Ads 的 BigQuery 数据传输服务 - 缺少一些列

未知 BigQuery Google Ads 数据传输服务错误:非经理帐户不存在(或帐户未处于活动状态),因此不会导入数据