google-bigquery - 通过 Apache Beam 写入动态 BigQuery 表

标签 google-bigquery google-cloud-dataflow apache-beam

我在运行时获取 BigQuery 表名称,并将该名称传递给管道末尾的 BigQueryIO.write 操作以写入该表。

我为它编写的代码是:

rows.apply("write to BigQuery", BigQueryIO
    .writeTableRows()
    .withSchema(schema)
    .to("projectID:DatasetID."+tablename)
    .withWriteDisposition(WriteDisposition.WRITE_TRUNCATE)
    .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED));

使用这种语法我总是得到一个错误,
Exception in thread "main" java.lang.IllegalArgumentException: Table reference is not in [project_id]:[dataset_id].[table_id] format

当我事先不知道应该将数据放入哪个表时,如何以正确的格式传递表名?有什么建议?

谢谢你

最佳答案

然而,这方面的聚会很晚了。
我怀疑问题是您传入的是字符串而不是表引用。

如果你创建了一个表引用,我怀疑你对上面的代码没有问题。

com.google.api.services.bigquery.model.TableReference table = new TableReference()
            .setProjectId(projectID)
            .setDatasetId(DatasetID)
            .setTableId(tablename);

rows.apply("write to BigQuery", BigQueryIO
    .writeTableRows()
    .withSchema(schema)
    .to(table)
    .withWriteDisposition(WriteDisposition.WRITE_TRUNCATE)
    .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED));

关于google-bigquery - 通过 Apache Beam 写入动态 BigQuery 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45030475/

相关文章:

google-bigquery - "Error: Unexpected. Please try again."加入

python - 全局名称 'bigquery' 未定义

java - Apache Beam 执行

python - 如何使用 Apache Beam 从 Google Pub/Sub 访问消息 ID?

javascript - 从 Cloud Function 触发 Cloud Dataflow 管道 - 函数超时

java - 是否可以将不同的子类传递给同一个 PCollection?

python - 从 python 上传到 Bigquery

oauth-2.0 - 尝试通过 API key 授权访问 Google BigQuery

sql - 谷歌bigquery中包含的字符串的等价物

python - 数据流: update BigQuery rows with python pipeline