BigQueryIO.Write 在数据流中 2.X

BigQueryIO.Write in dataflow 2.X

以下代码适用于 Dataflow 1.9 sdk,迁移到 2.X

PCollection<TableRow> tableRow = ...

tableRow.apply(BigQueryIO.Write()
                .to(String.format("%1$s:%2$s.%3$s",projectId, bqDataSet, bqTable))
                .withSchema(schema)
                .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));

我明白了

The method apply(PTransform<? super PCollection<TableRow>,OutputT>) in the type PCollection<TableRow> is not applicable for the arguments (BigQueryIO.Write<Object>)

Release notes 在这里没有多大帮助,2.X 上的文档不存在重定向到 API 页面。

您尝试过使用 BigqueryIO.writeTableRows() 吗?

Apache Beam 2.1.0 BigqueryIO 文档 https://beam.apache.org/documentation/sdks/javadoc/2.1.0/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.html

您可以尝试明确提供 TableRow 类型 (BigQuery.<TableRow>write()...) 或按照上面的建议使用 BigQuery.writeTableRows()

看起来界面在 2.x 中是通用的。早期版本对 TableRow 进行了硬编码。