spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "holdenk (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-13842) Consider __iter__ and __getitem__ methods for pyspark.sql.types.StructType
Date Fri, 25 Mar 2016 21:20:25 GMT

    [ https://issues.apache.org/jira/browse/SPARK-13842?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15212438#comment-15212438
] 

holdenk commented on SPARK-13842:
---------------------------------

This makes some additional sense when we consider that `StructType` in Scala has an `apply`
function which (when given a single column name) returns the corresponding `StructField` -
so part of this could be viewed as API parity.

> Consider __iter__ and __getitem__ methods for pyspark.sql.types.StructType
> --------------------------------------------------------------------------
>
>                 Key: SPARK-13842
>                 URL: https://issues.apache.org/jira/browse/SPARK-13842
>             Project: Spark
>          Issue Type: Improvement
>          Components: PySpark
>    Affects Versions: 1.6.1
>            Reporter: Shea Parkes
>            Priority: Minor
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> It would be nice to consider adding \_\_iter\_\_ and \_\_getitem\_\_ to {{pyspark.sql.types.StructType}}.
 Here are some simplistic suggestions:
> {code}
> def __iter__(self):
>     """Iterate the fields upon request."""
>     return iter(self.fields)
> def __getitem__(self, key):
>     """Return the corresponding StructField"""
>     _fields_dict = dict(zip(self.names, self.fields))
>     try:
>         return _fields_dict[key]
>     except KeyError:
>         raise KeyError('No field named {}'.format(key))
> {code}
> I realize the latter might be a touch more controversial since there could be name collisions.
 Still, I doubt there are that many in practice and it would be quite nice to work with.
> Privately, I have more extensive metadata extraction methods overlaid on this class,
but I imagine the rest of what I have done might go too far for the common user.  If this
request gains traction though, I'll share those other layers.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message