从 BigQuery 中的 2 个 csv 字段创建 1 个包含 2 个字段的数组
Create 1 array with 2 fields from 2 csv fields in BigQuery
我目前正在努力解决这个问题,但不确定如何进行。我有以下数据
ID
name
value
One
a,b,c
10,20,30
我想把它变成
|编号 | properties.name | properties.value |
|:---- |:------: | -----: |
|一 |一个 | 10 |
| |乙 | 20 |
| | c | 30 |
下面的查询看起来正常,但它没有创建一个数组,而是创建了一个包含 2 个数组字段的嵌套记录。
SELECT ID
name
, value
, array (
select as struct
split(name, ',') as name
, split(value, ',') as value
) as properties
FROM `orders`
考虑以下方法
select id, array(
select as struct name, value
from unnest(split(name)) name with offset
join unnest(split(value)) value with offset
using(offset)
) as properties
from `orders`
如果应用于您问题中的示例数据 - 输出为
我目前正在努力解决这个问题,但不确定如何进行。我有以下数据
ID | name | value |
---|---|---|
One | a,b,c | 10,20,30 |
我想把它变成 |编号 | properties.name | properties.value | |:---- |:------: | -----: | |一 |一个 | 10 | | |乙 | 20 | | | c | 30 |
下面的查询看起来正常,但它没有创建一个数组,而是创建了一个包含 2 个数组字段的嵌套记录。
SELECT ID
name
, value
, array (
select as struct
split(name, ',') as name
, split(value, ',') as value
) as properties
FROM `orders`
考虑以下方法
select id, array(
select as struct name, value
from unnest(split(name)) name with offset
join unnest(split(value)) value with offset
using(offset)
) as properties
from `orders`
如果应用于您问题中的示例数据 - 输出为