[SPARK-29379][SQL]SHOW FUNCTIONS show '!=', '<>' , 'between', 'case'#26053
[SPARK-29379][SQL]SHOW FUNCTIONS show '!=', '<>' , 'between', 'case'#26053AngersZhuuuu wants to merge 14 commits intoapache:masterfrom
Conversation
|
Actually there are multiple instances (see https://spark.apache.org/docs/latest/api/sql/index.html). Can we remove them from the function list? |
Not clear what you mean. |
|
Oh do you mean =!, <>, etc. Should be a function? I think its operator, not a function, which actually should be removed from "function"s. cc @cloud-fan and @gatorsmile |
then =, == , < , etc should also be operator? |
|
Not sure if Hive resuls are correct and we dont have to follow the behaviours that dont make sense. |
Ok, since |
|
Yea we should keep them consistent. Do you know why it's inconsistent now? Is it intentional? |
Since For |
|
|
||
| checkAnswer(sql("SHOW functions"), getFunctions("*")) | ||
| checkAnswer(sql("SHOW functions"), (getFunctions("*") ++ | ||
| Seq(Row("!="), Row("<>"), Row("between"), Row("case")))) |
There was a problem hiding this comment.
nit: shall we put this code in getFunctions?
There was a problem hiding this comment.
nit: shall we put this code in
getFunctions?
Good ideal, I will try this.
| @@ -2065,14 +2065,14 @@ abstract class DDLSuite extends QueryTest with SQLTestUtils { | |||
| test("show functions") { | |||
| withUserDefinedFunction("add_one" -> true) { | |||
| val numFunctions = FunctionRegistry.functionSet.size.toLong | |||
There was a problem hiding this comment.
shall we update it with val numFunctions = ... + 4?
|
Keeping it consistent sounds fine for now but I think we should fix this ambiguity between functions and operators at the end; otherwise, we will keep facing an issue such as #24947 |
|
ok to test |
|
Test build #111907 has finished for PR 26053 at commit
|
|
Test build #111929 has started for PR 26053 at commit |
|
Jenkins is crashed ? |
|
retest this please |
Do you have some suggestion about this problem, it's a big change. |
|
Alright, let's deal with it later separately. |
|
@HyukjinKwon can you help to trigger retest for this PR, seems jenkins is ok. |
|
retest this please |
|
Test build #111948 has finished for PR 26053 at commit
|
|
retest this please |
|
Test build #112099 has finished for PR 26053 at commit
|
|
@HyukjinKwon @cloud-fan |
|
|
||
| // Redefine a virtual function is not allowed | ||
| if (FunctionsCommand.virtualOperators.contains(functionName.toLowerCase(Locale.ROOT))) { | ||
| throw new AnalysisException(s"It's not allowed to redefine virtual function '$functionName'") |
There was a problem hiding this comment.
what's the error message if users try to redefine =?
There was a problem hiding this comment.
what's the error message if users try to redefine
=?
can't use create function = ...., since = is a reserved key, we should use
create function `=` ....
Error message:
org.apache.hadoop.hive.ql.metadata.HiveException: InvalidObjectException(message:= is not a valid object name);
org.apache.hadoop.hive.ql.metadata.HiveException: InvalidObjectException(message:> is not a valid object name);
org.apache.hadoop.hive.ql.metadata.HiveException: InvalidObjectException(message:!= is not a valid object name);
but `case` `between` can be registered.
as @HyukjinKwon methoned, we should fix this ambiguity between functions and operators at the end.
There was a problem hiding this comment.
If we can't fix the problem completely here, let's keep it unchanged and fix them all together later.
There was a problem hiding this comment.
If we can't fix the problem completely here, let's keep it unchanged and fix them all together later.
Ok, have remove these code.
|
Test build #112143 has finished for PR 26053 at commit
|
| val catalog = sparkSession.sessionState.catalog | ||
|
|
||
| if (FunctionsCommand.virtualOperators.contains(functionName.toLowerCase(Locale.ROOT))) { | ||
| throw new AnalysisException(s"Cannot drop virtual function '$functionName'") |
There was a problem hiding this comment.
ditto, we should make sure the behavior is consistent with other operators.
There was a problem hiding this comment.
ditto
OK,
drop function `!=\case\between\<>`
here it will through exception of function not found
|
Test build #112156 has finished for PR 26053 at commit
|
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val catalog = sparkSession.sessionState.catalog | ||
|
|
There was a problem hiding this comment.
Have you tried drop function '='? Does Spark fail with "function not found" or "Cannot drop native function"?
There was a problem hiding this comment.
Have you tried
drop function '='? Does Spark fail with "function not found" or "Cannot drop native function"?
Function not found.
Error in query: Function 'default.=' not found in database 'default';
There was a problem hiding this comment.
OK this can be improved later. Let's leave it for now. Thanks for the investigation!
| checkKeywordsExist(sql("describe functioN abcadf"), "Function: abcadf not found.") | ||
| } | ||
|
|
||
| test("drop virtual functions") { |
There was a problem hiding this comment.
since the related changes are reverted, we should remove the test as well
|
Test build #112168 has finished for PR 26053 at commit
|
|
Test build #112174 has finished for PR 26053 at commit
|
|
Test build #112177 has finished for PR 26053 at commit
|
| test("show functions") { | ||
| withUserDefinedFunction("add_one" -> true) { | ||
| val numFunctions = FunctionRegistry.functionSet.size.toLong | ||
| val numFunctions = FunctionRegistry.functionSet.size.toLong + 4L |
There was a problem hiding this comment.
ah missed this one. We should use FunctionsCommand.virtualOperators.length to be future-proof.
There was a problem hiding this comment.
ah missed this one. We should use
FunctionsCommand.virtualOperators.lengthto be future-proof.
Good ideal, make it more clear. Done
| 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) |
There was a problem hiding this comment.
ditto
Could you help to trigger retest ?
|
Test build #112199 has finished for PR 26053 at commit
|
|
Test build #112201 has finished for PR 26053 at commit
|
|
retest this please |
|
Test build #112263 has finished for PR 26053 at commit
|
|
thanks, merging to master! |
What changes were proposed in this pull request?
Current Spark SQL
SHOW FUNCTIONSdon't show!=,<>,between,caseBut these expressions is truly functions. We should show it in SQL
SHOW FUNCTIONSWhy are the changes needed?
SHOW FUNCTIONS show '!=', '<>' , 'between', 'case'
Does this PR introduce any user-facing change?
SHOW FUNCTIONS show '!=', '<>' , 'between', 'case'
How was this patch tested?
UT