[
https://issues.apache.org/jira/browse/BEAM-12803?focusedWorklogId=653213&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-653213
]
ASF GitHub Bot logged work on BEAM-12803:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 20/Sep/21 21:20
Start Date: 20/Sep/21 21:20
Worklog Time Spent: 10m
Work Description: JonathanHourany commented on a change in pull request
#15539:
URL: https://github.com/apache/beam/pull/15539#discussion_r712501402
##########
File path: sdks/python/apache_beam/typehints/native_type_compatibility.py
##########
@@ -107,7 +107,7 @@ def _match_is_exactly_iterable(user_type):
def match_is_named_tuple(user_type):
return (
_safe_issubclass(user_type, typing.Tuple) and
- hasattr(user_type, '_field_types'))
+ hasattr(user_type, '__annotations__'))
Review comment:
Good catch. The only other object I know of off the top of my head that
has `__annotations__` are `dataclasses`, but dataclasses aren't a subclass of
`typing.Tuple` so this function should still return `false` for those
instances. AFIAK it'll only return true if the dataclass sublcasses
`typing.Tuple` or `typing.NamedTuple`
```python
>>> from dataclasses import dataclass
>>> from apache_beam.typehints.native_type_compatibility import
match_is_named_tuple
>>> @dataclass
...: class TestDS():
...: foo: int
>>> match_is_named_tuple(TestDS)
False
```
However
```python
>>> from apache_beam.typehints.native_type_compatibility import
match_is_named_tuple
>>> @dataclass
...: class TestDS(typing.NamedTuple):
...: foo: int
>>> match_is_named_tuple(TestDS)
True
```
edit: updated example
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 653213)
Time Spent: 1h 40m (was: 1.5h)
> SqlTransform doesn't work on python 3.9
> ---------------------------------------
>
> Key: BEAM-12803
> URL: https://issues.apache.org/jira/browse/BEAM-12803
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Reporter: sean teeling
> Assignee: Brian Hulette
> Priority: P2
> Time Spent: 1h 40m
> Remaining Estimate: 0h
>
> Working example below -(Is there no way to paste pre-formatted code into
> jira?!)- (EDIT: I added the appropriate "code" block)
> {code:python}
> import itertools
> import csv
> import io
> import apache_beam as beam
> from apache_beam.dataframe.io import read_csv
> from apache_beam.transforms.sql import SqlTransform
> def parse_csv(val):
> deflower_headers(iterator):
> return itertools.chain([next(iterator).lower()], iterator)
> return csv.DictReader(lower_headers(io.TextIOWrapper(val.open())))
> class BeamTransformBuilder():
> def build(self, pipeline):
> practices = (
> pipeline
> | beam.io.fileio.MatchFiles("data.csv")
> | beam.io.fileio.ReadMatches()
> | beam.Reshuffle()
> | beam.FlatMap(parse_csv)
> | beam.Map(lambda x: beam.Row(id="test-id"))
> | SqlTransform("""
> SELECT
> id
> FROM PCOLLECTION""")
> )
> practices | beam.Map(print)
> def main():
> builder = BeamTransformBuilder()
> with beam.Pipeline('DirectRunner') as p:
> builder.build(p)
> if __name__ == '__main__':
> main()
> {code}
>
> Results in the error:
>
> {code:java}
> File
> "/usr/local/lib/python3.9/site-packages/apache_beam/typehints/schemas.py",
> line 185, in typing_to_runner_api
> element_type = typing_to_runner_api(_get_args(type_)[0])
> IndexError: tuple index out of range
> {code}
>
>
> Tested on Python 3.9.6.
>
> Annoyingly, it is difficult to test this out on other python versions.
> There's no documentation for how to setup a docker container using
> DirectRunner and running it locally. There's barely any documentation on what
> python versions are supported. And using pyenv, and pip install apache-beam
> requires a lot of other downloads that have conflicts when other versions are
> already installed.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)