From fa1cf5c207352b4b485d6b0dbed5ce680a377204 Mon Sep 17 00:00:00 2001 From: Kousuke Saruta Date: Thu, 11 Mar 2021 22:11:26 +0900 Subject: [PATCH] [SPARK-34697][SQL] Allow DESCRIBE FUNCTION and SHOW FUNCTIONS explain about || (string concatenation operator) ### What changes were proposed in this pull request? This PR fixes the behavior of `SHOW FUNCTIONS` and `DESCRIBE FUNCTION` for the `||` operator. The result of `SHOW FUNCTIONS` doesn't contains `||` and `DESCRIBE FUNCTION ||` says `Function: || not found.` even though `||` is supported. ### Why are the changes needed? It's a bug. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Confirmed manually with the following commands. ``` spark-sql> DESCRIBE FUNCTION ||; Function: || Usage: expr1 || expr2 - Returns the concatenation of `expr1` and `expr2`. spark-sql> SHOW FUNCTIONS; ! != % ... | || ~ ``` Closes #31800 from sarutak/fix-describe-concat-pipe. Authored-by: Kousuke Saruta Signed-off-by: HyukjinKwon --- .../apache/spark/sql/execution/command/functions.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala index 23b3db739c..25c88d6e63 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala @@ -120,7 +120,8 @@ case class DescribeFunctionCommand( } override def run(sparkSession: SparkSession): Seq[Row] = { - // Hard code "<>", "!=", "between", and "case" for now as there is no corresponding functions. + // Hard code "<>", "!=", "between", "case", and "||" + // for now as there is no corresponding functions. functionName.funcName.toLowerCase(Locale.ROOT) match { case "<>" => Row(s"Function: $functionName") :: @@ -140,6 +141,9 @@ case class DescribeFunctionCommand( "[WHEN expr4 THEN expr5]* [ELSE expr6] END - " + "When `expr1` = `expr2`, returns `expr3`; " + "when `expr1` = `expr4`, return `expr5`; else return `expr6`.") :: Nil + case "||" => + Row("Function: ||") :: + Row("Usage: expr1 || expr2 - Returns the concatenation of `expr1` and `expr2`.") :: Nil case _ => try { val info = sparkSession.sessionState.catalog.lookupFunctionInfo(functionName) @@ -280,5 +284,5 @@ case class RefreshFunctionCommand( object FunctionsCommand { // operators that do not have corresponding functions. // They should be handled `DescribeFunctionCommand`, `ShowFunctionsCommand` - val virtualOperators = Seq("!=", "<>", "between", "case") + val virtualOperators = Seq("!=", "<>", "between", "case", "||") }