-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48766][PYTHON] Document the behavior difference of extraction between element_at and try_element_at
#47161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-48766][PYTHON] Document the behavior difference of extraction between element_at and try_element_at
#47161
Conversation
11618a2 to
8365824
Compare
| If extraction is a string, :meth:`element_at` treats it as a literal string, | ||
| while :meth:`try_element_at` treats it as a column name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this behavior difference intentional? Is it consistent with the SQL functions element_at and try_element_at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the SQL side also treat it as a literal:
In [2]: spark.sql("SELECT ELEMENT_AT(MAP('a', 'b'), 'a')").show()
+------------------------+
|element_at(map(a, b), a)|
+------------------------+
| b|
+------------------------+
|
thanks all, merged to master |
|
Late LGTM |
|
|
||
| >>> from pyspark.sql import functions as sf | ||
| >>> df = spark.createDataFrame([({"a": 1.0, "b": 2.0}, "a")], ['data', 'b']) | ||
| >>> df.select(sf.try_element_at(df.data, 'b')).show() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add another example below this?
df.select(sf.try_element_at(df.data, df.b)).show()
Because of the grammar scene above, I took a long time to understand its intended meaning, which is so obscure, 😄
What changes were proposed in this pull request?
Document the behavior difference of
extractionbetweenelement_atandtry_element_atWhy are the changes needed?
when the function
try_element_atwas introduced in 3.5, itsextractionhandling was unintentionally not consistent with theelement_at, which causes confusion.This PR document this behavior difference (I don't think we can fix it since it will be a breaking change).
Does this PR introduce any user-facing change?
doc changes
How was this patch tested?
ci, added doctests
Was this patch authored or co-authored using generative AI tooling?
no