我想从谷歌云存储上传到BueQuery的数据,但我找不到描述如何执行此操作的Java示例代码。有人会请某个暗示如何做到这一点?

我实际想要做的是将Google App Engine表中的数据传输到BigQuery(并每天同步),这样我就可以进行一些分析。我使用Google App Engine中的Google Cloud Storage Service将(新)记录写入Google云存储中的文件,唯一缺少的部分是将数据追加到BigQuery中的表(或创建一个新表以获取第一次写入)。不可否认,我可以使用bigquery浏览器工具手动上传/附加数据,但我希望它是自动的,否则我需要每天手动执行它。

有帮助吗?

解决方案

我不知道任何用于将谷歌云存储的表加载到BigQuery中的样本。也就是说,如果您遵循运行查询作业的说明此处,您可以运行一个加载作业,而是与flowing:

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

job.setConfiguration(config);

// Set where you are importing from (i.e. the Google Cloud Storage paths).
List<String> sources = new ArrayList<String>();
sources.add("gs://bucket/csv_to_load.csv");
loadConfig.setSourceUris(sources);

// Describe the resulting table you are importing to:
TableReference tableRef = new TableReference();
tableRef.setDatasetId("myDataset");
tableRef.setTableId("myTable");
tableRef.setProjectId(projectId);
loadConfig.setDestinationTable(tableRef);

List<TableFieldSchema> fields = new ArrayList<TableFieldSchema>();
TableFieldSchema fieldFoo = new TableFieldSchema();
fieldFoo.setName("foo");
fieldFoo.setType("string");
TableFieldSchema fieldBar = new TableFieldSchema();
fieldBar.setName("bar");
fieldBar.setType("integer");
fields.add(fieldFoo);
fields.add(fieldBar);
TableSchema schema = new TableSchema();
schema.setFields(fields);
loadConfig.setSchema(schema);

// Also set custom delimiter or header rows to skip here....
// [not shown].

Insert insert = bigquery.jobs().insert(projectId, job);
insert.setProjectId(projectId);
JobReference jobRef =  insert.execute().getJobReference();

// ... see rest of codelab for waiting for job to complete.
.

有关负载配置对象的更多信息,请参阅javadoc 此处

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top