首页 > 解决方案 > 通过命令行在 BQ 中加载 CSV

问题描述

我一直在尝试使用此命令在 bigquery 中加载 csv 文件,但一直出错。我的 csv 文件看起来像这样,我的文件总共有 40 行,仅包括标题。当我尝试使用控制台 gui 加载 csv 文件时出现同样的错误

header 1,header 2,Header 3,Header 4,Header 5,Header 6,header 7,Header 8,header 9,Header 10 
Justine,Mobile,Address,Location,2020-01-26,1,0,11,3,1

使用此命令行:

bq load --allow_jagged_rows=1 --skip_leading_rows=1 --source_format=CSV  datasetId.mytableid /home/username/file.csv

我得到了这个错误

Upload complete.
Waiting on bqjob_r421ecc680c644b1b_0000016fdb99efe1_1 ... (1s) Current status: DONE   
BigQuery error in load operation: Error processing job 'my-project-id:bqjob_r4212fs8997c644b1b_000db99efe1_1': Error while reading data, error message: CSV table encountered too many errors,
giving up. Rows: 1; errors: 1. Please look into the errors[] collection for more details.
Failure details:
- Error while reading data, error message: Error detected while
parsing row starting at position: 309. Error: Bad character (ASCII
0) encountered.

标签: csvgoogle-bigquery

解决方案


bq load --source_format=CSV project_id:dataset.tablename /PATH_TO_FILE/airports.csv IATA:STRING,AIRPORT:STRING,CITY:STRING,STATE:STRING,COUNTRY:STRING,LATITUDE:FLOAT64,LONGITUDE:FLOAT64

我只是从 CVS 中删除了第一行(标题),因为我已经在命令中提到了模式和数据类型。然后我运行上面的命令,它为我创建了表


推荐阅读