2017-08-28 70 views
0

我想简单的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如下:2.0.25

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

bq版本:

$ gcloud version | grep ^bq 
bq 2.0.25 

回答

1

这里的问题是,标志apilog需要字符串输入。此命令应该适用于您:

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

空字符串将输出发送到stdout。如果您想将日志保存到本地文件,那么您可以发送一个非空字符串,如--apilog 'localfile_name'

1

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 
+0

最好使用'bq --apilog - load ...'或'bq --apilog''load ...',因为没有参数'--apilog'使用'load'作为参数。 –