ump45nose commented on code in PR #7227:
URL: https://github.com/apache/datafusion-comet/pull/7227#discussion_r4738300094


##########
native/core/src/parquet/schema_adapter.rs:
##########
@@ -673,18 +683,45 @@ fn spark_has_updater(
         | (DataType::Date32, DataType::Timestamp(_, Some(_)))
         // Timestamp -> Date.
         | (DataType::Timestamp(_, _), DataType::Date32)
+        // Timestamp -> narrower int, floating point or decimal.
+        | (
+            DataType::Timestamp(_, _),
+            DataType::Int8
+                | DataType::Int16
+                | DataType::Int32
+                | DataType::Float32
+                | DataType::Float64
+                | DataType::Decimal128(_, _)

Review Comment:
   Addressed in df2b5384. The check no longer keys on the Arrow type: 
`NativeSchemaAdapter` stamps each leaf with the Parquet physical type it was 
read from (`INT96_TIMESTAMP_KEY` or `NANOS_TIMESTAMP_KEY`, in addition to the 
Arrow hint), and both the footer path and the row-filter path consult that 
stamp through `PhysicalTypeSource` before deciding whether a conversion is 
allowed or rejected.
   
   That keeps the two cases you raised apart. An `INT64` timestamp whose Arrow 
annotation was lost (ArrowWriter's unannotated UTC seconds, and the second case 
in the issue) is still rejected when it is read back as a non-timestamp type, 
because its leaf is `INT64`; an `INT96` leaf, which Spark reads as a timestamp 
whatever the Arrow hint says, is checked as `INT96` and allowed.



##########
native/core/src/parquet/schema_adapter.rs:
##########
@@ -652,6 +675,8 @@ fn spark_has_updater(
         // Long -> date / timestamp (raw INT64; annotated columns surface as 
Date32/Timestamp).
         | (DataType::Int64, DataType::Date32)
         | (DataType::Int64, DataType::Timestamp(_, _))
+        // Unannotated INT64 that an `ARROW:schema` hint restored as a second 
timestamp.
+        | (DataType::Timestamp(TimeUnit::Second, _), DataType::Timestamp(_, _))

Review Comment:
   Fixed in df2b5384. An `INT96` leaf is now recognised by its Parquet physical 
type rather than by the Arrow type it surfaces as, so `timestamp[s]`-hinted 
`INT96` written by pyarrow with `flavor="spark"` is treated as a timestamp 
column: `spark.read.parquet` reads it normally instead of failing through the 
mismatch arm.
   
   `native scan reads INT96 timestamps with row filter pushdown like Spark` in 
`ParquetReadSuite` covers an `INT96` file read as `timestamp` in both plain and 
nested positions with row-filter pushdown on and off.



##########
native/core/src/parquet/schema_adapter.rs:
##########
@@ -2701,6 +2857,207 @@ pub(crate) mod test {
         Ok(())
     }
 
+    /// A `TIMESTAMP(MICROS)` column read as a string, a narrower integer, a 
float or a decimal:
+    /// Spark has no updater for these, so it rejects them instead of 
returning the timestamp as
+    /// text, the raw value or NULL. Reading it as `bigint` stays allowed. See 
#7214.
+    #[tokio::test]
+    async fn parquet_timestamp_read_as_non_timestamp_errors() -> Result<(), 
DataFusionError> {

Review Comment:
   Added in df2b5384 as `native scan uses Parquet timestamp encodings for 
conversion checks` in 
`spark/src/test/scala/org/apache/comet/parquet/ParquetReadSuite.scala`. It 
writes one file per encoding (`INT96` and `TIMESTAMP_MICROS`), then for 
`string` and `decimal(20,0)` asserts with `checkSparkAnswerMaybeThrows` that 
Spark and Comet both fail, with row-filter pushdown on and off, and asserts a 
plain `timestamp` read of the same file succeeds through a native operator via 
`checkSparkAnswerAndOperator`.
   
   I could not run the Spark suite in this environment because it has no JDK, 
so those cases are added but not executed locally; the Rust side was run with 
`cargo test -p datafusion-comet --lib` and `cargo clippy`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to