You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "panbingkun (via GitHub)" <gi...@apache.org> on 2023/06/14 11:23:09 UTC
[GitHub] [spark] panbingkun opened a new pull request, #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
panbingkun opened a new pull request, #41594:
URL: https://github.com/apache/spark/pull/41594
### What changes were proposed in this pull request?
Add following functions:
- replace
- split_part
- substr
- parse_url
- printf
- url_decode
- url_encode
- position
- endswith
- startswith
to:
- Scala API
- Python API
- Spark Connect Scala Client
- Spark Connect Python Client
### Why are the changes needed?
for parity
### Does this PR introduce _any_ user-facing change?
Yes, new functions.
### How was this patch tested?
- Add New UT.
- Pass GA.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] zhengruifeng commented on pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #41594:
URL: https://github.com/apache/spark/pull/41594#issuecomment-1595620586
also cc @beliefer
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] panbingkun commented on pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "panbingkun (via GitHub)" <gi...@apache.org>.
panbingkun commented on PR #41594:
URL: https://github.com/apache/spark/pull/41594#issuecomment-1595682077
This is all done.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] zhengruifeng commented on pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #41594:
URL: https://github.com/apache/spark/pull/41594#issuecomment-1595992832
thanks, merged to master
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] zhengruifeng closed pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng closed pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
URL: https://github.com/apache/spark/pull/41594
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on a diff in pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "beliefer (via GitHub)" <gi...@apache.org>.
beliefer commented on code in PR #41594:
URL: https://github.com/apache/spark/pull/41594#discussion_r1232965383
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala:
##########
@@ -2344,7 +2344,63 @@ class PlanGenerationTestSuite
}
functionTest("to_number") {
- fn.to_char(fn.col("g"), lit("$99.99"))
+ fn.to_number(fn.col("g"), lit("$99.99"))
+ }
+
+ functionTest("replace") {
+ fn.replace(fn.col("g"), fn.col("g"))
+ }
+
+ functionTest("replace with replace") {
Review Comment:
replace with specified string
##########
sql/core/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -3815,6 +3815,180 @@ object functions {
ToNumber(e.expr, format.expr)
}
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `str`, `str` is returned unchanged.
+ * @param replace
+ * A column of string, If `replace` is not specified or is an empty string, nothing replaces
+ * the string that is removed from `str`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column, replace: Column): Column = withExpr {
+ StringReplace(src.expr, search.expr, replace.expr)
+ }
+
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `src`, `src` is returned unchanged.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column): Column = withExpr {
+ new StringReplace(src.expr, search.expr)
+ }
+
+ /**
+ * Splits `str` by delimiter and return requested part of the split (1-based).
+ * If any input is null, returns null. if `partNum` is out of range of split parts,
+ * returns empty string. If `partNum` is 0, throws an error. If `partNum` is negative,
+ * the parts are counted backward from the end of the string.
+ * If the `delimiter` is an empty string, the `str` is not split.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def split_part(str: Column, delimiter: Column, partNum: Column): Column = withExpr {
+ SplitPart(str.expr, delimiter.expr, partNum.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos` and is of length `len`,
+ * or the slice of byte array that starts at `pos` and is of length `len`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column, len: Column): Column = withExpr {
+ Substring(str.expr, pos.expr, len.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos`,
+ * or the slice of byte array that starts at `pos`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column): Column = withExpr {
+ new Substring(str.expr, pos.expr)
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column, key: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr, key.expr))
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr))
+ }
+
+ /**
+ * Formats the arguments in printf-style and returns the result as a string column.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def printf(format: Column, arguments: Column*): Column = withExpr {
+ FormatString((lit(format) +: arguments).map(_.expr): _*)
+ }
+
+ /**
+ * Decodes a `str` in 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_decode(str: Column): Column = withExpr {
+ UrlDecode(str.expr)
+ }
+
+ /**
+ * Translates a string into 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_encode(str: Column): Column = withExpr {
+ UrlEncode(str.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `start`.
+ * The given `start` and return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column, start: Column): Column = withExpr {
+ StringLocate(substr.expr, str.expr, start.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `1`.
+ * The return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column): Column = withExpr {
+ new StringLocate(substr.expr, str.expr)
+ }
+
+ /**
+ * Returns a boolean. The value is True if str ends with suffix.
+ * Returns NULL if either input expression is NULL. Otherwise, returns False.
+ * Both str or suffix must be of STRING type.
+ *
+ * @note
Review Comment:
+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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] zhengruifeng commented on a diff in pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #41594:
URL: https://github.com/apache/spark/pull/41594#discussion_r1232948262
##########
sql/core/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -3815,6 +3815,180 @@ object functions {
ToNumber(e.expr, format.expr)
}
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `str`, `str` is returned unchanged.
+ * @param replace
+ * A column of string, If `replace` is not specified or is an empty string, nothing replaces
+ * the string that is removed from `str`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column, replace: Column): Column = withExpr {
+ StringReplace(src.expr, search.expr, replace.expr)
+ }
+
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `src`, `src` is returned unchanged.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column): Column = withExpr {
+ new StringReplace(src.expr, search.expr)
+ }
+
+ /**
+ * Splits `str` by delimiter and return requested part of the split (1-based).
+ * If any input is null, returns null. if `partNum` is out of range of split parts,
+ * returns empty string. If `partNum` is 0, throws an error. If `partNum` is negative,
+ * the parts are counted backward from the end of the string.
+ * If the `delimiter` is an empty string, the `str` is not split.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def split_part(str: Column, delimiter: Column, partNum: Column): Column = withExpr {
+ SplitPart(str.expr, delimiter.expr, partNum.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos` and is of length `len`,
+ * or the slice of byte array that starts at `pos` and is of length `len`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column, len: Column): Column = withExpr {
+ Substring(str.expr, pos.expr, len.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos`,
+ * or the slice of byte array that starts at `pos`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column): Column = withExpr {
+ new Substring(str.expr, pos.expr)
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column, key: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr, key.expr))
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr))
+ }
+
+ /**
+ * Formats the arguments in printf-style and returns the result as a string column.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def printf(format: Column, arguments: Column*): Column = withExpr {
+ FormatString((lit(format) +: arguments).map(_.expr): _*)
+ }
+
+ /**
+ * Decodes a `str` in 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_decode(str: Column): Column = withExpr {
+ UrlDecode(str.expr)
+ }
+
+ /**
+ * Translates a string into 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_encode(str: Column): Column = withExpr {
+ UrlEncode(str.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `start`.
+ * The given `start` and return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column, start: Column): Column = withExpr {
+ StringLocate(substr.expr, str.expr, start.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `1`.
+ * The return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column): Column = withExpr {
+ new StringLocate(substr.expr, str.expr)
+ }
+
+ /**
+ * Returns a boolean. The value is True if str ends with suffix.
+ * Returns NULL if either input expression is NULL. Otherwise, returns False.
+ * Both str or suffix must be of STRING type.
+ *
+ * @note
Review Comment:
please update the `@note` here
##########
sql/core/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -3815,6 +3815,180 @@ object functions {
ToNumber(e.expr, format.expr)
}
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `str`, `str` is returned unchanged.
+ * @param replace
+ * A column of string, If `replace` is not specified or is an empty string, nothing replaces
+ * the string that is removed from `str`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column, replace: Column): Column = withExpr {
+ StringReplace(src.expr, search.expr, replace.expr)
+ }
+
+ /**
+ * Replaces all occurrences of `search` with `replace`.
+ *
+ * @param src
+ * A column of string to be replaced
+ * @param search
+ * A column of string, If `search` is not found in `src`, `src` is returned unchanged.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def replace(src: Column, search: Column): Column = withExpr {
+ new StringReplace(src.expr, search.expr)
+ }
+
+ /**
+ * Splits `str` by delimiter and return requested part of the split (1-based).
+ * If any input is null, returns null. if `partNum` is out of range of split parts,
+ * returns empty string. If `partNum` is 0, throws an error. If `partNum` is negative,
+ * the parts are counted backward from the end of the string.
+ * If the `delimiter` is an empty string, the `str` is not split.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def split_part(str: Column, delimiter: Column, partNum: Column): Column = withExpr {
+ SplitPart(str.expr, delimiter.expr, partNum.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos` and is of length `len`,
+ * or the slice of byte array that starts at `pos` and is of length `len`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column, len: Column): Column = withExpr {
+ Substring(str.expr, pos.expr, len.expr)
+ }
+
+ /**
+ * Returns the substring of `str` that starts at `pos`,
+ * or the slice of byte array that starts at `pos`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def substr(str: Column, pos: Column): Column = withExpr {
+ new Substring(str.expr, pos.expr)
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column, key: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr, key.expr))
+ }
+
+ /**
+ * Extracts a part from a URL.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def parse_url(url: Column, partToExtract: Column): Column = withExpr {
+ ParseUrl(Seq(url.expr, partToExtract.expr))
+ }
+
+ /**
+ * Formats the arguments in printf-style and returns the result as a string column.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def printf(format: Column, arguments: Column*): Column = withExpr {
+ FormatString((lit(format) +: arguments).map(_.expr): _*)
+ }
+
+ /**
+ * Decodes a `str` in 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_decode(str: Column): Column = withExpr {
+ UrlDecode(str.expr)
+ }
+
+ /**
+ * Translates a string into 'application/x-www-form-urlencoded' format
+ * using a specific encoding scheme.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def url_encode(str: Column): Column = withExpr {
+ UrlEncode(str.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `start`.
+ * The given `start` and return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column, start: Column): Column = withExpr {
+ StringLocate(substr.expr, str.expr, start.expr)
+ }
+
+ /**
+ * Returns the position of the first occurrence of `substr` in `str` after position `1`.
+ * The return value are 1-based.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def position(substr: Column, str: Column): Column = withExpr {
+ new StringLocate(substr.expr, str.expr)
+ }
+
+ /**
+ * Returns a boolean. The value is True if str ends with suffix.
+ * Returns NULL if either input expression is NULL. Otherwise, returns False.
+ * Both str or suffix must be of STRING type.
+ *
+ * @note
+ * This is different from the `endswith` method in SQL that supports both STRING and BINARY
+ * type.
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def endswith(str: Column, suffix: Column): Column = withExpr {
+ EndsWith(str.expr, suffix.expr)
+ }
+
+ /**
+ * Returns a boolean. The value is True if str starts with prefix.
+ * Returns NULL if either input expression is NULL. Otherwise, returns False.
+ * Both str or prefix must be of STRING type.
+ *
+ * @note
Review Comment:
ditto
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] panbingkun commented on pull request #41594: [SPARK-43944][CONNECT][PYTHON] Add string functions to Scala and Python - part 2
Posted by "panbingkun (via GitHub)" <gi...@apache.org>.
panbingkun commented on PR #41594:
URL: https://github.com/apache/spark/pull/41594#issuecomment-1595580469
cc @zhengruifeng
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org