MaxonT opened a new pull request, #41750:
URL: https://github.com/apache/beam/pull/41750

   Hi, this adds documentation for dynamic destinations when writing Avro 
files, which #19571 notes was missing; I only touched the docs and left the 
code alone.
   
   Fixes #19571.
   
   ## Description
   
   The issue asks for a pipeline pattern that shows how to write Avro files to 
dynamic locations, and notes that it is not obvious why 
`.withDestinationCoder(StringUtf8Coder.of())` is needed. Thank you to the 
reporter for pointing at the example that people were copying.
   
   This adds a "Writing files to dynamic destinations" section to the File 
processing patterns page, with a compiled snippet in `Snippets.java` that uses 
`FileIO.writeDynamic()` with `AvroIO.sink(schema)`, and a line in the patterns 
overview. The text explains the destination coder: with a lambda in `by()` Beam 
cannot infer the destination type and fails at construction with `Unable to 
infer a coder for destination type`, so the coder has to be given explicitly. 
The section is Java only.
   
   I used `FileIO.writeDynamic()` rather than the 
`AvroIO.write().to(DynamicAvroDestinations)` form in the example linked from 
the issue, because it is the shorter one to explain. If you would rather show 
the `DynamicAvroDestinations` form, I can change it.
   
   ## How Has This Been Tested?
   
   I did not run the Gradle build or the website build. What I ran, in a 
separate Maven project against the released Beam 2.70.0 (`beam-sdks-java-core`, 
`beam-sdks-java-extensions-avro`, `beam-runners-direct-java`) on the 
DirectRunner:
   
   - The snippet text, cut out of the `FileProcessPatternWriteDynamicSnip1` 
region of this branch, compiles and writes one set of Avro files per `country` 
value (`events-NO-00000-of-00002.avro`, `events-SE-00001-of-00002.avro` for two 
sample records).
   - The same pipeline without `.withDestinationCoder(...)` throws 
`IllegalArgumentException: Unable to infer a coder for destination type 
(inferred from .by() as "OutputT") - specify it explicitly using 
.withDestinationCoder()`.
   
   Not checked: 2.79.0-SNAPSHOT (the version on this branch), other runners, 
and how the new section renders on the site.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to