加载作业尝试使用java

时间:2015-11-04 09:07:36

标签: java google-bigquery

我正在尝试这个,

    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;
      }

我收到以下错误

工作状态(601ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:待定 工作状态(1899毫秒)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_vJWfyum4tsmECoiBrygQ6PZn73c:待定 工作状态(24359ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:RUNNING 线程&#34; main&#34;中的例外情况工作状态(25643ms)job_vJWfyum4tsmECoiBrygQ6PZn73c:DONE 作业job_vJWfyum4tsmECoiBrygQ6PZn73c以关闭双引号(&#34;)和字段分隔符之间的错误数据结束:字段以:java.lang.RuntimeException开始:作业job_vJWfyum4tsmECoiBrygQ6PZn73c以关闭双引号(&#34;)和字段分隔符之间的错误数据结束:字段以:     在com.disney.facebook.LoadJob.checkQueryResults(LoadJob.java:181)     在com.disney.facebook.LoadJob.main(LoadJob.java:72)

--------------------------------------------------------------------------------------------------------------------------------------------------------

使用bq命令检查作业状态...在异常...

下面

C:\ Program Files(x86)\ Google \ Cloud SDK&gt; bq show -j job_inR4kMvXQCcpcTujY7nEC-LZs BQ 工作brilliobigquery-991:job_inR4kMvXQCcpcTujY7nEC-LZsBQ

作业类型状态开始时间持续时间字节已处理字节数 ed Billing Tier

加载FAILURE 04 Nov 12:18:32 0:00:01

作业执行期间遇到的错误。关闭双引号(&#34;)和。之间的数据  字段分隔符:字段以: 失败详情:   - 文件:0 /行:1 /字段:2:关闭双引号(&#34;)和之间的数据    字段分隔符:字段以:   - 文件:0 /行:1 /字段:3:关闭双引号(&#34;)和之间的数据    字段分隔符:字段以:   - 文件:0 /行:1 /字段:4:关闭双引号(&#34;)和之间的数据    字段分隔符:字段以:   - 文件:0 /行:1 /字段:5:关闭双引号(&#34;)和之间的数据    字段分隔符:字段以:

开头

要上传的文件将包含这样的内容。

{&#34; channel_skey&#34;:&#34; 124&#34;,&#34; the_date&#34;:&#34; 1444953600&#34;,&#34; total_subscribers&#34;:& #34; 782904&#34;,&#34; total_subscribing&#34;:&#34; 21&#34;,&#34; rec_insert_ts&#34;:&#34; 1444953600&#34;,&#34; rec_update_ts&# 34;:&#34; 1444953600&#34;} {&#34; channel_skey&#34;:&#34; 125&#34;,&#34; the_date&#34;:&#34; 1444953600&#34;,&#34; total_subscribers&#34;:&#34; 50359&#34;,&#34; total_subscribing&#34;:&#34; 0&#34;,&#34; rec_insert_ts&#34;:&#34; 1444953600&#34;,&#34; rec_update_ts&#34;: &#34; 1444953600&#34;}

请帮我解决这个问题。