Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.apache.spark.sql.catalyst.FunctionIdentifier
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, NoSuchFunctionException}
import org.apache.spark.sql.catalyst.catalog.{CatalogFunction, FunctionResource}
import org.apache.spark.sql.catalyst.expressions.{Attribute, ExpressionInfo}
import org.apache.spark.sql.catalyst.util.StringUtils
import org.apache.spark.sql.types.{StringType, StructField, StructType}


Expand Down Expand Up @@ -222,6 +223,13 @@ case class ShowFunctionsCommand(
case (f, "USER") if showUserFunctions => f.unquotedString
case (f, "SYSTEM") if showSystemFunctions => f.unquotedString
}
functionNames.sorted.map(Row(_))
if (showSystemFunctions) {
(functionNames ++
StringUtils.filterPattern(Seq("!=", "<>", "between", "case"), pattern.getOrElse("*")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add comment like

// Hard code "<>", "!=", "between", and "case" for now as there is no corresponding functions.

.sorted.map(Row(_))
} else {
functionNames.sorted.map(Row(_))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession {

createFunction(functions)

checkAnswer(sql("SHOW functions"), getFunctions("*"))
checkAnswer(sql("SHOW functions"), (getFunctions("*") ++
Seq(Row("!="), Row("<>"), Row("between"), Row("case"))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shall we put this code in getFunctions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shall we put this code in getFunctions?

Good ideal, I will try this.

assert(sql("SHOW functions").collect().size > 200)

Seq("^c*", "*e$", "log*", "*date*").foreach { pattern =>
// For the pattern part, only '*' and '|' are allowed as wildcards.
// For '*', we need to replace it to '.*'.
checkAnswer(sql(s"SHOW FUNCTIONS '$pattern'"), getFunctions(pattern))
checkAnswer(sql(s"SHOW FUNCTIONS '$pattern'"),
getFunctions(pattern) ++
StringUtils.filterPattern(Seq("!=", "<>", "between", "case"), pattern).map(Row(_)))
}
dropFunction(functions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2065,14 +2065,14 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils {
test("show functions") {
withUserDefinedFunction("add_one" -> true) {
val numFunctions = FunctionRegistry.functionSet.size.toLong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we update it with val numFunctions = ... + 4?

assert(sql("show functions").count() === numFunctions)
assert(sql("show system functions").count() === numFunctions)
assert(sql("show all functions").count() === numFunctions)
assert(sql("show functions").count() === numFunctions + 4L)
assert(sql("show system functions").count() === numFunctions + 4L)
assert(sql("show all functions").count() === numFunctions + 4L)
assert(sql("show user functions").count() === 0L)
spark.udf.register("add_one", (x: Long) => x + 1)
assert(sql("show functions").count() === numFunctions + 1L)
assert(sql("show system functions").count() === numFunctions)
assert(sql("show all functions").count() === numFunctions + 1L)
assert(sql("show functions").count() === numFunctions + 5L)
assert(sql("show system functions").count() === numFunctions + 4L)
assert(sql("show all functions").count() === numFunctions + 5L)
assert(sql("show user functions").count() === 1L)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
checkAnswer(
sql("SELECT testUDFToListInt(s) FROM inputTable"),
Seq(Row(Seq(1, 2, 3))))
assert(sql("show functions").count() == numFunc + 1)
assert(sql("show functions").count() == numFunc + 5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Could you help to trigger retest ?

assert(spark.catalog.listFunctions().count() == numFunc + 1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
allBuiltinFunctions.foreach { f =>
assert(allFunctions.contains(f))
}

Seq("!=", "<>", "between", "case").foreach { f =>
assert(allFunctions.contains(f))
}

withTempDatabase { db =>
def createFunction(names: Seq[String]): Unit = {
names.foreach { name =>
Expand Down