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-31515][SQL] Canonicalize Cast should consider the value of needTimeZone #28288

Closed
wants to merge 3 commits into from

Conversation

xuanyuanking
Copy link
Member

What changes were proposed in this pull request?

Override the canonicalized fields with respect to the result of needsTimeZone.

Why are the changes needed?

The current approach breaks sematic equal of two cast expressions that don't relate with datetime type. If we don't need to use timeZone information casting from type to to type, then the timeZoneId should not influence the canonicalize result.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New UT added.

@SparkQA
Copy link

SparkQA commented Apr 22, 2020

Test build #121605 has finished for PR 28288 at commit 4961eb3.

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

@cloud-fan
Copy link
Contributor

cc @hvanhovell

Comment on lines 52 to 55
case a: AnsiCast if !a.needsTimeZone && a.timeZoneId.nonEmpty =>
a.copy(timeZoneId = None)
case c: Cast if !c.needsTimeZone && c.timeZoneId.nonEmpty =>
c.copy(timeZoneId = None)
Copy link
Member

Choose a reason for hiding this comment

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

case c: CastBase if c.timeZoneId.nonEmpty && !c.needsTimeZone =>
      c.copy(timeZoneId = None)

No need to call needsTimeZone twice.

Copy link
Contributor

Choose a reason for hiding this comment

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

CastBase is not a case class and can't call copy

Copy link
Member

Choose a reason for hiding this comment

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

hmm, ok:

    case c: CastBase if c.timeZoneId.nonEmpty && !c.needsTimeZone => c.withTimeZone(null)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, done in 73f4694.

@SparkQA
Copy link

SparkQA commented Apr 22, 2020

Test build #121614 has finished for PR 28288 at commit 95102cc.

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

@SparkQA
Copy link

SparkQA commented Apr 22, 2020

Test build #121629 has finished for PR 28288 at commit 73f4694.

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

@maropu
Copy link
Member

maropu commented Apr 23, 2020

retest this please

@SparkQA
Copy link

SparkQA commented Apr 23, 2020

Test build #121641 has finished for PR 28288 at commit 73f4694.

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

@maropu maropu closed this in ca90e19 Apr 23, 2020
maropu pushed a commit that referenced this pull request Apr 23, 2020
…dTimeZone

### What changes were proposed in this pull request?
Override the canonicalized fields with respect to the result of `needsTimeZone`.

### Why are the changes needed?
The current approach breaks sematic equal of two cast expressions that don't relate with datetime type. If we don't need to use `timeZone` information casting `from` type to `to` type, then the timeZoneId should not influence the canonicalize result.

### Does this PR introduce any user-facing change?
No.

### How was this patch tested?
New UT added.

Closes #28288 from xuanyuanking/SPARK-31515.

Authored-by: Yuanjian Li <xyliyuanjian@gmail.com>
Signed-off-by: Takeshi Yamamuro <yamamuro@apache.org>
(cherry picked from commit ca90e19)
Signed-off-by: Takeshi Yamamuro <yamamuro@apache.org>
@maropu
Copy link
Member

maropu commented Apr 23, 2020

Thanks, all! Merged to master/3.0

@xuanyuanking
Copy link
Member Author

Thanks for the review!

@xuanyuanking xuanyuanking deleted the SPARK-31515 branch April 23, 2020 07:12
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.

5 participants