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-35916][SQL] Support subtraction among Date/Timestamp/TimestampWithoutTZ #33115

Closed

Conversation

gengliangwang
Copy link
Member

What changes were proposed in this pull request?

Support the following operations:

  • TimestampWithoutTZ - Date
  • Date - TimestampWithoutTZ
  • TimestampWithoutTZ - Timestamp
  • Timestamp - TimestampWithoutTZ
  • TimestampWithoutTZ - TimestampWithoutTZ

For subtraction between TimestampWithoutTZ and Timestamp, the Timestamp column is cast as TimestampWithoutTZType.

Why are the changes needed?

Support basic subtraction among Date/Timestamp/TimestampWithoutTZ.

Does this PR introduce any user-facing change?

No, the timestamp without time zone type is not release yet.

How was this patch tested?

Unit tests

@@ -386,8 +386,8 @@ class Analyzer(override val catalogManager: CatalogManager)
DatetimeSub(l, r, DateAddInterval(l, UnaryMinus(r, f), ansiEnabled = f))
case (_, CalendarIntervalType | _: DayTimeIntervalType) =>
Cast(DatetimeSub(l, r, TimeAdd(l, UnaryMinus(r, f))), l.dataType)
case (TimestampType, _) => SubtractTimestamps(l, r)
case (_, TimestampType) => SubtractTimestamps(l, r)
case (TimestampType | TimestampWithoutTZType, _) => SubtractTimestamps(l, r)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be case (AnyTimestampType(), _)?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. But we can simplify it with

case _ if AnyTimestampType.unapply(l) || AnyTimestampType.unapply(r) =>

@gengliangwang
Copy link
Member Author

Merging to master

gengliangwang added a commit that referenced this pull request Jun 29, 2021
### What changes were proposed in this pull request?

Replace the type collection `AllTimestampTypes` with the new data type `AnyTimestampType`

### Why are the changes needed?

As discussed in #33115 (comment), it is more convenient to have a new data type "AnyTimestampType" instead of using type collection `AllTimestampTypes`:
1. simplify the pattern match
2. In the default type coercion rules, when implicit casting a type to a TypeCollection type, Spark chooses the first convertible data type as the result. If we are going to make the default timestamp type configurable, having AnyTimestampType is better

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

No

### How was this patch tested?

Existing UT

Closes #33129 from gengliangwang/allTimestampTypes.

Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
@AmplabJenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/44890/

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