[Bug]: Potential issue in python SDF example
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 4.7k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 196
Description
### What happened?
I was checking this example
```
sdks/python/apache_beam/examples/snippets/snippets.py
```
And I think there might be an issue with this line of code
```
file_handle.seek(tracker.current_restriction.start())
```
It should be replaced with
```
file_handle.seek(tracker.current_restriction.start)
```
As the OffsetRange class does not have a method called start(), but just a member variable called start.
In addition to this I would also like to make a question about this excert of code:
```
class FileToWordsFn(beam.DoFn):
def process(
self,
file_name,
# Alternatively, we can let FileToWordsFn itself inherit from
# RestrictionProvider, implement the required methods and let
# tracker=beam.DoFn.RestrictionParam() which will use self as
# the provider.
tracker=beam.DoFn.RestrictionParam(FileToWordsRestrictionProvider())):
with open(file_name) as file_handle:
file_handle.seek(tracker.current_restriction.start())
while tracker.try_claim(file_handle.tell()):
yield read_next_record(file_handle)
# Providing the coder is only necessary if it can not be inferred at
# runtime.
def restriction_coder(self):
return ...
```
Why is is that the seek and tell are done before and it does not do the tryClaim directly with the position returned by the current tracker and leave the seek to when the claim has already been made?
### Issue Priority
Priority: 2
### Issue Component
Component: examples-python
Contributor guide
Assessment
This issue has not been assessed yet.