首页 文章

通过Apache Beam写入动态BigQuery表

提问于
浏览
3

我在运行时获取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

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

谢谢

1 回答

  • 3

    然而,派对很晚才到此 . 我怀疑问题是你传入的字符串不是表引用 .

    如果您创建了表引用,我怀疑您对上述代码没有任何问题 .

    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));
    

相关问题