MaxGekk commented on code in PR #49191: URL: https://github.com/apache/spark/pull/49191#discussion_r1923230780
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala: ########## @@ -3723,3 +3723,40 @@ case class Luhncheck(input: Expression) extends RuntimeReplaceable with Implicit override protected def withNewChildrenInternal( newChildren: IndexedSeq[Expression]): Expression = copy(newChildren(0)) } + +/** + * A function that prepends a backslash to each instance of single quote + * in the given string and encloses the result by single quotes. + */ +@ExpressionDescription( + usage = """ + _FUNC_(str) - Returns `str` enclosed by single quotes and + each instance of single quote in it is preceded by a backslash. Review Comment: It would be better to leave one string because the new line character occurs in docs. ########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala: ########## @@ -3723,3 +3723,40 @@ case class Luhncheck(input: Expression) extends RuntimeReplaceable with Implicit override protected def withNewChildrenInternal( newChildren: IndexedSeq[Expression]): Expression = copy(newChildren(0)) } + +/** + * A function that prepends a backslash to each instance of single quote + * in the given string and encloses the result by single quotes. + */ +@ExpressionDescription( + usage = """ + _FUNC_(str) - Returns `str` enclosed by single quotes and + each instance of single quote in it is preceded by a backslash. + """, + examples = """ + Examples: + > SELECT _FUNC_('Don\'t'); + 'Don\'t' + """, + since = "4.0.0", + group = "string_funcs") +case class Quote(input: Expression) extends RuntimeReplaceable with ImplicitCastInputTypes + with UnaryLike[Expression] { + override def nullIntolerant: Boolean = true + + override lazy val replacement: Expression = Invoke(input, "quote", input.dataType) Review Comment: Can't you use `StaticInvoke`? ########## sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala: ########## @@ -1452,4 +1452,21 @@ class StringFunctionsSuite extends QueryTest with SharedSparkSession { Seq(Row("abc", "def"))) } } + + test("SPARK-50582: string quote function") { + val df = Seq(("Don't")).toDF("value") + + checkAnswer( + df.select(quote($"value")), + Row("'Don\\'t'")) + + checkAnswer( + df.selectExpr("quote('Spark')"), + Row("'Spark'") + ) + + checkAnswer( + df.selectExpr("quote(NULL)"), + Row(null)) Review Comment: This is duplicates of checks in `string-functions.sql`? -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org