0

当我查询两级嵌套字段时,我错过了一些行。

架构是这样的:

Productid   STRING  REQUIRED 
Variants    RECORD  REPEATED
Variants.SKU    STRING  NULLABLE
Variants.Size   STRING  NULLABLE
Variants.Prices RECORD  REPEATED
Variants.Prices.Country STRING  NULLABLE
Variants.Prices.Currency    STRING  NULLABLE

一些 Variants.Price 记录为空。

当我用这个查询查询这个表时:

select Productid,Variants.SKU,Variants.Size
from ga-export-0000.feed.feed_dev
,UNNEST (Variants) AS Variants

我得到的行比这个多得多:

select Productid,Variants.SKU,Variants.Size
,Prices.Currency,Prices.Country
from ga-export-0000.feed.feed_dev
,UNNEST (Variants) AS Variants
,UNNEST(Variants.Prices) as Prices 

这是因为它不会返回缺少 Variants.Prices 的行。

如何修改我的第二个查询,使其返回所有行,如果 Variants.Prices 丢失,它显示为 NULL?

4

1 回答 1

2

您可能对文档中的扁平化数组主题感兴趣。使用 代替逗号LEFT JOIN,例如:

select Productid,Variants.SKU,Variants.Size
,Prices.Currency,Prices.Country
from `ga-export-0000.feed.feed_dev`
,UNNEST (Variants) AS Variants
LEFT JOIN UNNEST(Variants.Prices) as Prices 

如果该数组为空,这将返回一个NULL值。Prices

于 2017-03-23T13:24:42.807 回答