[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=342246&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-342246 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 12/Nov/19 22:24 Start Date: 12/Nov/19 22:24 Worklog Time Spent: 10m Work Description: stale[bot] commented on issue #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#issuecomment-553145136 This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the d...@beam.apache.org list. Thank you for your contributions. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 342246) Time Spent: 1h (was: 50m) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 1h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=346377&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-346377 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 20/Nov/19 00:28 Start Date: 20/Nov/19 00:28 Worklog Time Spent: 10m Work Description: stale[bot] commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 346377) Time Spent: 1h 20m (was: 1h 10m) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 1h 20m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=346375&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-346375 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 20/Nov/19 00:28 Start Date: 20/Nov/19 00:28 Worklog Time Spent: 10m Work Description: stale[bot] commented on issue #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#issuecomment-555778965 This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 346375) Time Spent: 1h 10m (was: 1h) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 1h 10m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312375&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312375 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324380075 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: Review comment: There are generally more efficient ways to get filesize than opening it up. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312375) Time Spent: 40m (was: 0.5h) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 40m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312377&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312377 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324379880 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): Review comment: ReadLines (plural) would be more natural. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312377) Time Spent: 50m (was: 40m) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 50m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312372&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312372 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324379615 ## File path: sdks/python/apache_beam/runners/portability/fn_api_runner_test.py ## @@ -1569,6 +1570,22 @@ def test_split_half(self): raise unittest.SkipTest("This test is for a single worker only.") +class FnApiRunnerSdfSourceTest(unittest.TestCase): Review comment: Should this be in apache_beam/io/sdf_line_source_test.py? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312372) Remaining Estimate: 0h Time Spent: 10m > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312370&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312370 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324378364 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): + """ An SplittableDoFn which reads lines from file and as output.""" + def process( + self, + element, + restriction_tracker=core.DoFn.RestrictionParam( + SdfReadLineRestrictionProvider())): +with open(element['file_pattern'], 'rb') as f: + start = restriction_tracker.start_position() + f.seek(start) + if start > 0: +f.seek(-1, os.SEEK_CUR) +start -= 1 +start += len(f.readline()) Review comment: start = f.tell()? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312370) Remaining Estimate: 0h Time Spent: 10m > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312376&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312376 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324378937 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): + """ An SplittableDoFn which reads lines from file and as output.""" + def process( + self, + element, + restriction_tracker=core.DoFn.RestrictionParam( + SdfReadLineRestrictionProvider())): +with open(element['file_pattern'], 'rb') as f: + start = restriction_tracker.start_position() + f.seek(start) + if start > 0: +f.seek(-1, os.SEEK_CUR) +start -= 1 +start += len(f.readline()) + current = start + line = f.readline() Review comment: I would put this line inside the loop, rather than right before it and at the end of the loop. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312376) Time Spent: 40m (was: 0.5h) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 40m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312374&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312374 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324377746 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): + """ An SplittableDoFn which reads lines from file and as output.""" + def process( + self, + element, + restriction_tracker=core.DoFn.RestrictionParam( + SdfReadLineRestrictionProvider())): +with open(element['file_pattern'], 'rb') as f: + start = restriction_tracker.start_position() + f.seek(start) + if start > 0: Review comment: This probably deserves some comments. (I assume you're trying to see if we're starting at a line? What about multi-char newlines (e.g. \r\f)? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312374) Time Spent: 0.5h (was: 20m) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 0.5h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312373&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312373 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324378492 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): + """ An SplittableDoFn which reads lines from file and as output.""" + def process( + self, + element, + restriction_tracker=core.DoFn.RestrictionParam( + SdfReadLineRestrictionProvider())): +with open(element['file_pattern'], 'rb') as f: + start = restriction_tracker.start_position() + f.seek(start) + if start > 0: +f.seek(-1, os.SEEK_CUR) +start -= 1 +start += len(f.readline()) + current = start + line = f.readline() + while restriction_tracker.try_claim(current): +if not line: + return +yield line.rstrip(b'\n') +current += len(line) Review comment: Won't this get off by one due to stripping the newline before adding the value to current? Possibly current = f.tell() would be more consistent. 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312373) Time Spent: 20m (was: 10m) > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 20m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)
[jira] [Work logged] (BEAM-8143) Provide a simple LineSource built on top of SDF
[ https://issues.apache.org/jira/browse/BEAM-8143?focusedWorklogId=312371&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312371 ] ASF GitHub Bot logged work on BEAM-8143: Author: ASF GitHub Bot Created on: 13/Sep/19 21:52 Start Date: 13/Sep/19 21:52 Worklog Time Spent: 10m Work Description: robertwb commented on pull request #9366: [BEAM-8143] Build simple LineSource directly on top of SDF URL: https://github.com/apache/beam/pull/9366#discussion_r324379782 ## File path: sdks/python/apache_beam/io/sdf_line_source.py ## @@ -0,0 +1,89 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +#http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import absolute_import + +import os + +from apache_beam import Create +from apache_beam import pvalue +from apache_beam.io.restriction_trackers import OffsetRange +from apache_beam.io.restriction_trackers import OffsetRestrictionTracker +from apache_beam.transforms import core +from apache_beam.transforms import ptransform + + +class SdfReadLineRestrictionProvider(core.RestrictionProvider): + """ A `core.RestrictionProvider` implementation which provides + `OffsetRestrictionTracker`.""" + def _get_file_size(self, file_name): +with open(file_name, 'rb') as f: + f.seek(0, os.SEEK_END) + return f.tell() + + def initial_restriction(self, element): +return OffsetRange(0, self._get_file_size(element['file_pattern'])) + + def create_tracker(self, restriction): +return OffsetRestrictionTracker(restriction) + + def split(self, element, restriction): +return restriction.split(element['desired_chunk_size']) + + def restriction_size(self, element, restriction): +return restriction.size() + + +class SdfReadLine(core.DoFn): + """ An SplittableDoFn which reads lines from file and as output.""" + def process( + self, + element, + restriction_tracker=core.DoFn.RestrictionParam( + SdfReadLineRestrictionProvider())): +with open(element['file_pattern'], 'rb') as f: Review comment: Should we be using Beam's filesystem here? 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 312371) Remaining Estimate: 0h Time Spent: 10m > Provide a simple LineSource built on top of SDF > --- > > Key: BEAM-8143 > URL: https://issues.apache.org/jira/browse/BEAM-8143 > Project: Beam > Issue Type: New Feature > Components: sdk-py-core >Reporter: Boyuan Zhang >Assignee: Boyuan Zhang >Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.2#803003)