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-32090][SQL] Improve UserDefinedType.equal() to make it be symmetrical #28923

Closed
wants to merge 5 commits into from

Conversation

Ngone51
Copy link
Member

@Ngone51 Ngone51 commented Jun 24, 2020

What changes were proposed in this pull request?

This PR fix UserDefinedType.equal() by comparing the UDT class instead of checking acceptsType().

Why are the changes needed?

It's weird that equality comparison between two UDT types can have different result by switching the order:

// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false

Does this PR introduce any user-facing change?

Yes.

Before:

// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false

After:

// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // false
println(udt2 == udt1) // false

How was this patch tested?

Added a unit test.

@Ngone51
Copy link
Member Author

Ngone51 commented Jun 24, 2020

@cloud-fan @HyukjinKwon Please take a look, thanks!

@SparkQA
Copy link

SparkQA commented Jun 24, 2020

Test build #124486 has finished for PR 28923 at commit b29cef0.

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

@maropu
Copy link
Member

maropu commented Jun 25, 2020

LGTM except for the @cloud-fan comment.

@dongjoon-hyun
Copy link
Member

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 for @cloud-fan and @maropu 's comments.

@SparkQA
Copy link

SparkQA commented Jun 27, 2020

Test build #124567 has finished for PR 28923 at commit b29cef0.

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

@dongjoon-hyun
Copy link
Member

The PR title, UserDefinedType.equal() should be symmetrical, seems to be too strong because we will not backport this to branch-3.0 or branch-2.4. Could you revise a little, @Ngone51 ?

@Ngone51 Ngone51 changed the title [SPARK-32090][SQL] UserDefinedType.equal() should be symmetrical [SPARK-32090][SQL] Improve UserDefinedType.equal() to make it be symmetrical Jun 29, 2020
@Ngone51
Copy link
Member Author

Ngone51 commented Jun 29, 2020

@dongjoon-hyun Updated the title, please take another look.

@Ngone51
Copy link
Member Author

Ngone51 commented Jun 29, 2020

Hi all, I've updated the PR according to your comments. Please take another look, thanks!

@dongjoon-hyun
Copy link
Member

Thank you, @Ngone51 and all. Today's 3 commits are only test case changes and I tested locally. The main body is already tested. Merged to master for Apache Spark 3.1.0.

@SparkQA
Copy link

SparkQA commented Jun 29, 2020

Test build #124617 has finished for PR 28923 at commit 28f46de.

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

@Ngone51
Copy link
Member Author

Ngone51 commented Jun 29, 2020

thanks all!!

maropu pushed a commit that referenced this pull request Oct 27, 2020
…etrical

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

This PR fix `UserDefinedType.equal()` by comparing the UDT class instead of checking `acceptsType()`.

### Why are the changes needed?

It's weird that equality comparison between two UDT types can have different result by switching the order:

```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false
```

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

Yes.

Before:
```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false
```

After:
```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // false
println(udt2 == udt1) // false
```

### How was this patch tested?

Added a unit test.

Closes #28923 from Ngone51/fix-udt-equal.

Authored-by: yi.wu <yi.wu@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
maropu pushed a commit that referenced this pull request Oct 27, 2020
…etrical

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

This PR fix `UserDefinedType.equal()` by comparing the UDT class instead of checking `acceptsType()`.

### Why are the changes needed?

It's weird that equality comparison between two UDT types can have different result by switching the order:

```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false
```

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

Yes.

Before:
```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // true
println(udt2 == udt1) // false
```

After:
```scala
// ExampleSubTypeUDT.userClass is a subclass of ExampleBaseTypeUDT.userClass
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
println(udt1 == udt2) // false
println(udt2 == udt1) // false
```

### How was this patch tested?

Added a unit test.

Closes #28923 from Ngone51/fix-udt-equal.

Authored-by: yi.wu <yi.wu@databricks.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@maropu
Copy link
Member

maropu commented Oct 27, 2020

I've backported this into branch-3.0/2.4. For the reason, please see: https://github.com/apache/spark/pull/30157/files#r512494277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants