beliefer commented on code in PR #41561:
URL: https://github.com/apache/spark/pull/41561#discussion_r1233271566
##########
sql/core/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -4075,6 +4075,210 @@ object functions {
StartsWith(str.expr, prefix.expr)
}
+ /**
+ * Returns the ASCII character having the binary equivalent to `n`.
+ * If n is larger than 256 the result is equivalent to char(n % 256)
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def char(n: Column): Column = withExpr {
+ Chr(n.expr)
+ }
+
+ /**
+ * Removes the leading and trailing space characters from `str`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def btrim(str: Column): Column = withExpr {
+ new StringTrimBoth(str.expr)
+ }
+
+ /**
+ * Remove the leading and trailing `trim` characters from `str`.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def btrim(str: Column, trim: Column): Column = withExpr {
+ new StringTrimBoth(str.expr, trim.expr)
+ }
+
+ /**
+ * Returns the character length of string data or number of bytes of binary
data.
+ * The length of string data includes the trailing spaces.
+ * The length of binary data includes binary zeros.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def char_length(str: Column): Column = withExpr {
+ Length(str.expr)
+ }
+
+ /**
+ * Returns the character length of string data or number of bytes of binary
data.
+ * The length of string data includes the trailing spaces.
+ * The length of binary data includes binary zeros.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def character_length(str: Column): Column = withExpr {
+ Length(str.expr)
+ }
+
+ /**
+ * Returns the ASCII character having the binary equivalent to `n`.
+ * If n is larger than 256 the result is equivalent to chr(n % 256)
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def chr(n: Column): Column = withExpr {
+ Chr(n.expr)
+ }
+
+ /**
+ * Returns a boolean. The value is True if right is found inside left.
+ * Returns NULL if either input expression is NULL. Otherwise, returns False.
+ * Both left or right must be of STRING type.
+ *
+ * @note
+ * Only STRING type is supported in this function, while `contains` in SQL
supports both
+ * STRING and BINARY.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def contains(left: Column, right: Column): Column = withExpr {
+ Contains(left.expr, right.expr)
+ }
+
+ /**
+ * Returns the `n`-th input, e.g., returns `input2` when `n` is 2.
+ * The function returns NULL if the index exceeds the length of the array
+ * and `spark.sql.ansi.enabled` is set to false. If `spark.sql.ansi.enabled`
is set to true,
+ * it throws ArrayIndexOutOfBoundsException for invalid indices.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ @scala.annotation.varargs
+ def elt(inputs: Column*): Column = withExpr {
+ Elt(inputs.map(_.expr))
+ }
+
+ /**
+ * Returns the index (1-based) of the given string (`str`) in the
comma-delimited
+ * list (`strArray`). Returns 0, if the string was not found or if the given
string (`str`)
+ * contains a comma.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def find_in_set(str: Column, strArray: Column): Column = withExpr {
+ FindInSet(str.expr, strArray.expr)
+ }
+
+ /**
+ * Returns true if str matches `pattern` with `escapeChar`, null if any
arguments are null,
+ * false otherwise.
+ *
+ * @group string_funcs
+ * @since 3.5.0
+ */
+ def like(str: Column, pattern: Column, escapeChar: Column): Column =
withExpr {
+ escapeChar.expr match {
+ case escape @ Literal(_, StringType) =>
+ Like(str.expr, pattern.expr, escape.eval().toString.charAt(0))
Review Comment:
```suggestion
case StringLiteral(v) if v.size == 1 =>
Like(str.expr, pattern.expr, v.charAt(0))
```
##########
core/src/main/resources/error/error-classes.json:
##########
@@ -395,6 +395,11 @@
"Input to <functionName> should all be the same type, but it's
<dataType>."
]
},
+ "ESCAPE_CHAR_WRONG_TYPE" : {
+ "message" : [
+ "EscapeChar should be a string literal."
Review Comment:
`'EscapeChar' should be a string literal of length one.`
--
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]