本文整理汇总了Java中org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.Write方法的典型用法代码示例。如果您正苦于以下问题:Java BigQueryIO.Write方法的具体用法?Java BigQueryIO.Write怎么用?Java BigQueryIO.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO
的用法示例。
在下文中一共展示了BigQueryIO.Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sinkResultsToBigQuery
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO; //导入方法依赖的package包/类
/**
* Send {@code formattedResults} to BigQuery.
*/
private void sinkResultsToBigQuery(
PCollection<String> formattedResults, long now,
String version) {
String tableSpec = tableSpec(now, version);
TableSchema tableSchema =
new TableSchema().setFields(ImmutableList.of(
new TableFieldSchema().setName("result").setType("STRING"),
new TableFieldSchema().setName("records").setMode("REPEATED").setType("RECORD")
.setFields(ImmutableList.of(
new TableFieldSchema().setName("index").setType("INTEGER"),
new TableFieldSchema().setName("value").setType("STRING")))));
NexmarkUtils.console("Writing results to BigQuery table %s", tableSpec);
BigQueryIO.Write io =
BigQueryIO.write().to(tableSpec)
.withSchema(tableSchema)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND);
formattedResults
.apply(queryName + ".StringToTableRow", ParDo.of(new StringToTableRow()))
.apply(queryName + ".WriteBigQueryResults", io);
}
示例2: setWriteOperation
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO; //导入方法依赖的package包/类
private BigQueryIO.Write setWriteOperation(BigQueryIO.Write bigQueryIOPTransform) {
if (properties.tableOperation.getValue() == BigQueryOutputProperties.TableOperation.NONE
|| properties.tableOperation.getValue() == BigQueryOutputProperties.TableOperation.CREATE_IF_NOT_EXISTS) {
switch (properties.writeOperation.getValue()) {
case APPEND:
bigQueryIOPTransform = bigQueryIOPTransform.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND);
break;
case WRITE_TO_EMPTY:
bigQueryIOPTransform = bigQueryIOPTransform.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_EMPTY);
break;
default:
throw new RuntimeException("To be implemented: " + properties.writeOperation.getValue());
}
} else {
if (properties.writeOperation.getValue() != null) {
LOG.info("Write operation " + properties.writeOperation.getValue() + " be ignored when Table operation is "
+ properties.tableOperation.getValue());
}
}
return bigQueryIOPTransform;
}
示例3: expand
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO; //导入方法依赖的package包/类
@Override
public PDone expand(PCollection<IndexedRecord> in) {
TableReference table = new TableReference();
table.setProjectId(datastore.projectName.getValue());
table.setDatasetId(dataset.bqDataset.getValue());
table.setTableId(dataset.tableName.getValue());
BigQueryIO.Write bigQueryIOPTransform = BigQueryIO.writeTableRows().to(table);
bigQueryIOPTransform = setTableOperation(bigQueryIOPTransform);
bigQueryIOPTransform = setWriteOperation(bigQueryIOPTransform);
in.apply(ParDo.of(new IndexedRecordToTableRowFn())).apply(bigQueryIOPTransform);
return PDone.in(in.getPipeline());
}
示例4: setTableOperation
import org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO; //导入方法依赖的package包/类
private BigQueryIO.Write setTableOperation(BigQueryIO.Write bigQueryIOPTransform) {
TableSchema bqSchema = null;
if (properties.tableOperation.getValue() == BigQueryOutputProperties.TableOperation.CREATE_IF_NOT_EXISTS
|| properties.tableOperation.getValue() == BigQueryOutputProperties.TableOperation.DROP_IF_EXISTS_AND_CREATE) {
Schema designSchema = properties.getDatasetProperties().main.schema.getValue();
if (designSchema != null && !AvroUtils.isSchemaEmpty(designSchema) && !AvroUtils.isIncludeAllFields(designSchema)) {
bqSchema = BigQueryAvroRegistry.get().guessBigQuerySchema(designSchema);
}
if (bqSchema == null) {
throw new RuntimeException("Need to specify schema to create table");
}
}
switch (properties.tableOperation.getValue()) {
case NONE:
bigQueryIOPTransform = bigQueryIOPTransform.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER);
break;
case CREATE_IF_NOT_EXISTS:
bigQueryIOPTransform = bigQueryIOPTransform.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
.withSchema(bqSchema);
break;
case DROP_IF_EXISTS_AND_CREATE:
bigQueryIOPTransform = bigQueryIOPTransform.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED).withSchema(bqSchema);
break;
case TRUNCATE:
bigQueryIOPTransform = bigQueryIOPTransform.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER);
break;
default:
throw new RuntimeException("To be implemented: " + properties.tableOperation.getValue());
}
return bigQueryIOPTransform;
}