没有上传数据,但使用java在bigquery加载作业中作业状态为DONE

时间:2017-07-28 08:31:35

标签: java google-bigquery

我正在尝试上传CSV文件,格式正确。如果我尝试只上传3行数据,那么它可以工作,但是对于大文件,有时它会说套接字超时异常我们刚刚完成的工作。此数据集位于其他位置。

    Bigquery bigquery = GoogleConnector.getBigQuery();
    TableSchema schema = new TableSchema();

    List<TableFieldSchema> tableFieldSchema = 
    getTableFieldSchema("mostRecentObservation");
    schema.setFields(tableFieldSchema);

    Table table = new Table();
    table.setSchema(schema);
    TableReference tableRef = new TableReference();
    tableRef.setDatasetId("MetroMallsEU");

    tableRef.setProjectId(projectId);
    tableRef.setTableId("mostRecentObsTest");
    table.setTableReference(tableRef);

    FileContent content = new FileContent("application/octet-stream", 
    new File(fileNameToLoad));
    Job job = new Job();
    JobConfiguration config = new JobConfiguration();
    JobConfigurationLoad configLoad = new JobConfigurationLoad();

    configLoad.setSchema(schema);
    configLoad.setDestinationTable(tableRef);

    configLoad.setEncoding("UTF-8");
    configLoad.setCreateDisposition("CREATE_IF_NEEDED");
    configLoad.setSourceFormat("CSV");

    //        configLoad.setSkipLeadingRows(1);
    config.setLoad(configLoad);
    job.setConfiguration(config);

try {
        Bigquery.Jobs.Insert insert = bigquery.jobs().insert(projectId, 
        job, content);
        insert.setProjectId(projectId);
        JobReference jobRef = insert.execute().getJobReference();
        String jobId = jobRef.getJobId();
        String status;

        while (!bigquery.jobs().
                get(projectId, jobId).execute().getStatus().getState().equalsIgnoreCase("DONE")) {

            status = bigquery.jobs().
                    get(projectId, jobId).execute().getStatus().getState();

            System.out.println("Status: " + status);
            Thread.sleep(1000);

        }

    }catch (Exception e){
    e.printStackTrace();
    }

1 个答案:

答案 0 :(得分:1)

检查作业的status属性的文档 -

status.state只是告诉你工作是否完成 如果已完成('完成') - 您仍然需要检查它是如何完成的 - 有或没有错误 - 您可以使用status.errorResult属性