Skip to content

Commit

Permalink
Use fileNameTemplate attribute for file prefix (#31844)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar3tto authored Jul 11, 2024
1 parent 041ccdb commit 9ee961f
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1079,13 +1079,17 @@ public Object[] apply(T element) {
ParDo.of(new MapObjectsArrayToCsvFn(getQuotationMark())))
.setCoder(StringUtf8Coder.of());

String filePrefix = getFileNameTemplate();
if (filePrefix == null) {
filePrefix = UUID.randomUUID().toString().subSequence(0, 8).toString();
}
WriteFilesResult<Void> filesResult =
mappedUserData.apply(
"Write files to specified location",
FileIO.<String>write()
.via(TextIO.sink())
.to(stagingBucketDir)
.withPrefix(UUID.randomUUID().toString().subSequence(0, 8).toString())
.withPrefix(filePrefix)
.withSuffix(".csv")
.withNumShards(numShards)
.withCompression(Compression.GZIP));
Expand Down

0 comments on commit 9ee961f

Please sign in to comment.