将 JSON 数据加载到 BigQuery 表中



我正在尝试通过以下方式将简单的JSON数据加载到BigQuery表中:

$ bq load 
--apilog 
--source_format=NEWLINE_DELIMITED_JSON 
my_dataset.my_table 
./input.json ./schema.json

但收到以下错误消息:

Upload complete.
Waiting on bqjob_xxxx_xxx ... (3s) Current status: DONE
BigQuery error in load operation: Error processing job 'my_project_id:bqjob_xxxx_xxx': CSV table encountered too many errors, giving up. Rows: 1; errors: 1.
Failure details:
- file-00000000: Error detected while parsing row starting at
position: 0. Error: Data between close double quote (") and field
separator.

它抱怨一些CSV错误,但我正在尝试加载JSON(--source_format=NEWLINE_DELIMITED_JSON)

我的input.json包含以下数据:

{"domain":"stackoverflow.com","key":"hello","value":"world"}

schema.json如下:

[
{
"name": "domain",
"type": "string",
"mode": "nullable"
},
{
"name": "key",
"type": "string",
"mode": "nullable"
},
{
"name": "value",
"type": "string",
"mode": "nullable"
}
]

bq版本 2.0.25:

$ gcloud version | grep ^bq
bq 2.0.25

这里的问题是标志apilog需要一个字符串作为输入。此命令应该适合您:

bq load 
--apilog '' 
--source_format=NEWLINE_DELIMITED_JSON 
my_dataset.my_table 
./input.json ./schema.json

空字符串将输出发送到stdout。如果要将日志保存到本地文件,则可以仅发送非空字符串,例如--apilog 'localfile_name'

BQ 命令说:

USAGE: bq.py [--global_flags] <command> [--command_flags] [args]

如您所见,有global_flagscommand_flags

对于具有值的global_flags,您需要使用等号:

--flag=value

command_flags要么是布尔值:

--[no]replace

或者他们采用必须遵循标志的参数:

--source_format NEWLINE_DELIMITED_JSON

也不要混合使用全局标志和命令标志:apilog 是一个全局标志。 我会将您的命令重写为:

$ bq --apilog load 
--source_format NEWLINE_DELIMITED_JSON 
my_dataset.my_table 
./input.json ./schema.json

最新更新