You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2020/05/15 20:34:32 UTC
[spark] branch branch-2.4 updated: [SPARK-31712][SQL][TESTS][2.4]
Check casting timestamps before the epoch to Byte/Short/Int/Long types
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-2.4 by this push:
new 8b72eb7 [SPARK-31712][SQL][TESTS][2.4] Check casting timestamps before the epoch to Byte/Short/Int/Long types
8b72eb7 is described below
commit 8b72eb768383d3f4992ca76c6af86dd5b2531a57
Author: Maxim Gekk <ma...@gmail.com>
AuthorDate: Fri May 15 13:31:08 2020 -0700
[SPARK-31712][SQL][TESTS][2.4] Check casting timestamps before the epoch to Byte/Short/Int/Long types
### What changes were proposed in this pull request?
Added tests to check casting timestamps before 1970-01-01 00:00:00Z to ByteType, ShortType, IntegerType and LongType in ansi and non-ansi modes.
This is a backport of https://github.com/apache/spark/pull/28531.
### Why are the changes needed?
To improve test coverage and prevent errors while modifying the CAST expression code.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
By running the modified test suites:
```
$ ./build/sbt "test:testOnly *CastSuite"
```
Closes #28542 from MaxGekk/test-cast-timestamp-to-byte-2.4.
Authored-by: Maxim Gekk <ma...@gmail.com>
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
.../apache/spark/sql/catalyst/expressions/CastSuite.scala | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
index c9a8c29..7616645 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala
@@ -1004,4 +1004,16 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(ret, InternalRow(null))
}
}
+
+ test("cast a timestamp before the epoch 1970-01-01 00:00:00Z") {
+ withDefaultTimeZone(DateTimeUtils.TimeZoneUTC) {
+ val negativeTs = Timestamp.valueOf("1900-05-05 18:34:56.1")
+ assert(negativeTs.getTime < 0)
+ val expectedSecs = Math.floorDiv(negativeTs.getTime, DateTimeUtils.MILLIS_PER_SECOND)
+ checkEvaluation(cast(negativeTs, ByteType), expectedSecs.toByte)
+ checkEvaluation(cast(negativeTs, ShortType), expectedSecs.toShort)
+ checkEvaluation(cast(negativeTs, IntegerType), expectedSecs.toInt)
+ checkEvaluation(cast(negativeTs, LongType), expectedSecs)
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org