gpt4 book ai didi

json - 如何从 BigQuery 中的平面表创建嵌套的 JSON 格式表?

转载 作者:行者123 更新时间:2023-12-04 21:45:09 26 4
gpt4 key购买 nike

我有一个宽平面表,以以下类似格式存储在 Google bigquery 中:

log_date:integer,sessionid:integer,computer:string,ip:string,event_id:integer,amount:float



我正在尝试以分层嵌套格式创建此表,具有 2 个嵌套级别,如下所示:
 [
{
"name": "log_date",
"type": "integer"
},
{
"name": "session",
"type": "record",
"mode": "repeated",
"fields": [
{
"name": "sessionid",
"type": "integer"
},
{
"name": "computer",
"type": "string"
},
{
"name": "ip",
"type": "string"
},
{
"name": "event",
"type": "record",
"mode": "repeated",
"fields": [
{
"name": "event_id",
"type": "integer"
},
{
"name": "amount",
"type": "float"
}]] } ]

从 bigquery 表生成 json 格式的数据文件的最佳方法是什么?
有没有比
1.将表格下载到外部csv
2.建立json记录,并写入外部文件
3.将外部json文件上传到新的bigquery表中

我们可以有一个从现有表生成 json 的直接过程吗?

谢谢你

最佳答案

目前没有一种方法可以自动将数据转换为嵌套格式。如果您想以 json 格式而不是 CSV 格式导出数据,您可以使用带有 --destination_format 的导出命令。标志设置为 NEWLINE_DELIMITED_JSON .
例如

bq extract \
--destination_format=NEWLINE_DELIMITED_JSON \
yourdataset.table \
gs://your_bucket/result*.json

关于json - 如何从 BigQuery 中的平面表创建嵌套的 JSON 格式表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15393165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com