读取数据时出错,错误消息:CSV 表引用列位置 15,但从位置:0 开始的行仅包含 1 列

问题描述 投票:0回答:4

我是bigquery的新手,这里我尝试加载我手动创建的GCP BigQuery表中的数据,我有一个包含bq加载命令的bash文件 -

bq load --source_format=CSV --field_delimiter=$(printf '\u0001') dataset_name.table_name gs://bucket-name/sample_file.csv

我的 CSV 文件包含多个具有 16 列的行 - 示例行是

100563^3b9888^Buckname^https://www.settttt.ff/setlllll/buckkkkk-73d58581.html^Buckcherry^null^null^2019-12-14^23d74444^Reverb^Reading^Pennsylvania^United States^US^40.3356483^-75.9268747

表架构 -

当我从 Cloud shell 执行 bash 脚本文件时,出现以下错误 -

Waiting on bqjob_r10e3855fc60c6e88_0000016f42380943_1 ... (0s) Current status: DONE   
BigQuery error in load operation: Error processing job 'project-name- 
staging:bqjob_r10e3855fc60c6e88_0000ug00004521': 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:
- gs://bucket-name/sample_file.csv: Error while
reading data, error message: CSV table references column position
15, but line starting at position:0 contains only 1 columns.

解决方案是什么,提前谢谢

csv google-bigquery google-cloud-storage
4个回答
2
投票

您试图根据您提供的架构向表中插入错误的值

根据表架构和您的数据示例,我运行此命令:

./bq load --source_format=CSV  --field_delimiter=$(printf '^') mydataset.testLoad  /Users/tamirklein/data2.csv

第一个错误

故障详情: - 读取数据时出错,错误消息:无法解析“39b888” 作为字段 Field2(位置 1)的 int,从位置 0 开始

此时,我手动从 39b888 中删除了 b,现在我得到了这个

第二个错误

故障详情: - 读取数据时出错,错误消息:无法解析 “14/12/2019”作为字段 Field8(位置 7)的日期,起始于 位置 0

此时,我将 14/12/2019 更改为 2019-12-14,这是 BQ 日期格式,现在一切正常了

上传完成。 正在等待 bqjob_r9cb3e4ef5ad596e_0000016f42abd4f6_1 ...(0 秒)当前状态:完成

您需要在上传之前清理数据,或者使用带有

--max_bad_records
标志的更多行的数据样本(有些行没问题,有些则不基于您的数据质量)

注意:不幸的是,在上传过程中无法控制日期格式,请参阅此answer作为参考


2
投票

我们在将数据从本地导入到 BigQuery 时遇到了同样的问题。研究数据后我们发现有数据开始 或 \s enter image description here

实施

ua['ColumnName'].str.strip()
ua['District'].str.rstrip()
之后。我们可以将数据添加到 Bg。

谢谢


0
投票

我们在将数据从本地导入到 BigQuery 时遇到了同样的问题。经过测试了这么多选项后,我们发现错误的原因是数据中的列数与架构中的列数不匹配。希望这对一些人有帮助 🙂


0
投票

今天我也遇到了同样的问题。
原因是某些字段值包含 CRLF。 example

© www.soinside.com 2019 - 2024. All rights reserved.