riteshghorse commented on code in PR #28855:
URL: https://github.com/apache/beam/pull/28855#discussion_r1348961951
##########
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:
I guess this is for not breaking imports in other files. Looks like it is in
these two files: bigquery.py and bigquery_read_internal.py. So we may able to
get rid of it. Not blocking though!
##########
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:
is it worth storing this computed schema to `self._schema` here?
--
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]