Skip to content

Conversation

@yaooqinn
Copy link
Member

@yaooqinn yaooqinn commented Jun 24, 2019

What changes were proposed in this pull request?

SQL queries like select 1 where in (), which miss the attribute name should throw AnalysisException with Invalid number of arguments for function in as debug message rather than java.lang.UnsupportedOperationException: empty.init.

This problem I guess is related to this pr - #21226

How was this patch tested?

  1. add ut
  2. Manually

Before

select 1 where in ();
19/06/24 13:37:33 ERROR SparkSQLDriver: Failed in [select 1 where in ()]
java.lang.UnsupportedOperationException: empty.init

After

Invalid number of arguments for function in. Expected: 2; Found: 0

@yaooqinn
Copy link
Member Author

cc @cloud-fan

@SparkQA
Copy link

SparkQA commented Jun 24, 2019

Test build #106819 has finished for PR 24947 at commit 4af96a1.

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

@yaooqinn
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Jun 24, 2019

Test build #106823 has finished for PR 24947 at commit 4af96a1.

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

@SparkQA
Copy link

SparkQA commented Jun 24, 2019

Test build #106833 has finished for PR 24947 at commit 9ca1990.

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

@cloud-fan
Copy link
Contributor

does the problem still exist when we turn on spark.sql.parser.ansi.enabled?

@yaooqinn
Copy link
Member Author

@cloud-fan spark.sql.parser.ansi.enabled=true works fine

spark-sql> select 1 where not in ('2019-06-21');
Error in query:
no viable alternative at input 'in'(line 1, pos 19)

== SQL ==
select 1 where not in ('2019-06-21')

@cloud-fan
Copy link
Contributor

Then I think it's a parser issue(and is already fixed), we shouldn't hack FunctionRegistry for it.

@SparkQA
Copy link

SparkQA commented Jun 25, 2019

Test build #106856 has finished for PR 24947 at commit 15c67d6.

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

@SparkQA
Copy link

SparkQA commented Jun 25, 2019

Test build #106866 has finished for PR 24947 at commit 30ef47e.

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

@yaooqinn
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Jun 25, 2019

Test build #106874 has finished for PR 24947 at commit 30ef47e.

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

val expectedNumberOfParameters = if (validParametersCount.length == 1) {
val expectedNumberOfParameters = if (validParametersCount.isEmpty) {
constructors.headOption.map(_.getParameterCount).getOrElse(0).toString
} else if (validParametersCount.length == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

@yaooqinn, can you show the error message before and after this change, and fix the PR description and title? I think this PR now targets throw a better exception for the expression that has no constructors to call.

@yaooqinn yaooqinn changed the title [SPARK-28143][SQL]IN expression missing attribute should throw analysis exception [SPARK-28143][SQL]Expressions without proper constructors should throw AnalysisException Jun 26, 2019
@dongjoon-hyun dongjoon-hyun changed the title [SPARK-28143][SQL]Expressions without proper constructors should throw AnalysisException [SPARK-28143][SQL] Expressions without proper constructors should throw AnalysisException Jul 6, 2019
@srowen
Copy link
Member

srowen commented Jul 16, 2019

@yaooqinn I think there are some last comments to address?

@yaooqinn
Copy link
Member Author

@srowen I have updated the pr description and title as last comment required. If anything I misread, please correct me. Thanks very much.

@srowen
Copy link
Member

srowen commented Jul 17, 2019

@HyukjinKwon is that OK by you?

@SparkQA
Copy link

SparkQA commented Jul 21, 2019

Test build #4826 has finished for PR 24947 at commit 30ef47e.

  • This patch fails Spark unit tests.
  • This patch does not merge cleanly.
  • This patch adds no public classes.

.map(_.getParameterCount).distinct.sorted
val expectedNumberOfParameters = if (validParametersCount.length == 1) {
val expectedNumberOfParameters = if (validParametersCount.isEmpty) {
constructors.headOption.map(_.getParameterCount).getOrElse(0).toString
Copy link
Member

@gatorsmile gatorsmile Jul 22, 2019

Choose a reason for hiding this comment

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

Using headIption is hacky. We should follow the same logic what we are doing here.

val params = Seq.fill(expressions.size)(classOf[Expression])
val f = constructors.find(_.getParameterTypes.toSeq == params).getOrElse {
val validParametersCount = constructors
.filter(_.getParameterTypes.forall(_ == classOf[Expression]))
Copy link
Member

Choose a reason for hiding this comment

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

If we remove this line, what is the outcome?

In this PR, the logic is to add a special case. When unable to find a constructor whose parameters are all Expressions, we use the remaining constructors. [Note, headOption means we only choose the first one] Could you please check whether we should list all of them in the error messages?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we remove this line, it works fine. I did this in the first commit of the pr, discussed with HyukjinKwon here

Copy link
Member

Choose a reason for hiding this comment

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

No, It doesn't work fine.
We should only recognise the constructor with expressions because those are only able to be used in SQL. Otherwise, it shows incorrect information about possible argument combination which partially reverts #21226.

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that we have function registered in but that's unable/not supposed to to call via in(...) currently. Possibly there might be more cases like this.

@SparkQA
Copy link

SparkQA commented Jul 26, 2019

Test build #108197 has finished for PR 24947 at commit a0363de.

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

@yaooqinn
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Jul 26, 2019

Test build #108226 has finished for PR 24947 at commit a0363de.

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

@HyukjinKwon
Copy link
Member

Seems we're blocked by #24947 (comment), shall we close this and investigate if we can remove those functions from function registry? That way will cleanly fix this issue.

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.

8 participants