Write just one file per window with WriteToFiles transform
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 204
Description
In this case all message from Pub/Sub topic need accumulate in one text file per window, however WriteToFiles produce many file instead one
```
input = (p
| 'ReadData' >> beam.io.ReadFromPubSub(topic=known_args.input_topic).with_output_types(bytes)
| "Decode" >> beam.Map(lambda x: x.decode('utf-8'))
| 'Parse' >> beam.Map(parse_json)
| 'Data w' >> beam.WindowInto(
FixedWindows(60),
trigger=trigger.AfterWatermark(),
accumulation_mode=AccumulationMode.DISCARDING
)
| 'Group elements into windows' >> beam.Reshuffle()
)
event_data = (input
| 'Filter events' >> beam.Filter(lambda x: x['t']
== 'event')
| 'Encode ' >> beam.Map(lambda x: json.dumps(x))
| 'Write to
file's' >> fileio.WriteToFiles(
path='gs://some/gcs/bucket/',
file_naming=fileio.default_file_naming(
prefix='events',
suffix='.txt'
),
shards=1
)
)
```
Imported from Jira [BEAM-10998](https://issues.apache.org/jira/browse/BEAM-10998). Original Jira may contain additional context.
Reported by: andy_ap.
Contributor guide
Research direction
Start with the Python fileio.WriteToFiles implementation and its windowing and sharding behavior, then reproduce the Pub/Sub-to-GCS example with one-minute fixed windows and shards=1. Compare the produced files with the expected result of one text file per window, and inspect existing tests or documentation around WriteToFiles before defining the regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- google-cloud, python
- Domain
- cloud, data-engineering, stream-processing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100