tvalentyn opened a new issue, #41914:
URL: https://github.com/apache/beam/issues/41914

   ### What happened?
   
   disclaimer: I used an AI tool to draft this issue.
   
   `fileio.WriteToFiles` with the default file naming fails if a window's 
bounds are outside the years that Python's `datetime` supports (1 to 9999):
   ```
   OverflowError: date value out of range [while running 
'WriteToFiles/ParDo(_MoveTempFilesIntoFinalDestinationFn)']
   ```
   
   `_format_shard` in `sdks/python/apache_beam/io/fileio.py` calls 
`window.start.to_utc_datetime().isoformat()`.
   Such windows are easy to get. `GroupByKey` and `BatchElements` (and so 
`RunInference` and `Enrichment`) give their outputs in the global window the 
timestamp of the end of the global window, which is in the year 294247. For 
example, writing the dead letters of a batched step:
   ```python
   import apache_beam as beam
   from apache_beam.io import fileio
   from apache_beam.transforms import window
   def fail(batch):
     raise ValueError(batch)
   with beam.Pipeline() as p:
     result = (
         p
         | beam.Create(range(4))
         | beam.BatchElements(min_batch_size=2, max_batch_size=2)
         | beam.Map(fail).with_exception_handling())
     _ = (
         result.bad
         | beam.Map(str)
         | beam.WindowInto(window.FixedWindows(60))
         | fileio.WriteToFiles(path='/tmp/dead_letters'))
   ```
   
   Proposed fix: format bounds outside the `datetime` range in the same ISO 
format with the actual year, for example `294247-01-09T04:00:00`. The Java 
SDK's `FileIO` writes such files and names them after the actual year.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [ ] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
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]

Reply via email to