HyukjinKwon commented on a change in pull request #25950: [SPARK-29240][PYTHON]
Pass Py4J column instance to support PySpark column in element_at function
URL: https://github.com/apache/spark/pull/25950#discussion_r329061403
##########
File path: python/pyspark/sql/functions.py
##########
@@ -2052,11 +2052,12 @@ def element_at(col, extraction):
[Row(element_at(data, 1)=u'a'), Row(element_at(data, 1)=None)]
>>> df = spark.createDataFrame([({"a": 1.0, "b": 2.0},), ({},)], ['data'])
- >>> df.select(element_at(df.data, "a")).collect()
+ >>> df.select(element_at(df.data, lit("a"))).collect()
[Row(element_at(data, a)=1.0), Row(element_at(data, a)=None)]
"""
sc = SparkContext._active_spark_context
- return Column(sc._jvm.functions.element_at(_to_java_column(col),
extraction))
+ return Column(sc._jvm.functions.element_at(
+ _to_java_column(col), lit(extraction)._jc)) # noqa: F821 'lit' is
dynamically defined.
Review comment:
Otherwise:
```
flake8 checks failed:
./python/pyspark/sql/functions.py:2059:70: F821 undefined name 'lit'
return Column(sc._jvm.functions.element_at(_to_java_column(col),
lit(extraction)._jc))
^
1 F821 undefined name 'lit'
1
1
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]