Skip to content

Commit

Permalink
[SPARK-34697][SQL] Allow DESCRIBE FUNCTION and SHOW FUNCTIONS explain…
Browse files Browse the repository at this point in the history
… 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 <sarutak@oss.nttdata.com>
Signed-off-by: HyukjinKwon <gurwls223@apache.org>
  • Loading branch information
sarutak authored and HyukjinKwon committed Mar 11, 2021
1 parent 9d3d25b commit fa1cf5c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") ::
Expand All @@ -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)
Expand Down Expand Up @@ -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", "||")
}

0 comments on commit fa1cf5c

Please sign in to comment.