Skip to content

Conversation

@gengliangwang
Copy link
Member

@gengliangwang gengliangwang commented Jun 29, 2021

What changes were proposed in this pull request?

Support extracting hour/minute/second fields from timestamp without time zone values. In details, the following syntaxes are supported:

  • extract [hour | minute | second] from timestampWithoutTZ
  • date_part('[hour | minute | second]', timestampWithoutTZ)
  • hour(timestampWithoutTZ)
  • minute(timestampWithoutTZ)
  • second(timestampWithoutTZ)

Why are the changes needed?

Support basic operations for the new timestamp type.

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 test

@github-actions github-actions bot added the SQL label Jun 29, 2021
case (StringType, target: NumericType) => target
case (StringType, DateType) => DateType
case (StringType, TimestampType) => TimestampType
case (StringType, AnyTimestampType) => TimestampType
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 need this for the default implicit cast from string to timestamp type. This regression is found on running extract.sql.

@SparkQA
Copy link

SparkQA commented Jun 29, 2021

Test build #140356 has finished for PR 33136 at commit 877d150.

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

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

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

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

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

@@ -189,6 +189,7 @@ object AnsiTypeCoercion extends TypeCoercionBase {
}

case (DateType, TimestampType) => Some(TimestampType)
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we support Date -> Timestamp NTZ? in case we have such functions in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well we can have it but it is not related to this PR and there is no test case for the change

}

case (DateType, TimestampType) => Some(TimestampType)
case (DateType, AnyTimestampType) => Some(TimestampType)
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we use AnyTimestampType.defaultConcreteType?

Copy link
Member Author

Choose a reason for hiding this comment

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

The default concrete type is TimestampWithoutTZType. The current code is not ready for that yet.
There will be a new flag for the default timestamp type in SQL. Let's revisit this later.

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 just change the default concrete type of AnyTimestampType to TimestampType, which makes more sense.

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

Test build #140426 has finished for PR 33136 at commit 0596534.

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

if s.left.dataType != s.right.dataType =>
val newLeft = castIfNotSameType(s.left, AnyTimestampType.defaultConcreteType)
val newRight = castIfNotSameType(s.right, AnyTimestampType.defaultConcreteType)
val newLeft = castIfNotSameType(s.left, TimestampWithoutTZType)
Copy link
Member Author

Choose a reason for hiding this comment

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

Here the result is the same if casting both to TimestampWithoutTZType or TimestampType. Casting to TimestampWithoutTZType is more straightforward.

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

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

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

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

@gengliangwang
Copy link
Member Author

Merging to master


// Implicit cast between date time types
case (DateType, TimestampType) => TimestampType
case (DateType, AnyTimestampType) => TimestampType
Copy link
Contributor

Choose a reason for hiding this comment

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

here should be AnyTimestampType.defaultConcreteType as well

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 will address this in the PR for extracting date fields.

@SparkQA
Copy link

SparkQA commented Jun 30, 2021

Test build #140437 has finished for PR 33136 at commit c206f2a.

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

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.

3 participants