Google bigquery 表行中的BigqueryIO架构

Google bigquery 表行中的BigqueryIO架构,google-bigquery,google-cloud-dataflow,Google Bigquery,Google Cloud Dataflow,我有一个TableRow的PCollection,表行中有tablename和schema,如下所示 我需要将col1、col2和col3值插入到前面提到的行中具有模式的表中,使用 BigQueryIO.writeTableRows() 我们可以使用lambda从行访问表名,如下所示 BigQueryIO.writeTableRows().to(tablerow->tablerow.get(“Table”).toString()) 但是我们如何使用BigQueryIO.writeTableRo

我有一个TableRow的PCollection,表行中有tablename和schema,如下所示

我需要将col1、col2和col3值插入到前面提到的行中具有模式的表中,使用 BigQueryIO.writeTableRows()

我们可以使用lambda从行访问表名,如下所示 BigQueryIO.writeTableRows().to(tablerow->tablerow.get(“Table”).toString()) 但是我们如何使用BigQueryIO.writeTableRows()和schema()从表行访问模式呢

请帮助

您需要使用为每个元素选择表名和要应用的模式

分解文档的代码示例

events.apply(BigQueryIO.<UserEvent>write()
  .to(new DynamicDestinations<UserEvent, String>() {
// Here you extract the "key" value for the selection of schema and table. 
// If you need the values of the 2 first column, you can create your own structure
// Example: <schema>|<table>
        public String getDestination(ValueInSingleWindow<UserEvent> element) {
          return element.getValue().getUserId();
        }
// Here return the Table destination (dataset and table) according to the "Key"
// If you have the value in your key, you can do key.split("|")[1], according to my previous example
        public TableDestination getTable(String user) {
          return new TableDestination(tableForUser(user), "Table for user " + user);
        }
//Same for the schema here.
        public TableSchema getSchema(String user) {
          return tableSchemaForUser(user);
        }
      })
events.apply(BigQueryIO.write()
.to(新的动态估计){
//在这里,您将提取用于选择模式和表的“key”值。
//如果需要第2列的值,可以创建自己的结构
//例如:|
公共字符串getDestination(ValueInSingleWindow元素){
返回元素.getValue().getUserId();
}
//这里根据“键”返回表目标(数据集和表)
//根据我前面的示例,如果键中有值,则可以执行key.split(“|”)[1]
公共TableDestination可获取(字符串用户){
返回新的TableDestination(tableForUser(用户),“Table for user”+用户);
}
//这里的模式也是如此。
公共表模式getSchema(字符串用户){
返回表chemaforuser(用户);
}
})