bigquery 的行命名问题

row naming issue with bigquery

我有

"Can not set java.util.List field com.google.api.services.bigquery.model.TableRow.f to java.lang.String"

将行命名为 "f"。

哪些步骤会重现问题?

TableRow row = new TableRow();
row.set("f", 7.7);
TableDataInsertAllRequest.Rows rows = new TableDataInsertAllRequest.Rows();
rows.setInsertId(timestamp);
rows.setJson(row);
List  rowList = new ArrayList();
rowList.add(rows);
TableDataInsertAllRequest content =  new TableDataInsertAllRequest().setRows(rowList);
TableDataInsertAllResponse response = bigquery.tabledata().insertAll(
        projectId, datasetId, tableId, content).execute();

预期的输出是什么?你看到了什么?

正在将列重命名为 smth。像 f1 工作正常。

Gradle 依赖关系:

dependencies {
    compile project(':shared')
    compile 'com.google.api-client:google-api-client:1.19.0'
    compile 'com.google.http-client:google-http-client:1.19.0'
    compile 'com.google.http-client:google-http-client-jackson2:1.19.0'
    compile 'com.google.oauth-client:google-oauth-client:1.19.0'
    compile 'com.google.oauth-client:google-oauth-client-servlet:1.19.0'
    compile 'com.google.apis:google-api-services-bigquery:v2-rev171-1.19.0'
    compile 'redis.clients:jedis:2.4.2'
    compile 'com.fasterxml.jackson.core:jackson-core:2.4.4'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
    compile 'log4j:log4j:1.2.16'
    compile 'org.json:json:20090211'
    compile 'com.google.api-client:google-api-client:1.17.0-rc'
    compile 'com.google.guava:guava:15.0'
    compile 'org.glassfish.jersey.core:jersey-server:2.10.1'
    compile 'org.glassfish.jersey.core:jersey-client:2.10.1'
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.10.1'
    compile 'org.glassfish.jersey.containers:jersey-container-jetty-servlet:2.10.1'
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.10.1'
    compile 'javax.servlet:javax.servlet-api:3.1.0'
    compile 'com.jayway.jsonpath:json-path-assert:0.9.1'
    compile 'com.googlecode.json-simple:json-simple:1.1.1'
    compile 'redis.clients:jedis:2.4.2'
    compile 'com.github.fge:json-schema-validator:2.2.5'
    compile 'org.eclipse.jetty:jetty-server:9.2.1.v20140609'
    compile 'org.mongodb:mongo-java-driver:2.12.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.apache.commons:commons-email:1.3.3'
    testCompile 'org.mockito:mockito-all:1.9.5'

}

由于一个TableRow可以有多个字段,所以我通常会看到如下结构:

TableDataInsertAllResponse response = bigquery.tabledata()
    .insertAll(projectId, datasetId, tableId, new TableDataInsertAllRequest()
        .setRows(ImmutableList.of(new TableDataInsertAllRequest.Rows()
            .setInsertId(insertId)
            .setJson(new ImmutableMap.Builder<String, Object>()
                .put("f", 7.7)
                .build())))).execute();

这对你有用吗?

请注意,我在该示例中包括了一个 insertId,因为您需要将其用于行级重复数据删除 if/when 您添加了重试逻辑。如果您的用例不需要它,请暂时放弃它。