-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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-49552][PYTHON] Add DataFrame API support for new 'randstr' and 'uniform' SQL functions #48143
Open
dtenedor
wants to merge
28
commits into
apache:master
Choose a base branch
from
dtenedor:dataframes-uniform-randstr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+329
−10
Open
[SPARK-49552][PYTHON] Add DataFrame API support for new 'randstr' and 'uniform' SQL functions #48143
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d9223e5
commit
dtenedor c0a2551
respond to code review comments
dtenedor f6ffde0
respond to code review comments
dtenedor c22fef2
respond to code review comments
dtenedor c78d8f0
fix test
dtenedor 5b6194e
fix test
dtenedor da390f9
fix test
dtenedor 836ec8e
commit
dtenedor 4b41b34
commit
dtenedor 54a1a2e
respond to code review comments
dtenedor c372075
fix function description
dtenedor 515b046
fix test
dtenedor 3504124
fix test
dtenedor 0683318
respond to code review comments
dtenedor 7ec25a8
respond to code review comments
dtenedor 1f5e866
fix RandomSuite
dtenedor 8b64f33
respond to code review comments
dtenedor 0313fbe
commit
dtenedor d54eec7
sync
dtenedor 48f1dde
sync
dtenedor f496e86
commit
dtenedor 160a5f4
respond to code review comments
dtenedor 795f5a6
fix test
dtenedor 6bb123f
fix
dtenedor 05a674c
commit
dtenedor fd3262f
fix test
dtenedor 4929fbd
fix
dtenedor ef7f9e7
fix
dtenedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11861,6 +11861,44 @@ def regexp_like(str: "ColumnOrName", regexp: "ColumnOrName") -> Column: | |
return _invoke_function_over_columns("regexp_like", str, regexp) | ||
|
||
|
||
@_try_remote_functions | ||
def randstr(length: Union[Column, int], seed: Optional[Union[Column, int]] = None) -> Column: | ||
"""Returns a string of the specified length whose characters are chosen uniformly at random from | ||
the following pool of characters: 0-9, a-z, A-Z. The random seed is optional. The string length | ||
must be a constant two-byte or four-byte integer (SMALLINT or INT, respectively). | ||
|
||
.. versionadded:: 4.0.0 | ||
|
||
Parameters | ||
---------- | ||
length : :class:`~pyspark.sql.Column` or int | ||
Number of characters in the string to generate. | ||
seed : :class:`~pyspark.sql.Column` or int | ||
Optional random number seed to use. | ||
|
||
Returns | ||
------- | ||
:class:`~pyspark.sql.Column` | ||
The generated random string with the specified length. | ||
|
||
Examples | ||
-------- | ||
>>> from pyspark.sql import functions as sf | ||
>>> df = spark.createDataFrame([('3',)], ['a']) | ||
>>> df.select(sf.randstr(lit(5), lit(0)).alias('result')).show() | ||
+------+ | ||
|result| | ||
+------+ | ||
| ceV0P| | ||
+------+ | ||
|
||
""" | ||
if seed is None: | ||
return _invoke_function_over_columns("randstr", length) | ||
else: | ||
return _invoke_function_over_columns("randstr", length, seed) | ||
|
||
|
||
@_try_remote_functions | ||
def regexp_count(str: "ColumnOrName", regexp: "ColumnOrName") -> Column: | ||
r"""Returns a count of the number of times that the Java regex pattern `regexp` is matched | ||
|
@@ -12227,6 +12265,52 @@ def unhex(col: "ColumnOrName") -> Column: | |
return _invoke_function_over_columns("unhex", col) | ||
|
||
|
||
@_try_remote_functions | ||
def uniform( | ||
dtenedor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
min: Union[Column, int, float], | ||
max: Union[Column, int, float], | ||
seed: Optional[Union[Column, int]] = None, | ||
) -> Column: | ||
"""Returns a random value with independent and identically distributed (i.i.d.) values with the | ||
specified range of numbers. The random seed is optional. The provided numbers specifying the | ||
minimum and maximum values of the range must be constant. If both of these numbers are integers, | ||
then the result will also be an integer. Otherwise if one or both of these are floating-point | ||
numbers, then the result will also be a floating-point number. | ||
|
||
.. versionadded:: 4.0.0 | ||
|
||
Parameters | ||
---------- | ||
min : :class:`~pyspark.sql.Column`, int, or float | ||
Minimum value in the range. | ||
max : :class:`~pyspark.sql.Column`, int, or float | ||
Maximum value in the range. | ||
seed : :class:`~pyspark.sql.Column` or int | ||
Optional random number seed to use. | ||
|
||
Returns | ||
------- | ||
:class:`~pyspark.sql.Column` | ||
The generated random number within the specified range. | ||
|
||
Examples | ||
-------- | ||
>>> from pyspark.sql import functions as sf | ||
>>> df = spark.createDataFrame([('3',)], ['a']) | ||
>>> df.select(sf.uniform(lit(0), lit(10), lit(0)).alias('result')).show() | ||
+------+ | ||
|result| | ||
+------+ | ||
| 7| | ||
+------+ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, this is done. |
||
""" | ||
if seed is None: | ||
return _invoke_function_over_columns("uniform", min, max) | ||
else: | ||
return _invoke_function_over_columns("uniform", min, max, seed) | ||
|
||
|
||
@_try_remote_functions | ||
def length(col: "ColumnOrName") -> Column: | ||
"""Computes the character length of string data or number of bytes of binary data. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: we normally don't include an empty line at the end of the docstring
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.
Sounds good, this is done.