You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/07/26 15:28:13 UTC
[GitHub] [spark] cloud-fan opened a new pull request, #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
cloud-fan opened a new pull request, #37301:
URL: https://github.com/apache/spark/pull/37301
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'core/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
This PR fixes a mismatch between v1 and v2 SHOW FUNCTIONS command: v1 prints qualified function names such as `spark_catalog.db1.f1`, but v2 only prints the function name. V2 command should follow v1 behavior which makes more sense.
This PR also updates the SHOW FUNCTIONS test suites to match the new behavior.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
keep v1 and v2 commands consistent.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No, v2 SHOW FUNCTIONS is new in Spark 3.4 (not released)
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
updated tests
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37301:
URL: https://github.com/apache/spark/pull/37301#discussion_r930111496
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowFunctionsSuiteBase.scala:
##########
@@ -141,48 +138,35 @@ trait ShowFunctionsSuiteBase extends QueryTest with DDLCommandTestUtils {
funs.foreach(createFunction)
QueryTest.checkAnswer(
sql(s"SHOW USER FUNCTIONS IN $ns LIKE '*'"),
- testFuns.map(testFun => Row(showFun("ns", testFun))))
+ testFuns.map(testFun => Row(qualifiedFunName("ns", testFun))))
QueryTest.checkAnswer(
sql(s"SHOW USER FUNCTIONS IN $ns LIKE '*rc*'"),
- Seq("crc32i", "crc16j").map(testFun => Row(showFun("ns", testFun))))
+ Seq("crc32i", "crc16j").map(testFun => Row(qualifiedFunName("ns", testFun))))
}
}
test("show a function by its string name") {
- assume(!isTempFunctions())
val testFuns = Seq("crc32i", "crc16j")
withNamespaceAndFuns("ns", testFuns) { (ns, funs) =>
assert(sql(s"SHOW USER FUNCTIONS IN $ns").isEmpty)
funs.foreach(createFunction)
QueryTest.checkAnswer(
sql(s"SHOW USER FUNCTIONS IN $ns 'crc32i'"),
- Row(showFun("ns", "crc32i")) :: Nil)
+ Row(qualifiedFunName("ns", "crc32i")) :: Nil)
}
}
test("show functions matched to the '|' pattern") {
- assume(!isTempFunctions())
val testFuns = Seq("crc32i", "crc16j", "date1900", "Date1")
withNamespaceAndFuns("ns", testFuns) { (ns, funs) =>
assert(sql(s"SHOW USER FUNCTIONS IN $ns").isEmpty)
funs.foreach(createFunction)
QueryTest.checkAnswer(
sql(s"SHOW USER FUNCTIONS IN $ns LIKE 'crc32i|date1900'"),
- Seq("crc32i", "date1900").map(testFun => Row(showFun("ns", testFun))))
+ Seq("crc32i", "date1900").map(testFun => Row(qualifiedFunName("ns", testFun))))
QueryTest.checkAnswer(
sql(s"SHOW USER FUNCTIONS IN $ns LIKE 'crc32i|date*'"),
- Seq("crc32i", "date1900", "Date1").map(testFun => Row(showFun("ns", testFun))))
- }
- }
-
- test("show a function by its id") {
Review Comment:
Removing it because it's almost the same as `show a function in the USER name space`
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk closed pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
MaxGekk closed pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
URL: https://github.com/apache/spark/pull/37301
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #37301:
URL: https://github.com/apache/spark/pull/37301#issuecomment-1195632829
cc @MaxGekk
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] MaxGekk commented on pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
MaxGekk commented on PR #37301:
URL: https://github.com/apache/spark/pull/37301#issuecomment-1196799601
+1, LGTM. Merging to master.
Thank you, @cloud-fan and @beliefer for review.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37301:
URL: https://github.com/apache/spark/pull/37301#discussion_r930112075
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowFunctionsSuite.scala:
##########
@@ -26,30 +26,22 @@ import org.apache.spark.sql.execution.command
* table catalogs. The tests that cannot run for all V1 catalogs are located in more
* specific test suites:
*
- * - Temporary functions of V1 catalog:
- * `org.apache.spark.sql.execution.command.v1.ShowTempFunctionsSuite`
- * - Permanent functions of V1 catalog:
- * `org.apache.spark.sql.hive.execution.command.ShowFunctionsSuite`
+ * - V1 In-Memory catalog: `org.apache.spark.sql.execution.command.v1.ShowFunctionsSuite`
+ * - V1 Hive External catalog: `org.apache.spark.sql.hive.execution.command.ShowFunctionsSuite`
*/
trait ShowFunctionsSuiteBase extends command.ShowFunctionsSuiteBase
- with command.TestsV1AndV2Commands
-
-/**
- * The class contains tests for the `SHOW FUNCTIONS` command to check temporary functions.
- */
-class ShowTempFunctionsSuite extends ShowFunctionsSuiteBase with CommandSuiteBase {
- override def commandVersion: String = super[ShowFunctionsSuiteBase].commandVersion
- override protected def isTempFunctions(): Boolean = true
-
+ with command.TestsV1AndV2Commands {
override protected def createFunction(name: String): Unit = {
- spark.udf.register(name, (arg1: Int, arg2: String) => arg2 + arg1)
+ sql(s"CREATE FUNCTION $name AS '${classOf[MyDoubleSum].getName}'")
Review Comment:
V1 in memory catalog supports persistent functions as well: the UDAF interface.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37301:
URL: https://github.com/apache/spark/pull/37301#discussion_r930593095
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowFunctionsExec.scala:
##########
@@ -37,28 +38,27 @@ case class ShowFunctionsExec(
systemScope: Boolean,
pattern: Option[String]) extends V2CommandExec with LeafExecNode {
+ private def applyPattern(names: Seq[String]): Seq[String] = {
+ StringUtils.filterPattern(names.toSeq, pattern.getOrElse("*"))
+ }
+
override protected def run(): Seq[InternalRow] = {
val rows = new ArrayBuffer[InternalRow]()
val systemFunctions = if (systemScope) {
- // All built-in functions
- (FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet).map(_.unquotedString) ++
- // Hard code "<>", "!=", "between", "case", and "||"
- // for now as there is no corresponding functions.
- // "<>", "!=", "between", "case", and "||" is system functions,
- // only show when systemScope=true
- FunctionRegistry.builtinOperators.keys.toSeq
+ // All built-in functions, and operators such as "<>", "||"
+ val builtinFunctions = FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet
+ applyPattern(builtinFunctions.map(_.unquotedString).toSeq ++
+ FunctionRegistry.builtinOperators.keys.toSeq)
} else Seq.empty
val userFunctions = if (userScope) {
// List all temporary functions in the session catalog
- session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString) ++
- // List all functions registered in the given name space of the catalog
- catalog.listFunctions(namespace.toArray).map(_.name()).toSeq
+ applyPattern(session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString)) ++
+ // List all functions registered in the given namespace of the catalog
+ applyPattern(catalog.listFunctions(namespace.toArray).map(_.name())).map { funcName =>
+ (catalog.name() +: namespace :+ funcName).quoted
+ }
} else Seq.empty
- val allFunctions = StringUtils.filterPattern(
- userFunctions ++ systemFunctions,
- pattern.getOrElse("*")).distinct.sorted
Review Comment:
We can't apply only once after this PR. The pattern will be applied to function names only, not qualified names. So I have to apply the pattern separately for persistent functions before generating qualified names.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowFunctionsExec.scala:
##########
@@ -37,28 +38,27 @@ case class ShowFunctionsExec(
systemScope: Boolean,
pattern: Option[String]) extends V2CommandExec with LeafExecNode {
+ private def applyPattern(names: Seq[String]): Seq[String] = {
+ StringUtils.filterPattern(names.toSeq, pattern.getOrElse("*"))
+ }
+
override protected def run(): Seq[InternalRow] = {
val rows = new ArrayBuffer[InternalRow]()
val systemFunctions = if (systemScope) {
- // All built-in functions
- (FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet).map(_.unquotedString) ++
- // Hard code "<>", "!=", "between", "case", and "||"
- // for now as there is no corresponding functions.
- // "<>", "!=", "between", "case", and "||" is system functions,
- // only show when systemScope=true
- FunctionRegistry.builtinOperators.keys.toSeq
+ // All built-in functions, and operators such as "<>", "||"
+ val builtinFunctions = FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet
+ applyPattern(builtinFunctions.map(_.unquotedString).toSeq ++
+ FunctionRegistry.builtinOperators.keys.toSeq)
} else Seq.empty
val userFunctions = if (userScope) {
// List all temporary functions in the session catalog
- session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString) ++
- // List all functions registered in the given name space of the catalog
- catalog.listFunctions(namespace.toArray).map(_.name()).toSeq
+ applyPattern(session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString)) ++
+ // List all functions registered in the given namespace of the catalog
+ applyPattern(catalog.listFunctions(namespace.toArray).map(_.name())).map { funcName =>
+ (catalog.name() +: namespace :+ funcName).quoted
+ }
} else Seq.empty
- val allFunctions = StringUtils.filterPattern(
- userFunctions ++ systemFunctions,
- pattern.getOrElse("*")).distinct.sorted
Review Comment:
We can't apply only once after this PR. The pattern should be applied to function names only, not qualified names. So I have to apply the pattern separately for persistent functions before generating qualified names.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on a diff in pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
beliefer commented on code in PR #37301:
URL: https://github.com/apache/spark/pull/37301#discussion_r930601452
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowFunctionsExec.scala:
##########
@@ -37,28 +38,27 @@ case class ShowFunctionsExec(
systemScope: Boolean,
pattern: Option[String]) extends V2CommandExec with LeafExecNode {
+ private def applyPattern(names: Seq[String]): Seq[String] = {
+ StringUtils.filterPattern(names.toSeq, pattern.getOrElse("*"))
+ }
+
override protected def run(): Seq[InternalRow] = {
val rows = new ArrayBuffer[InternalRow]()
val systemFunctions = if (systemScope) {
- // All built-in functions
- (FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet).map(_.unquotedString) ++
- // Hard code "<>", "!=", "between", "case", and "||"
- // for now as there is no corresponding functions.
- // "<>", "!=", "between", "case", and "||" is system functions,
- // only show when systemScope=true
- FunctionRegistry.builtinOperators.keys.toSeq
+ // All built-in functions, and operators such as "<>", "||"
+ val builtinFunctions = FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet
+ applyPattern(builtinFunctions.map(_.unquotedString).toSeq ++
+ FunctionRegistry.builtinOperators.keys.toSeq)
} else Seq.empty
val userFunctions = if (userScope) {
// List all temporary functions in the session catalog
- session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString) ++
- // List all functions registered in the given name space of the catalog
- catalog.listFunctions(namespace.toArray).map(_.name()).toSeq
+ applyPattern(session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString)) ++
+ // List all functions registered in the given namespace of the catalog
+ applyPattern(catalog.listFunctions(namespace.toArray).map(_.name())).map { funcName =>
+ (catalog.name() +: namespace :+ funcName).quoted
+ }
} else Seq.empty
- val allFunctions = StringUtils.filterPattern(
- userFunctions ++ systemFunctions,
- pattern.getOrElse("*")).distinct.sorted
Review Comment:
I see. function names has been qualified.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on a diff in pull request #37301: [SPARK-39880][SQL] V2 SHOW FUNCTIONS command should print qualified function name like v1
Posted by GitBox <gi...@apache.org>.
beliefer commented on code in PR #37301:
URL: https://github.com/apache/spark/pull/37301#discussion_r930584912
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowFunctionsExec.scala:
##########
@@ -37,28 +38,27 @@ case class ShowFunctionsExec(
systemScope: Boolean,
pattern: Option[String]) extends V2CommandExec with LeafExecNode {
+ private def applyPattern(names: Seq[String]): Seq[String] = {
+ StringUtils.filterPattern(names.toSeq, pattern.getOrElse("*"))
+ }
+
override protected def run(): Seq[InternalRow] = {
val rows = new ArrayBuffer[InternalRow]()
val systemFunctions = if (systemScope) {
- // All built-in functions
- (FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet).map(_.unquotedString) ++
- // Hard code "<>", "!=", "between", "case", and "||"
- // for now as there is no corresponding functions.
- // "<>", "!=", "between", "case", and "||" is system functions,
- // only show when systemScope=true
- FunctionRegistry.builtinOperators.keys.toSeq
+ // All built-in functions, and operators such as "<>", "||"
+ val builtinFunctions = FunctionRegistry.functionSet ++ TableFunctionRegistry.functionSet
+ applyPattern(builtinFunctions.map(_.unquotedString).toSeq ++
+ FunctionRegistry.builtinOperators.keys.toSeq)
} else Seq.empty
val userFunctions = if (userScope) {
// List all temporary functions in the session catalog
- session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString) ++
- // List all functions registered in the given name space of the catalog
- catalog.listFunctions(namespace.toArray).map(_.name()).toSeq
+ applyPattern(session.sessionState.catalog.listTemporaryFunctions().map(_.unquotedString)) ++
+ // List all functions registered in the given namespace of the catalog
+ applyPattern(catalog.listFunctions(namespace.toArray).map(_.name())).map { funcName =>
+ (catalog.name() +: namespace :+ funcName).quoted
+ }
} else Seq.empty
- val allFunctions = StringUtils.filterPattern(
- userFunctions ++ systemFunctions,
- pattern.getOrElse("*")).distinct.sorted
Review Comment:
In my minor opinion, the origin code only call `StringUtils.filterPattern` once, it seems no need create a new method `applyPattern`.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org