Ronserruya opened a new pull request, #46901:
URL: https://github.com/apache/spark/pull/46901
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR:
https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a
faster review.
7. If you want to add a new configuration, please read the guideline first
for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the
guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
https://issues.apache.org/jira/browse/SPARK-48555
For pyspark, added the ability to use the "Column" type or names of column
for the parameters of the following functions:
- array_remove
- array_position
- map_contains_key
- substring
For scala, added the ability to use "Column" type as the parameters of the
`substring` function
This functionality already exists in the SQL syntax:
```
select array_remove(col1, col2) from values (array(1,2,3), 2)
```
however, it isn't possible to do the same in python
```python
df.select(F.array_remove(F.col("col1"), F.col("col2"))
```
Note that in scala the functions other than `substring` already accepted
Column params (or rather, they accept `Any` and pass whatever the param is to
`lit` so it ends up working), so I only needed to change substring in the
scala side.
### Why are the changes needed?
To align the scala/python API with the SQL one.
### Does this PR introduce _any_ user-facing change?
Yes, added new overloaded functions in scala and changed type
hints/docstrings in python.
### How was this patch tested?
Added doctests for the python changes, and tests in the scala test suites,
then tested both manually and using the CI.
### Was this patch authored or co-authored using generative AI tooling?
No.
### Notes:
- I opened the related JIRA ticket, but looks like I don't have the option
to assign it myself, so if it is required and any reviewer does have
permissions for it, I'd appreciate it
- The "Build" workflow passed successfully, but the "report tes results" one
didn't due to some authorization issue, I see that this is the same for many
other open PRs right now so I assume its ok.
- For the python changes, I tried to follow the convention used by other
functions (such as `array_contains` or `when`), of using `value._jc if
isinstance(value, Column) else value`
- For the scala side, this is the first time I'm touching scala, I think I
covered it all as I tried to match similar changes done in [a similar
PR](https://github.com/apache/spark/pull/46045)
- The same issue also exists for `substring_index` however I wasn't able to
fix this one the same way I did for `substring`. Calling it with a `lit` for
the `count` arg worked, but using a `col` error with a `NumberFormatError` for
"project_value_3". I assume the error is related to trying to parse the Int
[here](https://github.com/apache/spark/blob/7cba1ab4d6acef4e9d73a8e6018b0902aac3a18d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L1449)
. In that case I got lost in the scala code and decided to drop it, but if
anyone knows how to fix this error I could change that function as well.
The contribution is my original work and I license the work to the project
under the project’s open source license.
--
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]