cloud-fan commented on a change in pull request #27915: [SPARK-31159][SQL] 
Rebase date/timestamp from/to Julian calendar in parquet
URL: https://github.com/apache/spark/pull/27915#discussion_r394087112
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetIOSuite.scala
 ##########
 @@ -879,6 +880,72 @@ class ParquetIOSuite extends QueryTest with ParquetTest 
with SharedSparkSession
       assert(metaData.get(SPARK_VERSION_METADATA_KEY) === SPARK_VERSION_SHORT)
     }
   }
+
+  test("compatibility with Spark 2.4 in reading dates/timestamps") {
+    Seq(false, true).foreach { vectorized =>
+      withSQLConf(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> 
vectorized.toString,
+        SQLConf.LEGACY_PARQUET_REBASE_DATETIME.key -> "true") {
+        checkAnswer(
+          
readResourceParquetFile("test-data/before_1582_date_v2_4.snappy.parquet"),
+          Row(java.sql.Date.valueOf("1001-01-01")))
+        checkAnswer(readResourceParquetFile(
+          "test-data/before_1582_timestamp_micros_v2_4.snappy.parquet"),
+          Row(java.sql.Timestamp.valueOf("1001-01-01 01:02:03.123456")))
+        checkAnswer(readResourceParquetFile(
+          "test-data/before_1582_timestamp_millis_v2_4.snappy.parquet"),
+          Row(java.sql.Timestamp.valueOf("1001-01-01 01:02:03.123")))
+         checkAnswer(readResourceParquetFile(
+          "test-data/before_1582_timestamp_int96_v2_4.snappy.parquet"),
+          Row(java.sql.Timestamp.valueOf("1001-01-01 01:02:03.123456")))
+      }
+    }
+  }
+
+  test("rebasing timestamps in write") {
+    Seq(
+      ("TIMESTAMP_MILLIS", "1001-01-01 01:02:03.123", "1001-01-07 
01:09:05.123"),
+      ("TIMESTAMP_MICROS", "1001-01-01 01:02:03.123456", "1001-01-07 
01:09:05.123456"),
+      ("INT96", "1001-01-01 01:02:03.123456", "1001-01-07 01:09:05.123456")
+    ).foreach { case (outType, tsStr, nonRebased) =>
+      withClue(s"output type $outType") {
+        withSQLConf(SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key -> outType) {
+          withTempPath { dir =>
+            val path = dir.getAbsolutePath
+            withSQLConf(SQLConf.LEGACY_PARQUET_REBASE_DATETIME.key -> "true") {
+              Seq(tsStr).toDF("tsS")
+                .select($"tsS".cast("timestamp").as("ts"))
+                .write
+                .parquet(path)
+
+              checkAnswer(spark.read.parquet(path), 
Row(Timestamp.valueOf(tsStr)))
+            }
+            if (outType != "INT96") { // Spark always rebases INT96 timestamps
 
 Review comment:
   maybe we can have an individual test case for INT96 timestamp

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to