有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何从Java客户端(没有CSV文件)创建BigQuery数据集和表/模式

我认为起始行200here的方法是相关的(编辑:我需要向该行添加一个参数) 插入insertReq=bigquery。乔布斯()。插入(项目ID,插入作业); )但它不起作用。我得到“加载配置必须至少指定一个源URI”

我尝试了以下方法:

    TableSchema schema = new TableSchema();
    List<TableFieldSchema> tableFieldSchema = new ArrayList<TableFieldSchema>();
    TableFieldSchema schemaEntry = new TableFieldSchema();
    schemaEntry.setName(myFirstFieldName);
    schemaEntry.setType("STRING");
    tableFieldSchema.add(schemaEntry);
    schema.setFields(tableFieldSchema);

    Table table = new Table();
    table.setSchema(schema);
    table.setId(tableName);
    table.setCreationTime(System.currentTimeMillis());
    table.setKind("bigquery#table");
    try {
        bigquery.tables().insert(PROJECT_ID, DATASET_ID, table).execute();
    } catch (IOException e) {
    }

但是我得到了一个错误Required parameter is missing


共 (1) 个答案

  1. # 1 楼答案

    尝试在表上设置项目id和数据集id(我意识到这似乎是多余的,因为您在insert()操作中指定了它们,但这是REST的一个怪癖。。。项目和数据集是URL的一部分,但它们也是资源的一部分

    从原始HTTP api级别来看,以下功能可以发挥作用:

    https://www.googleapis.com/bigquery/v2/projects/myproject/datasets/mydataset/tables?alt=json    
    {"tableReference": 
        {"tableId": "dfdlkfjx", "projectId": "myproject", "datasetId": "mydataset"},
     "schema": 
         {"fields": [{"name": "a", "type": "STRING"}]}}