3

尝试使用 JAVA API 设置加载作业时出现 503 - 后端错误。

我要加载的文件位于 Google Cloud Storage 上,如果我尝试从 BigQuery Web 界面加载数据,告诉我要从 Google Cloud Storage 加载,一切正常。

我使用 API 的方式可能有问题。

这是代码:

            String url = "[GOOGLE_CLOUD_STORAGE_URL];

    Job job = new Job();
    JobConfiguration config = new JobConfiguration();
    JobConfigurationLoad loadConfig = new JobConfigurationLoad();

    config.setLoad(loadConfig);

    job.setConfiguration(config);

    List<String> sources = new ArrayList<String>();
    sources.add("gs://" + url);
    loadConfig.setSourceUris(sources);

    TableReference tableRef = new TableReference();
    tableRef.setDatasetId("Foo");
    tableRef.setTableId("Bar");
    tableRef.setProjectId(PROJECT_ID);
    loadConfig.setDestinationTable(tableRef);

    List<TableFieldSchema> fields = new ArrayList<TableFieldSchema>();
    TableFieldSchema field = new TableFieldSchema();

            ..... A LOT OF FIELDS

            field.setName("real_dollars_balance");
    field.setType("float");

    fields.add(field);
            TableSchema schema = new TableSchema();
    schema.setFields(fields);
    loadConfig.setSchema(schema);

    Insert insert = bigquery.jobs().insert(PROJECT_ID, job);
    insert.setProjectId(PROJECT_ID);
    JobReference jobId = insert.execute().getJobReference();

由于插入操作失败,我无法获得有效的作业参考,我在 BigQuery 上看不到任何新作业。我在 BigQuery 上通过了正确的身份验证,我可以浏览数据集和表格。我错过了什么吗?

编辑-“execute()”方法调用抛出一个异常,GoogleJsonResponseException,包含:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service           Unavailable
 {
   "code" : 503,
   "errors" : [ {
      "domain" : "global",
      "message" : "Backend Error",
      "reason" : "backendError"
    } ],
   "message" : "Backend Error"
  }

而且,它永远不会变得“可用”。我真的不知道我错过了什么。你们是如何设置自动程序以在 Google BigQuery 上加载数据的?Google 上的文档并不清楚,就像我对这样的服务所期望的那样。

4

0 回答 0