robertwb commented on code in PR #28855:
URL: https://github.com/apache/beam/pull/28855#discussion_r1349244980
##########
sdks/python/apache_beam/io/avroio.py:
##########
@@ -338,12 +351,15 @@ def split_points_unclaimed(stop_position):
yield record
+_create_avro_source = _FastAvroSource
Review Comment:
Yep, exactly.
##########
sdks/python/apache_beam/io/avroio.py:
##########
@@ -382,17 +398,32 @@ def __init__(
Returns:
A WriteToAvro transform usable for writing.
"""
- self._sink = _create_avro_sink(
+ self._schema = schema
+ self._sink_provider = lambda avro_schema: _create_avro_sink(
file_path_prefix,
- schema,
+ avro_schema,
codec,
file_name_suffix,
num_shards,
shard_name_template,
mime_type)
def expand(self, pcoll):
- return pcoll | beam.io.iobase.Write(self._sink)
+ if self._schema:
+ avro_schema = self._schema
+ records = pcoll
+ else:
+ try:
+ beam_schema = schemas.schema_from_element_type(pcoll.element_type)
+ except TypeError as exn:
+ raise ValueError(
+ "An explicit schema is required to write non-schema'd
PCollections."
+ ) from exn
+ avro_schema = beam_schema_to_avro_schema(beam_schema)
Review Comment:
We also use the absence of an explicit schema to do the pre-processing.
Typically expand is only called once, so caching is not a big savings here
anyway.
--
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]