Viranshul-P opened a new issue, #41702:
URL: https://github.com/apache/beam/issues/41702

   ### What happened?
   
   `WriteToCsv` and `WriteToJson` ignore `num_shards` when the input arrives as 
one batch, which is the usual case for small and medium PCollections. This was 
reported in #34188, which the stale bot closed; it still happens on master 
(`38eed1e5da0`):
   
   ```python
   import apache_beam as beam
   
   with beam.Pipeline() as p:
     (p | beam.Create([beam.Row(a=i) for i in range(30)])
        | beam.io.WriteToCsv('/tmp/out/res', num_shards=3))
   # writes only res-00000-of-00001
   ```
   
   `WriteToText(..., num_shards=3)` on the same data writes three files.
   
   Cause: `_WriteToPandas` (`apache_beam/dataframe/io.py`) does pass 
`shards=num_shards` to `fileio.WriteToFiles`, but `WriteToFiles` assigns a 
shard per element, and each element here is a whole pandas DataFrame batch. One 
batch fills one shard, the other shards get nothing, and the final names count 
only the files written (`-of-00001`).
   
   Proposed fix (ready with a test): when `num_shards > 1`, split each 
DataFrame batch into `num_shards` row ranges before `WriteToFiles`, so every 
shard gets rows. `num_shards=None`, `0` and `1` are unchanged.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [x] Component: IO connector
   
   ---
   Found, reproduced and drafted with Claude Code (Claude Opus 5.5).
   


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