通过Google Cloud Dataflow创建/写入Sharded(Dated)BigQuery表

时间:2016-07-07 00:43:45

标签: google-cloud-platform google-cloud-dataflow apache-beam-io

是否有一个易于理解的示例如何配置流模式Dataflow Pipeline将每个窗口写入单独的BigQuery表(并在必要时创建一个)?

即。 - table_20160701,table_20160702等

1 个答案:

答案 0 :(得分:2)

示例代码:

`

PCollection<TableRow> quotes = 
  quotes.apply(Window.<TableRow>into(CalendarWindows.days(1)))
        .apply(BigQueryIO.Write
          .named("Write")
          .withSchema(schema)
          .to(new SerializableFunction<BoundedWindow, String>() {
            public String apply(BoundedWindow window) {
              // The cast below is safe because CalendarWindows.days(1) produces IntervalWindows.
              String dayString = DateTimeFormat.forPattern("yyyy_MM_dd")
                   .withZone(DateTimeZone.UTC)
                   .print(((IntervalWindow) window).start());
              return "my-project:output.output_table_" + dayString;
            }
          }));
  }

`

从这里采取:

https://github.com/GoogleCloudPlatform/DataflowJavaSDK/blob/master/sdk/src/main/java/com/google/cloud/dataflow/sdk/io/BigQueryIO.java