【问题标题】:Examples using Dataflow with BigQueryIO.Write.Method.STORAGE_WRITE_API将 Dataflow 与 BigQueryIO.Write.Method.STORAGE_WRITE_API 结合使用的示例
【发布时间】:2021-08-11 21:13:00
【问题描述】:

当前的 Dataflow 文档和参考模板(请参阅下面的链接)使用 BigQueryIO.Write.Method.STREAMING_INSERTS 作为 BigQuery 的输入法。

https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/HEAD/src/main/java/com/google/cloud/teleport/templates/PubSubToBigQuery.java

是否有任何代码示例展示了如何将新的STORAGE_WRITE_API 与 Dataflow 一起使用?

【问题讨论】:

    标签: google-cloud-dataflow


    【解决方案1】:

    您可以从 Apache Beam 存储库中看到一个示例,其中我们有 an integration test

        Pipeline p = Pipeline.create(options);
        final int payloadSizeBytes = options.getPayloadSizeBytes();
    
        // Generate input.
        PCollection<Value> values =
            p.apply(
                    GenerateSequence.from(1)
                        .to(1000000)
                        .withRate(options.getRecordsPerSecond(), Duration.standardSeconds(1)))
                .apply(
                    MapElements.into(TypeDescriptor.of(Value.class))
                        .via(
                            l -> {
                              byte[] payload = "".getBytes(StandardCharsets.UTF_8);
                              if (payloadSizeBytes > 0) {
                                payload = new byte[payloadSizeBytes];
                                ThreadLocalRandom.current().nextBytes(payload);
                              }
                              return new AutoValue_BigQueryStorageAPIStreamingIT_Value(
                                  l, ByteBuffer.wrap(payload));
                            }));
    
        values.apply(
            "writeVortex",
            BigQueryIO.<Value>write()
                .useBeamSchema()
                .to(options.getTargetTable())
                .withMethod(Write.Method.STORAGE_WRITE_API)
                .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)
                .withWriteDisposition(WriteDisposition.WRITE_APPEND)
                .withNumStorageWriteApiStreams(options.getNumShards())
                .withTriggeringFrequency(Duration.standardSeconds(options.getTriggerFrequencySec())));
    
        p.run();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 2018-08-24
      • 2010-09-25
      • 1970-01-01
      • 2019-02-10
      • 2016-04-11
      • 1970-01-01
      相关资源
      最近更新 更多