ahmedabu98 commented on code in PR #30045:
URL: https://github.com/apache/beam/pull/30045#discussion_r1459862152
##########
sdks/python/apache_beam/io/gcp/bigquery.py:
##########
@@ -2244,18 +2250,65 @@ def find_in_nested_dict(schema):
table = bigquery_tools.get_hashable_destination(self.table_reference)
# None type is not supported
triggering_frequency = self.triggering_frequency or 0
- # SchemaTransform expects Beam Rows, so map to Rows first
- if is_rows:
- input_beam_rows = pcoll
- else:
- input_beam_rows = (
+
+ # For dynamic destinations, we first figure out where each row is going.
+ # Then we append the destination to each row before sending it over to
+ # the Java SchemaTransform.
+ # We need to do this here because there are obstacles to passing the
+ # destinations function to Java
+ if callable(table):
+ # call function and append destination to each row
+ input_rows = (
pcoll
- | "Convert dict to Beam Row" >> beam.Map(
- lambda row: bigquery_tools.beam_row_from_dict(row, schema)
- ).with_output_types(
- RowTypeConstraint.from_fields(
-
bigquery_tools.get_beam_typehints_from_tableschema(schema)))
- )
+ | "Append dynamic destinations" >> beam.ParDo(
+ bigquery_tools.AppendDestinationsFn(table),
+ *self.table_side_inputs))
+
+ # if input type is Beam Row, just wrap everything in another Row
+ if is_rows:
+ input_beam_rows = (
+ input_rows
+ | "Wrap in Beam Row" >>
+ beam.Map(lambda row: beam.Row(destination=row[0], record=row[
+ 1])).with_output_types(
+ RowTypeConstraint.from_fields([
+ ('destination', str), ('record', pcoll.element_type)
Review Comment:
Yup
--
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]