You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/04/30 00:11:13 UTC

[PR] test: demonstrate INT96 read as TimestampNTZ correctness issue [datafusion-comet]

andygrove opened a new pull request, #4154:
URL: https://github.com/apache/datafusion-comet/pull/4154

   ## Which issue does this PR close?
   
   Related to #3720.
   
   ## Rationale for this change
   
   Issue #3720 documents that the `native_datafusion` scan can silently return incorrect timestamp values when a Parquet file stores INT96 timestamps and the read schema requests `TimestampNTZ`. Spark itself raises (SPARK-36182) to prevent the unsafe LTZ to NTZ reinterpretation. There is no regression test on `main` that captures the silent miscompute, so future changes could mask or unmask it without anyone noticing.
   
   This PR adds a single targeted test that demonstrates the bug as it exists on `main`, so we have a reproducer recorded in the test suite that PR #4087 (or any future fix) can convert into a correctness assertion.
   
   ## What changes are included in this PR?
   
   A new `ParquetInt96NtzCorrectnessSuite` containing one test:
   
   1. Configures `SESSION_LOCAL_TIMEZONE=America/Los_Angeles`, `PARQUET_OUTPUT_TIMESTAMP_TYPE=INT96`, and `USE_V1_SOURCE_LIST=parquet`.
   2. Writes `2020-01-01 12:00:00` as `TimestampType` (encoded as INT96).
   3. With Comet disabled, asserts `spark.read.schema("ts timestamp_ntz").parquet(...)` raises `SparkException` (Spark's reference behavior).
   4. With `spark.comet.scan.impl=native_datafusion`, reads the same file as `TimestampNTZ` and asserts the returned `LocalDateTime` does not equal the original `2020-01-01T12:00:00`, capturing the silent wall-clock divergence.
   
   ## How are these changes tested?
   
   The new suite is the test. Verified locally against `apache/main` at `050e1e2f7` with Spark 3.5: the test passes, confirming the divergence between Spark's behavior (throws) and `native_datafusion`'s behavior (returns shifted wall-clock value).


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] test: demonstrate INT96 read as TimestampNTZ correctness issue [datafusion-comet]

Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #4154:
URL: https://github.com/apache/datafusion-comet/pull/4154#discussion_r3165495472


