[英]Error in parsing while load job tries to insert json to BigQuery table using java
I am trying this , 我正在尝试这个
Job job = new Job();
JobConfiguration config = new JobConfiguration();
JobConfigurationLoad loadConfig = new JobConfigurationLoad();
config.setLoad(loadConfig);
job.setConfiguration(config);
// Set where you are importing from (i.e. the Google Cloud Storage paths).
List<String> sources = new ArrayList<String>();
sources.add(GCS_URL);
loadConfig.setSourceUris(sources);
boolean tableExists =checkTableExists(bigquery,projectId,datasetId,tableName);
System.out.println("Whether table exists "+tableExists);
TableReference tableRef = new TableReference();
tableRef.setProjectId(projectId);
tableRef.setDatasetId(datasetId);
tableRef.setTableId(tableName);
if(!tableExists)
{
System.out.println("Create table");
Table table = new Table();
table.setSchema(getSchemaForBqTable(tableName));
table.setTableReference(tableRef);
bigquery.tables().insert(projectId,datasetId,table).execute();
}
loadConfig.setDestinationTable(tableRef);
loadConfig.setSchema(getSchemaForBqTable(tableName));
Insert insertJob =bigquery.jobs().insert(projectId, job);
insertJob.setProjectId(projectId);
JobReference jobId = insertJob.execute().getJobReference();
and also polling the status and error results ..
while (true) {
pollJob = bigquery.jobs().get(projectId, jobId.getJobId()).execute();
elapsedTime = System.currentTimeMillis() - startTime;
System.out.format("Job status (%dms) %s: %s\n", elapsedTime,
jobId.getJobId(), pollJob.getStatus().getState());
if (pollJob.getStatus().getErrorResult() != null) {
// The job ended with an error.
System.out.format("Job %s ended with error %s", jobId.getJobId(),pollJob.getStatus().getErrorResult().getMessage(), projectId);
throw new RuntimeException(String.format("Job %s ended with error %s", jobId.getJobId(),
pollJob.getStatus().getErrorResult().getMessage()));
}
if (pollJob.getStatus().getState().equals("DONE")) {
return pollJob;
}
I am getting the below error 我收到以下错误
Job status (601ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (1899ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (3235ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (5505ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (7621ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (8904ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (10188ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (11461ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (13615ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (14890ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (16160ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (17444ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (19602ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (20887ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (22168ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: PENDING Job status (24359ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: RUNNING Exception in th 工作状态(601ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(1899ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(3235ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(5505ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(7621ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(8904ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(10188ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(11461ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(13615ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(14890ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(16160ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(17444ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的工作状态(19602ms )job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的作业状态(20887ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待处理的作业状态(22168ms)job_vJWfyum4tsmECoiBrygQ6PZn73cJWyWING read "main" Job status (25643ms) job_vJWfyum4tsmECoiBrygQ6PZn73c: DONE Job job_vJWfyum4tsmECoiBrygQ6PZn73c ended with error Data between close double quote (") and field separator: field starts with: java.lang.RuntimeException: Job job_vJWfyum4tsmECoiBrygQ6PZn73c ended with error Data between close double quote (") and field separator: field starts with: at com.disney.facebook.LoadJob.checkQueryResults(LoadJob.java:181) at com.disney.facebook.LoadJob.main(LoadJob.java:72)
读取“主要”作业状态(25643毫秒)job_vJWfyum4tsmECoiBrygQ6PZn73c:DONE Job job_vJWfyum4tsmECoiBrygQ6PZn73c以错误结束双引号(“)和字段分隔符之间的数据:字段开头:java.lang.RuntimeException:Job_vJECf6B终止于(Q) “)和字段分隔符:字段以com.disney.facebook.LoadJob.checkQueryResults(LoadJob.java:181)开头,位于com.disney.facebook.LoadJob.main(LoadJob.java:72)
--------------------------------------------------------------------------------------------------------------------------------------------------------
checked the job status using bq commands ...below the exception... 使用bq命令检查了作业状态...在异常下方...
C:\\Program Files (x86)\\Google\\Cloud SDK>bq show -j job_inR4kMvXQCcpcTujY7nEC-LZs BQ Job brilliobigquery-991:job_inR4kMvXQCcpcTujY7nEC-LZsBQ C:\\ Program Files(x86)\\ Google \\ Cloud SDK> bq show -j job_inR4kMvXQCcpcTujY7nEC-LZs BQ Job brilliobigquery-991:job_inR4kMvXQCcpcTujY7nEC-LZsBQ
Job Type State Start Time Duration Bytes Processed Bytes Bill ed Billing Tier 作业类型状态开始时间持续时间字节处理字节计费账单层
load FAILURE 04 Nov 12:18:32 0:00:01 加载失败04 Nov 12:18:32 0:00:01
Errors encountered during job execution. 作业执行期间遇到的错误。 Data between close double quote (") and field separator: field starts with: Failure details: - File: 0 / Line:1 / Field:2: Data between close double quote (") and field separator: field starts with: - File: 0 / Line:1 / Field:3: Data between close double quote (") and field separator: field starts with: - File: 0 / Line:1 / Field:4: Data between close double quote (") and field separator: field starts with: - File: 0 / Line:1 / Field:5: Data between close double quote (") and field separator: field starts with:
右双引号(“)和字段分隔符之间的数据:字段开头:失败详细信息:-文件:0 /行:1 / /字段:2:右双引号(”)和字段分隔符之间的数据:字段开头:-文件:0 /行:1 /字段:3:双引号(“)和字段分隔符之间的数据:字段以以下内容开头:-文件:0 /行:1 / /字段:4:双引号(”)和字段之间的数据分隔符:字段开头:-文件:0 /行:1 /字段:5:右双引号(“)和字段分隔符之间的数据:字段开头:
File to upload will have content like this. 要上传的文件将具有这样的内容。
{"channel_skey":"124", "the_date":"1444953600", "total_subscribers":"782904", "total_subscribing":"21", "rec_insert_ts":"1444953600", "rec_update_ts":"1444953600"} {"channel_skey":"125", "the_date":"1444953600", "total_subscribers":"50359", "total_subscribing":"0", "rec_insert_ts":"1444953600", "rec_update_ts":"1444953600"} {“ channel_skey”:“ 124”,“ the_date”:“ 1444953600”,“ total_subscribers”:“ 782904”,“ total_subscribing”:“ 21”,“ rec_insert_ts”:“ 1444953600”,“ rec_update_ts”:“ 1444953600”} { “ channel_skey”:“ 125”,“ the_date”:“ 1444953600”,“ total_subscribers”:“ 50359”,“ total_subscribing”:“ 0”,“ rec_insert_ts”:“ 1444953600”,“ rec_update_ts”:“ 1444953600”}
Kindly help me to resolve this issue. 请帮助我解决此问题。
You need to set the source format to NEWLINE_DELIMITED_JSON. 您需要将源格式设置为NEWLINE_DELIMITED_JSON。 This job is trying to parse your data as CSV.
这项工作正在尝试将您的数据解析为CSV。
API reference: API参考:
https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load.sourceFormat https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load.sourceFormat
Java client library reference: Java客户端库参考:
https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/com/google/api/services/bigquery/model/JobConfigurationLoad.html#setSourceFormat(java.lang.String) https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/com/google/api/services/bigquery/model/JobConfigurationLoad.html#setSourceFormat(java.lang.String)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.