读取 BigQuery federated table 作为数据流中的源会引发错误

Reading BigQuery federated table as source in Dataflow throws an error

我在 BigQuery 中有一个联合源,它指向 GCS 中的一些 CSV 文件。

当我尝试读取联合 BigQuery table 作为 Dataflow 管道的源时,它抛出以下错误:

    1226 [main] ERROR com.google.cloud.dataflow.sdk.util.BigQueryTableRowIterator  - Error reading from BigQuery table Federated_test_dataflow of dataset CPT_7414_PLAYGROUND : 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Cannot list a table of type EXTERNAL.",
    "reason" : "invalid"
  } ],
  "message" : "Cannot list a table of type EXTERNAL."
}

Dataflow 是否不支持 BigQuery 中的联合源,还是我做错了什么?我知道我可以将文件从 GCS 直接读取到我的管道中,但由于应用程序的设计,我更愿意使用 BigQuery TableRow 对象。

 PCollection<TableRow> results = pipeline.apply("fed-test", BigQueryIO.Read.from("<project_id>:CPT_7414_PLAYGROUND.Federated_test_dataflow")).apply(ParDo.of(new DoFn<TableRow, TableRow>() {
        @Override
        public void processElement(ProcessContext c) throws Exception {
            System.out.println(c.element());
        }
    }));

Dataflow BigQuery 源旨在读取 "TABLE" 类型的 BigQuery 托管表。 (可以在 https://cloud.google.com/bigquery/docs/reference/v2/tables#type 找到类型定义。)不支持 EXTERNAL 和 VIEW 表。

BigQuery "federated table" 功能允许 bigquery 直接查询 Google Cloud Storage 等地方的数据。 Dataflow 还可以从 Google Cloud Storage 读取文件,因此您应该能够将 Dataflow 计算直接指向要读取的源。

正如 Michael 所说,BigQuery 不支持直接从 EXTERNAL(联合 tables)或 VIEW 读取:即使有效读取也需要查询。

要在 Dataflow 中读取这些 table,您可以改为使用

BigQueryIO.Read.fromQuery("SELECT * FROM table_or_view_name")

这将发出查询并将结果保存到临时 table,然后开始读取过程。当然,这会产生在 BigQuery 上查询的成本,因此如果您希望重复读取相同的 VIEW 或 EXTERNAL table,您可能需要手动创建 table.