问题描述
我认为方法起始行200 是相关的(编辑:我需要添加一个参数到行
插入insertReq = bigquery .jobs()。insert(PROJECT_ID,insertJob);
)但它不起作用。我得到加载配置必须指定至少一个源URI
我试过以下内容:
TableSchema schema = new TableSchema();
列表< 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);
尝试{
bigquery.tables()。insert(PROJECT_ID,DATASET_ID,table).execute();
} catch(IOException e){
}
但我得到一个错误缺少必要的参数
OK基于Jordan Tigani的想法,这里是Java代码,用于在Google Java API客户端的BigQuery中创建一个空白表:
TableSchema schema = new TableSchema ();
列表< 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);
尝试{
bigquery.tables()。insert(PROJECT_ID,DATASET_ID,table).execute();
} catch(IOException e){
}
创建数据集在创建表之前)
数据集dataset = new Dataset();
DatasetReference datasetRef = new DatasetReference();
datasetRef.setProjectId(PROJECT_ID);
datasetRef.setDatasetId(DATASET_ID);
dataset.setDatasetReference(datasetRef);
尝试{
bigquery.datasets()。insert(PROJECT_ID,dataset).execute();
} catch(IOException e){
}
I think the method starting line 200 here is relevant (edit: I needed to add a parameter to the line Insert insertReq = bigquery.jobs().insert(PROJECT_ID, insertJob);) but it doesn't work. I get "Load configuration must specify at least one source URI"
I have tried the following:
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) {
}
but I get an error Required parameter is missing
OK based on the idea by Jordan Tigani, here is the Java code that works to create a blank table in BigQuery with Google Java API Client:
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) {
}
To create a dataset (before creating the table)
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) {
}
这篇关于如何从Java客户端创建BigQuery数据集和表/模式(无CSV文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!