Thanatos9404 opened a new issue, #41567:
URL: https://github.com/apache/beam/issues/41567
### What happened?
`FileBasedSink` (used by `WriteToText`, `WriteToAvro`, `WriteToTFRecord`,
`WriteToParquet` and others) builds glob patterns from the output path in
`_get_final_name_glob` and `_check_state_for_finalize_write`, without escaping
it. If the path contains a glob character, for example `[`, which is legal in
local, GCS and S3 paths, the path is read as a pattern:
```python
import os
import apache_beam as beam
d = '/tmp/sink_glob'
os.makedirs(d, exist_ok=True)
# Output of some other job in the same directory.
for name in ['out1-00000-of-00001', 'out2-00000-of-00001']:
with open(os.path.join(d, name), 'w') as f:
f.write('other job')
with beam.Pipeline() as p:
p | beam.Create(['a', 'b']) | beam.io.WriteToText(os.path.join(d,
'out[12]'))
```
- `pre_finalize` matches `out[12]-*-of-00001`, which matches
`out1-00000-of-00001` and `out2-00000-of-00001`, and deletes both ("Deleting 2
existing files in target path matching ...").
- Finalize then fails with `BeamIOError: src and dst files do not exist`,
because the glob for the temporary files, `beam-temp-out[12]-<uuid>/*`, matches
nothing either. Only the temporary directory is left.
A directory with a glob character, such as `WriteToText('/tmp/run[1]/out')`,
fails the same way without deleting anything.
Expected: the path is used literally. The pipeline writes
`out[12]-00000-of-00001` and other files are never touched.
Only the shard name part of these patterns is meant to be a glob, so the
prefix, the suffix and the temporary directory can be escaped (`[` as `[[]`,
`*` as `[*]`, `?` as `[?]`, which `FileSystem.translate_pattern` already reads
as literal characters). I have a PR with tests ready.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Python SDK
- [x] Component: IO connector
--
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]