Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-35288][SQL] StaticInvoke should find the method without exact argument classes match #32413

Closed
wants to merge 10 commits into from

Conversation

viirya
Copy link
Member

@viirya viirya commented May 1, 2021

What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

Why are the changes needed?

Unlike Invoke, StaticInvoke only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, StaticInvoke cannot find the method.

StaticInvoke should be able to find the method under the cases too.

Does this PR introduce any user-facing change?

Yes. StaticInvoke can find a method even the argument classes are not exactly matched.

How was this patch tested?

Unit test.

@github-actions github-actions bot added the SQL label May 1, 2021
@@ -236,7 +236,32 @@ case class StaticInvoke(
override def children: Seq[Expression] = arguments

lazy val argClasses = ScalaReflection.expressionJavaClasses(arguments)
@transient lazy val method = cls.getDeclaredMethod(functionName, argClasses : _*)
@transient lazy val method = {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is duplicated with Invoke. But this will be backported, so I will leave the merging of method only to master branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even though it's for backporting, shall we still avoid duplicated code and add a def findMethod(cls: Class[_]) in the base class?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@SparkQA
Copy link

SparkQA commented May 1, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42655/

@SparkQA
Copy link

SparkQA commented May 1, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42655/

sys.error(s"Couldn't find $functionName on $cls")
} else if (m.length > 1) {
// More than one matched method signature. Exclude synthetic one, e.g. generic one.
val realMethods = m.filter(!_.isSynthetic)
Copy link
Member

Choose a reason for hiding this comment

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

This check is needed for the static case, too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just test it. We can remove it.

@transient lazy val method = cls.getDeclaredMethod(functionName, argClasses : _*)
@transient lazy val method = {
try {
cls.getDeclaredMethod(functionName, argClasses: _*)
Copy link
Member

Choose a reason for hiding this comment

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

btw, java_method can support more cases via the same resolution logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Took a rough look at how java_method resolves the calling method. java_method only calls Java static method, but StaticInvoke covers Scala object method too. java_method's argument types seem only for catalyst primitive data types, so complext type and ObjectType is not supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

We may extend java_method later.

@SparkQA
Copy link

SparkQA commented May 2, 2021

Test build #138134 has finished for PR 32413 at commit cb7e903.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class AddJarsCommand(paths: Seq[String]) extends LeafRunnableCommand
  • case class AddFilesCommand(paths: Seq[String]) extends LeafRunnableCommand
  • case class AddArchivesCommand(paths: Seq[String]) extends LeafRunnableCommand

Comment on lines +641 to +644
val input = (1, 2)
checkObjectExprEvaluation(
Invoke(Literal(obj, clsType), "testFunc", IntegerType, Seq(Literal(1))), 0)
Invoke(Literal(obj, clsType), "testFunc", IntegerType,
Seq(Literal(input, ObjectType(input.getClass)))), 2)
Copy link
Member Author

Choose a reason for hiding this comment

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

Fix this test from SPARK-35278. Original one doesn't produce synthetic method. I may miss it when I changed the code.

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

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

The changes look making sense to me

// Ambiguous case, we don't know which method to choose, just fail it.
sys.error(s"Found ${m.length} $functionName on $cls")
} else {
m.head
Copy link
Member

Choose a reason for hiding this comment

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

I get it, but this may not match. I understand that if I want to pass a String, then a method taking an Object "works" but a method taking a Long does not. Does that just cause other problems, or, are we assuming that because it already fails, we just get a different failure, so whatever? you could inspect the args to see if each isAssignableFrom or something I suppose, but maybe not worth it

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we work best here to find a method for given method name and arguments. For a method taking Object, seems it works to take a String. Adding isAssignableFrom check may work for some cases to catch a failure earily. Although as I test, isAssignableFrom is unable to catch the case if argument class is int and parameter type is Object too.

Copy link
Member Author

Choose a reason for hiding this comment

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

As I plan to backport this, for further improvement I will leave for master only. This change is only for the missing case. Is any update I should do for this change?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to stay conservative for a change you will backport. This will only cause cases that failed completely to possibly work now, right? so I think that's OK.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's OK for 2.4.8. It will only cause code that failed outright before to possibly succeed, right? that's OK then as a fix.

@SparkQA
Copy link

SparkQA commented May 5, 2021

Test build #138155 has finished for PR 32413 at commit d1aa94d.

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

@SparkQA
Copy link

SparkQA commented May 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42676/

@SparkQA
Copy link

SparkQA commented May 5, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42676/

@viirya
Copy link
Member Author

viirya commented May 5, 2021

retest this please

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @viirya .

@SparkQA
Copy link

SparkQA commented May 5, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42702/

@SparkQA
Copy link

SparkQA commented May 5, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42702/

@viirya
Copy link
Member Author

viirya commented May 6, 2021

Thanks @dongjoon-hyun @srowen. @maropu @cloud-fan Need to take another look? I may merge this before this week and backport so I can begin to cut RC4 of 2.4.8.

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented May 6, 2021

I think you can merge this, @viirya . All comments seems to be addressed (including this, #32413 (comment))

@dongjoon-hyun
Copy link
Member

Also, it's okay to wait for @cloud-fan 's comment if this is not that urgent.

@viirya
Copy link
Member Author

viirya commented May 6, 2021

Thanks @dongjoon-hyun @srowen @maropu. Let me wait more a few days. I will merge before the end of this week.

@cloud-fan
Copy link
Contributor

shall we consider #32404 (comment) ?

@SparkQA
Copy link

SparkQA commented May 6, 2021

Test build #138181 has finished for PR 32413 at commit d1aa94d.

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

@viirya
Copy link
Member Author

viirya commented May 6, 2021

shall we consider #32404 (comment) ?

It looks promising. Do you think we should use it even in backports? Or just use it in master only?

@viirya
Copy link
Member Author

viirya commented May 6, 2021

@cloud-fan If we decide to leave using of the util method in master, this is pretty conservative fix, shall we backport this, and then open new PRs for util method in master?

Copy link
Contributor

@cloud-fan cloud-fan left a comment

Choose a reason for hiding this comment

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

@viirya
Copy link
Member Author

viirya commented May 7, 2021

Added the shared method.

@viirya
Copy link
Member Author

viirya commented May 7, 2021

Thanks @cloud-fan @dongjoon-hyun. I will merge once CI passes.

@SparkQA
Copy link

SparkQA commented May 7, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42752/

@SparkQA
Copy link

SparkQA commented May 7, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42752/

@SparkQA
Copy link

SparkQA commented May 7, 2021

Test build #138230 has finished for PR 32413 at commit 0ec8117.

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

@viirya
Copy link
Member Author

viirya commented May 7, 2021

Thanks al! Merging to master/3.1/3.0/2.4.

@viirya viirya closed this in 33fbf56 May 7, 2021
viirya added a commit that referenced this pull request May 7, 2021
…argument classes match

### What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

### Why are the changes needed?

Unlike `Invoke`, `StaticInvoke` only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, `StaticInvoke` cannot find the method.

`StaticInvoke` should be able to find the method under the cases too.

### Does this PR introduce _any_ user-facing change?

Yes. `StaticInvoke` can find a method even the argument classes are not exactly matched.

### How was this patch tested?

Unit test.

Closes #32413 from viirya/static-invoke.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 33fbf56)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
viirya added a commit that referenced this pull request May 7, 2021
…argument classes match

### What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

### Why are the changes needed?

Unlike `Invoke`, `StaticInvoke` only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, `StaticInvoke` cannot find the method.

`StaticInvoke` should be able to find the method under the cases too.

### Does this PR introduce _any_ user-facing change?

Yes. `StaticInvoke` can find a method even the argument classes are not exactly matched.

### How was this patch tested?

Unit test.

Closes #32413 from viirya/static-invoke.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 33fbf56)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
viirya added a commit that referenced this pull request May 7, 2021
…argument classes match

### What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

### Why are the changes needed?

Unlike `Invoke`, `StaticInvoke` only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, `StaticInvoke` cannot find the method.

`StaticInvoke` should be able to find the method under the cases too.

### Does this PR introduce _any_ user-facing change?

Yes. `StaticInvoke` can find a method even the argument classes are not exactly matched.

### How was this patch tested?

Unit test.

Closes #32413 from viirya/static-invoke.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 33fbf56)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
@viirya
Copy link
Member Author

viirya commented May 7, 2021

Then I will prepare a master only PR to use the util method.

flyrain pushed a commit to flyrain/spark that referenced this pull request Sep 21, 2021
…argument classes match

### What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

### Why are the changes needed?

Unlike `Invoke`, `StaticInvoke` only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, `StaticInvoke` cannot find the method.

`StaticInvoke` should be able to find the method under the cases too.

### Does this PR introduce _any_ user-facing change?

Yes. `StaticInvoke` can find a method even the argument classes are not exactly matched.

### How was this patch tested?

Unit test.

Closes apache#32413 from viirya/static-invoke.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 33fbf56)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
fishcus pushed a commit to fishcus/spark that referenced this pull request Jan 12, 2022
…argument classes match

### What changes were proposed in this pull request?

This patch proposes to make StaticInvoke able to find method with given method name even the parameter types do not exactly match to argument classes.

### Why are the changes needed?

Unlike `Invoke`, `StaticInvoke` only tries to get the method with exact argument classes. If the calling method's parameter types are not exactly matched with the argument classes, `StaticInvoke` cannot find the method.

`StaticInvoke` should be able to find the method under the cases too.

### Does this PR introduce _any_ user-facing change?

Yes. `StaticInvoke` can find a method even the argument classes are not exactly matched.

### How was this patch tested?

Unit test.

Closes apache#32413 from viirya/static-invoke.

Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 33fbf56)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
@viirya viirya deleted the static-invoke branch December 27, 2023 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants