Ronserruya commented on code in PR #46901:
URL: https://github.com/apache/spark/pull/46901#discussion_r1636747630
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -17267,9 +17317,21 @@ def map_contains_key(col: "ColumnOrName", value: Any)
-> Column:
+--------------------------+
| false|
+--------------------------+
+
+ Example 3: Check for key using a column
+
+ >>> from pyspark.sql import functions as sf
+ >>> df = spark.sql("SELECT map(1, 'a', 2, 'b') as data, 1 as key")
+ >>> df.select(sf.map_contains_key("data", sf.col("key"))).show()
+ +---------------------------+
+ |map_contains_key(data, key)|
+ +---------------------------+
+ | true|
+ +---------------------------+
"""
from pyspark.sql.classic.column import _to_java_column
+ value = value._jc if isinstance(value, Column) else value
Review Comment:
Is it?
In spark 3.5.1 this gives me an error
```
df = spark.sql("select map(1, 2, 3, 4) as m, 1 as k")
df.select(F.map_contains_key(df.m, df.k))
# pyspark.errors.exceptions.base.PySparkTypeError: [NOT_ITERABLE] Column is
not iterable.
```
which makes sense since you try to pass a Column type to `_invoke_function`
which expects only native types or JavaObject for the args
##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -14034,9 +14053,22 @@ def array_position(col: "ColumnOrName", value: Any) ->
Column:
+-----------------------+
| 3|
+-----------------------+
+
+ Example 6: Finding the position of a column's value in an array of integers
+
+ >>> from pyspark.sql import functions as sf
+ >>> df = spark.createDataFrame([([10, 20, 30], 20)], ['data', 'col'])
+ >>> df.select(sf.array_position(df.data, df.col)).show()
+ +-------------------------+
+ |array_position(data, col)|
+ +-------------------------+
+ | 2|
+ +-------------------------+
+
"""
from pyspark.sql.classic.column import _to_java_column
+ value = value._jc if isinstance(value, Column) else value
Review Comment:
it does, but some of the other functions like `array_contained` used this
method to "convert" to a jc. I agree though calling `_to_java_column` is nicer,
so ill change that
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]