簡體   English   中英

通過 Cloudbuild 將整數替換為 Dataflow yaml

[英]Substitute ints into Dataflow via Cloudbuild yaml

我有一個流式數據流管道,使用 BEAM 2.35 編寫於 Java。 它通過 StorageWriteApi 將數據提交到 BigQuery。 最初代碼看起來像

BigQueryIO.writeTableRows()
  .withTimePartitioning(/* some column */)
  .withClustering(/* another column */)
  .withMethod(BigQueryIO.Write.Method.STORAGE_WRITE_API)
  .withTriggeringFrequency(Duration.standardSeconds(30))
  .withNumStorageWriteApiStreams(20) // want to make this dynamic

此代碼在不同的環境中運行,例如 Dev & Prod。 當我在 Dev 中部署時,我想要 2 個 StorageWriteApiStreams,在 Prod 中我想要 20 個,並且在我使用 Cloudbuild 部署時我試圖傳遞/解析這些值。

cloudbuild-dev.yaml 看起來像

steps:
  - lots-of-steps
args:
 --numStorageWriteApiStreams=${_NUM_STORAGEWRITEAPI_STREAMS}
substitutions:
  _PROJECT: dev-project
  _NUM_STORAGEWRITEAPI_STREAMS: '2'

我用一個接口公開工作代碼中的替換

  ValueProvider<String> getNumStorageWriteApiStreams();
  void setNumStorageWriteApiStreams(ValueProvider<String> numStorageWriteApiStreams);

然后我重構 writeTableRows() 調用以調用 getNumStorageWriteApiStreams()

BigQueryIO.writeTableRows()
  .withTimePartitioning(/* some column */)
  .withClustering(/* another column */)
  .withMethod(BigQueryIO.Write.Method.STORAGE_WRITE_API)
  .withTriggeringFrequency(Duration.standardSeconds(30))
  .withNumStorageWriteApiStreams(Integer.parseInt(String.valueOf(options.getNumStorageWriteApiStreams())))

現在它是動態的,但由於java.lang.IllegalArgumentException: methods with same signature getNumStorageWriteApiStreams() but incompatible return types: [class java.lang.Integer, interface org.apache.beam.sdk.options.ValueProvider]

我的理解是Integer.parseInt返回一個int ,這是我想要的,所以我可以將它傳遞給需要intwithNumStorageWriteApiStreams()

我將不勝感激我能得到的任何幫助謝謝

原來BigQueryOptions.java已經有一個返回 Integer 的方法getNumStorageWriteApiStreams() 。我在不知不覺中試圖用不同的返回重寫它,哎呀。

https://github.com/apache/beam/blob/master/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryOptions。 java#L95-L98

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM