Skip to content

Conversation

@AngersZhuuuu
Copy link
Contributor

What changes were proposed in this pull request?

Current Spark SQL SHOW FUNCTIONS don't show !=, <>, between, case
But these expressions is truly functions. We should show it in SQL SHOW FUNCTIONS

Why 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

@HyukjinKwon
Copy link
Member

Actually there are multiple instances (see https://spark.apache.org/docs/latest/api/sql/index.html). Can we remove them from the function list?

@AngersZhuuuu
Copy link
Contributor Author

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.

@HyukjinKwon
Copy link
Member

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

@AngersZhuuuu
Copy link
Contributor Author

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?
I want to add this since show functions in hive will get these four expression and desc function extended != is supported .

@HyukjinKwon
Copy link
Member

Not sure if Hive resuls are correct and we dont have to follow the behaviours that dont make sense.

@AngersZhuuuu
Copy link
Contributor Author

Not sure if Hive resuls are correct and we dont have to follow the behaviours that dont make sense.

Ok, since desc function !=/between/<>/case is supported, maybe we should keep consistent.

@cloud-fan
Copy link
Contributor

Yea we should keep them consistent. Do you know why it's inconsistent now? Is it intentional?

@AngersZhuuuu
Copy link
Contributor Author

Yea we should keep them consistent. Do you know why it's inconsistent now? Is it intentional?

Since !=/<>/between/case don't have expression class, they all change to other manifestation。

For desc function !=/between/<>/case, it was supported by hardcode:

override def run(sparkSession: SparkSession): Seq[Row] = {


checkAnswer(sql("SHOW functions"), getFunctions("*"))
checkAnswer(sql("SHOW functions"), (getFunctions("*") ++
Seq(Row("!="), Row("<>"), Row("between"), Row("case"))))
Copy link
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
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.


test("show functions") {
withUserDefinedFunction("add_one" -> true) {
val numFunctions = FunctionRegistry.functionSet.size.toLong
Copy link
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?

@HyukjinKwon
Copy link
Member

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

@HyukjinKwon
Copy link
Member

ok to test

@SparkQA
Copy link

SparkQA commented Oct 8, 2019

Test build #111907 has finished for PR 26053 at commit 9b8d63e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 9, 2019

Test build #111929 has started for PR 26053 at commit b066088.

@AngersZhuuuu
Copy link
Contributor Author

Jenkins is crashed ?

@HyukjinKwon
Copy link
Member

retest this please

@AngersZhuuuu
Copy link
Contributor Author

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

Do you have some suggestion about this problem, it's a big change.

@HyukjinKwon
Copy link
Member

Alright, let's deal with it later separately.

@AngersZhuuuu
Copy link
Contributor Author

@HyukjinKwon can you help to trigger retest for this PR, seems jenkins is ok.

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Oct 12, 2019

Test build #111948 has finished for PR 26053 at commit b066088.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member

wangyum commented Oct 15, 2019

retest this please

@SparkQA
Copy link

SparkQA commented Oct 15, 2019

Test build #112099 has finished for PR 26053 at commit b066088.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AngersZhuuuu
Copy link
Contributor Author

@HyukjinKwon @cloud-fan
Any more advise


// 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'")
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the error message if users try to redefine =?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we can't fix the problem completely here, let's keep it unchanged and fix them all together later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112143 has finished for PR 26053 at commit 3d6c85d.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

val catalog = sparkSession.sessionState.catalog

if (FunctionsCommand.virtualOperators.contains(functionName.toLowerCase(Locale.ROOT))) {
throw new AnalysisException(s"Cannot drop virtual function '$functionName'")
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, we should make sure the behavior is consistent with other operators.

Copy link
Contributor Author

@AngersZhuuuu AngersZhuuuu Oct 16, 2019

Choose a reason for hiding this comment

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

ditto

OK,

drop function `!=\case\between\<>`

here it will through exception of function not found

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112156 has finished for PR 26053 at commit 85556a6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.


override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried drop function '='? Does Spark fail with "function not found" or "Cannot drop native function"?

Copy link
Contributor Author

@AngersZhuuuu AngersZhuuuu Oct 16, 2019

Choose a reason for hiding this comment

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

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';

Copy link
Contributor

Choose a reason for hiding this comment

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

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") {
Copy link
Contributor

Choose a reason for hiding this comment

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

since the related changes are reverted, we should remove the test as well

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112168 has finished for PR 26053 at commit 22b3487.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112174 has finished for PR 26053 at commit a285290.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112177 has finished for PR 26053 at commit 9f68ead.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

test("show functions") {
withUserDefinedFunction("add_one" -> true) {
val numFunctions = FunctionRegistry.functionSet.size.toLong
val numFunctions = FunctionRegistry.functionSet.size.toLong + 4L
Copy link
Contributor

Choose a reason for hiding this comment

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

ah missed this one. We should use FunctionsCommand.virtualOperators.length to be future-proof.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah missed this one. We should use FunctionsCommand.virtualOperators.length to 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
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 ?

@SparkQA
Copy link

SparkQA commented Oct 17, 2019

Test build #112199 has finished for PR 26053 at commit bc04f99.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Oct 17, 2019

Test build #112201 has finished for PR 26053 at commit 7ac4d16.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Oct 18, 2019

Test build #112263 has finished for PR 26053 at commit 7ac4d16.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan cloud-fan closed this in 9a3dcca Oct 18, 2019
@cloud-fan
Copy link
Contributor

thanks, merging to master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants