Complete the code to create a Dataflow pipeline that reads from a Pub/Sub topic.
pipeline = beam.Pipeline(options=PipelineOptions()) messages = pipeline | 'ReadFromPubSub' >> beam.io.ReadFromPubSub(topic=[1])
The Pub/Sub topic must be specified with the full resource path including project and topic name.
Complete the code to write the output of the pipeline to a BigQuery table.
output | 'WriteToBigQuery' >> beam.io.WriteToBigQuery(table=[1])
BigQuery table must be specified with the full resource path including project, dataset, and table.
Fix the error in the pipeline options to enable streaming mode.
options = PipelineOptions() options.view_as(StandardOptions).[1] = True
The correct attribute to enable streaming mode is 'streaming' set to True.
Fill both blanks to create a windowed aggregation that sums values every 5 minutes.
windowed_data = data | 'Window' >> beam.WindowInto(beam.window.[1](5 * 60)) result = windowed_data | 'SumValues' >> beam.CombinePerKey([2])
FixedWindows creates fixed time windows. 'sum' sums values per key.
Fill both blanks to filter elements greater than 100 and map keys to uppercase.
filtered = data | 'FilterGreater' >> beam.Filter(lambda x: x[1] [1] 100) mapped = filtered | 'MapKeys' >> beam.Map(lambda x: (x[0][2], x[1])) result = mapped | 'GroupByKey' >> beam.GroupByKey()
Filter uses '>' to keep values greater than 100. Map uses '.upper()' to uppercase keys. GroupByKey groups by keys.