[英]Apache beam Dataflow : File Transfer from Azure to GCS
我試圖將文件從 Azure 容器傳輸到 GCS 存儲桶,但最終出現以下問題
無論如何,Apache 管道可以在不處理文件內容的情況下傳輸文件本身(這樣就不會發生上述問題)? 因為我需要將多個文件從 Azure 容器傳輸到 GCS 存儲桶
下面的代碼我現在用來傳輸文件
String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY_MM_DD_HH_MM_SS3")).toString();
String connectionString = "<<AZURE_STORAGE_CONNECTION_STRING>>";
PipelineOptions options = PipelineOptionsFactory.create();
options.as(BlobstoreOptions.class).setAzureConnectionString(connectionString);
Pipeline p = Pipeline.create(options);
p.apply(TextIO.read().from("azfs://storageaccountname/containername/CSVSample.csv"))
.apply("",FileIO.<String>write().to("azfs://storageaccountname/containername/"+format+"/").withNumShards(1).withSuffix(".csv")
.via(TextIO.sink()));
p.run().waitUntilFinish();
您應該能夠為此目的使用FileIO轉換。
例如(未經測試的偽代碼),
FileIO.match().filepattern("azfs://storageaccountname/containername/CSVSample.csv")
.apply(FileIO.readMatches())
.apply(ParDo.of(new MyWriteDoFn()));
MyWriteDoFn()
上方將是一個DoFn
,它從單個文件中讀取字節(使用AzureBlobStoreFileSystem )並寫入 GCS(使用GCSFileSystem )。 您可以使用帶有正確前綴的FileSystems class 中的 static 方法,而不是直接調用底層 FileSystem 實現的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.