##########
spark/src/test/scala/org/apache/comet/parquet/ParquetInt96NtzCorrectnessSuite.scala:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet.parquet
+
+import java.sql.Timestamp
+import java.time.LocalDateTime
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.internal.SQLConf
+
+import org.apache.comet.CometConf
+
+/**
+ * Demonstrates the correctness issue tracked in
+ * https://github.com/apache/datafusion-comet/issues/3720: when a Parquet file stores timestamps
+ * as INT96 (Spark's TimestampType, UTC-adjusted local-time semantics) and the read schema
+ * requests TimestampNTZ, the `native_datafusion` scan silently returns wall-clock values that
+ * disagree with what was written. Spark itself raises (SPARK-36182) to prevent the silent
+ * reinterpretation.
+ */
+class ParquetInt96NtzCorrectnessSuite extends CometTestBase {
+  import testImplicits._
+
+  test("INT96 TimestampType read as TimestampNTZ silently returns wrong values") {
+    val sessionTz = "America/Los_Angeles"
+    val written = "2020-01-01 12:00:00"
+
+    withSQLConf(
+      SQLConf.SESSION_LOCAL_TIMEZONE.key -> sessionTz,
+      SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key -> "INT96",
+      SQLConf.USE_V1_SOURCE_LIST.key -> "parquet") {
+      withTempPath { dir =>
+        val path = dir.getCanonicalPath
+
+        // Write "2020-01-01 12:00:00" America/Los_Angeles as INT96. The bits encode
+        // the UTC instant 2020-01-01 20:00:00; reading back as TimestampType applies
+        // session-TZ adjustment to recover the original local wall-clock value.
+        Seq(Timestamp.valueOf(written)).toDF("ts").write.parquet(path)
+
+        // Reference behavior: Spark refuses to read INT96 as TimestampNTZ
+        // (SPARK-36182) because it cannot safely reinterpret an LTZ instant as NTZ.
+        withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+          intercept[SparkException] {
+            spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          }
+        }
+
+        // native_datafusion does not refuse; it silently returns a value that
+        // disagrees with the wall-clock value originally written. This is the
+        // correctness issue the safety-check fallback is intended to prevent.
+        withSQLConf(CometConf.COMET_NATIVE_SCAN_IMPL.key -> CometConf.SCAN_NATIVE_DATAFUSION) {
+          val rows = spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          assert(rows.length == 1)
+          val actual = rows.head.getAs[LocalDateTime](0)
+          assert(
+            actual != LocalDateTime.parse("2020-01-01T12:00:00"),
+            s"native_datafusion returned the original wall-clock value $actual; " +

Review Comment:
   Thanks @andygrove . It looks like the strings on lines 75-76 have an s prefix but don't contain any variables.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: fall back to Spark for Parquet scans containing TimestampNTZ [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #4154:
URL: https://github.com/apache/datafusion-comet/pull/4154#issuecomment-4372862542

   @mbutrovich this PR now adds a fallback as discussed, let's see what breaks in CI


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] test: demonstrate INT96 read as TimestampNTZ correctness issue [datafusion-comet]

Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #4154:
URL: https://github.com/apache/datafusion-comet/pull/4154#discussion_r3165495472


##########
spark/src/test/scala/org/apache/comet/parquet/ParquetInt96NtzCorrectnessSuite.scala:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet.parquet
+
+import java.sql.Timestamp
+import java.time.LocalDateTime
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.internal.SQLConf
+
+import org.apache.comet.CometConf
+
+/**
+ * Demonstrates the correctness issue tracked in
+ * https://github.com/apache/datafusion-comet/issues/3720: when a Parquet file stores timestamps
+ * as INT96 (Spark's TimestampType, UTC-adjusted local-time semantics) and the read schema
+ * requests TimestampNTZ, the `native_datafusion` scan silently returns wall-clock values that
+ * disagree with what was written. Spark itself raises (SPARK-36182) to prevent the silent
+ * reinterpretation.
+ */
+class ParquetInt96NtzCorrectnessSuite extends CometTestBase {
+  import testImplicits._
+
+  test("INT96 TimestampType read as TimestampNTZ silently returns wrong values") {
+    val sessionTz = "America/Los_Angeles"
+    val written = "2020-01-01 12:00:00"
+
+    withSQLConf(
+      SQLConf.SESSION_LOCAL_TIMEZONE.key -> sessionTz,
+      SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key -> "INT96",
+      SQLConf.USE_V1_SOURCE_LIST.key -> "parquet") {
+      withTempPath { dir =>
+        val path = dir.getCanonicalPath
+
+        // Write "2020-01-01 12:00:00" America/Los_Angeles as INT96. The bits encode
+        // the UTC instant 2020-01-01 20:00:00; reading back as TimestampType applies
+        // session-TZ adjustment to recover the original local wall-clock value.
+        Seq(Timestamp.valueOf(written)).toDF("ts").write.parquet(path)
+
+        // Reference behavior: Spark refuses to read INT96 as TimestampNTZ
+        // (SPARK-36182) because it cannot safely reinterpret an LTZ instant as NTZ.
+        withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+          intercept[SparkException] {
+            spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          }
+        }
+
+        // native_datafusion does not refuse; it silently returns a value that
+        // disagrees with the wall-clock value originally written. This is the
+        // correctness issue the safety-check fallback is intended to prevent.
+        withSQLConf(CometConf.COMET_NATIVE_SCAN_IMPL.key -> CometConf.SCAN_NATIVE_DATAFUSION) {
+          val rows = spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          assert(rows.length == 1)
+          val actual = rows.head.getAs[LocalDateTime](0)
+          assert(
+            actual != LocalDateTime.parse("2020-01-01T12:00:00"),
+            s"native_datafusion returned the original wall-clock value $actual; " +

Review Comment:
   The CI is failing. It looks like the strings on lines 75-76 have an s prefix but don't contain any variables.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: reject INT96→TimestampNTZ at native reader level (SPARK-36182) [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #4154: fix: reject INT96→TimestampNTZ at native reader level (SPARK-36182)
URL: https://github.com/apache/datafusion-comet/pull/4154


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] test: demonstrate INT96 read as TimestampNTZ correctness issue [datafusion-comet]

Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #4154:
URL: https://github.com/apache/datafusion-comet/pull/4154#discussion_r3165495472


##########
spark/src/test/scala/org/apache/comet/parquet/ParquetInt96NtzCorrectnessSuite.scala:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet.parquet
+
+import java.sql.Timestamp
+import java.time.LocalDateTime
+
+import org.apache.spark.SparkException
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.internal.SQLConf
+
+import org.apache.comet.CometConf
+
+/**
+ * Demonstrates the correctness issue tracked in
+ * https://github.com/apache/datafusion-comet/issues/3720: when a Parquet file stores timestamps
+ * as INT96 (Spark's TimestampType, UTC-adjusted local-time semantics) and the read schema
+ * requests TimestampNTZ, the `native_datafusion` scan silently returns wall-clock values that
+ * disagree with what was written. Spark itself raises (SPARK-36182) to prevent the silent
+ * reinterpretation.
+ */
+class ParquetInt96NtzCorrectnessSuite extends CometTestBase {
+  import testImplicits._
+
+  test("INT96 TimestampType read as TimestampNTZ silently returns wrong values") {
+    val sessionTz = "America/Los_Angeles"
+    val written = "2020-01-01 12:00:00"
+
+    withSQLConf(
+      SQLConf.SESSION_LOCAL_TIMEZONE.key -> sessionTz,
+      SQLConf.PARQUET_OUTPUT_TIMESTAMP_TYPE.key -> "INT96",
+      SQLConf.USE_V1_SOURCE_LIST.key -> "parquet") {
+      withTempPath { dir =>
+        val path = dir.getCanonicalPath
+
+        // Write "2020-01-01 12:00:00" America/Los_Angeles as INT96. The bits encode
+        // the UTC instant 2020-01-01 20:00:00; reading back as TimestampType applies
+        // session-TZ adjustment to recover the original local wall-clock value.
+        Seq(Timestamp.valueOf(written)).toDF("ts").write.parquet(path)
+
+        // Reference behavior: Spark refuses to read INT96 as TimestampNTZ
+        // (SPARK-36182) because it cannot safely reinterpret an LTZ instant as NTZ.
+        withSQLConf(CometConf.COMET_ENABLED.key -> "false") {
+          intercept[SparkException] {
+            spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          }
+        }
+
+        // native_datafusion does not refuse; it silently returns a value that
+        // disagrees with the wall-clock value originally written. This is the
+        // correctness issue the safety-check fallback is intended to prevent.
+        withSQLConf(CometConf.COMET_NATIVE_SCAN_IMPL.key -> CometConf.SCAN_NATIVE_DATAFUSION) {
+          val rows = spark.read.schema("ts timestamp_ntz").parquet(path).collect()
+          assert(rows.length == 1)
+          val actual = rows.head.getAs[LocalDateTime](0)
+          assert(
+            actual != LocalDateTime.parse("2020-01-01T12:00:00"),
+            s"native_datafusion returned the original wall-clock value $actual; " +

Review Comment:
   Thanks @andygrove . The CI is failing. It looks like the strings on lines 75-76 have an s prefix but don't contain any variables.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org