我认为该方法从200行开始here https://code.google.com/p/google-bigquery-tools/source/browse/samples/java/cmdline/src/main/java/com/google/api/services/samples/bigquery/cmdline/BigQuerySample.java是相关的(编辑:我需要向该行添加一个参数
插入 insertReq = bigquery.jobs().insert(PROJECT_ID, insertJob);
)但它不起作用。我收到“加载配置必须指定至少一个源 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
好的,根据 Jordan Tigani 的想法,以下是使用 Google Java API 客户端在 BigQuery 中创建空白表的 Java 代码:
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);
TableReference tableRef = new TableReference();
tableRef.setDatasetId(DATASET_ID);
tableRef.setProjectId(PROJECT_ID);
tableRef.setTableId(tableId);
table.setTableReference(tableRef);
try {
bigquery.tables().insert(PROJECT_ID, DATASET_ID, table).execute();
} catch (IOException e) {
}
创建数据集(在创建表之前)
Dataset dataset = new Dataset();
DatasetReference datasetRef = new DatasetReference();
datasetRef.setProjectId(PROJECT_ID);
datasetRef.setDatasetId(DATASET_ID);
dataset.setDatasetReference(datasetRef);
try {
bigquery.datasets().insert(PROJECT_ID, dataset).execute();
} catch (IOException e) {
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)