viirya commented on code in PR #5457:
URL: https://github.com/apache/datafusion-comet/pull/5457#discussion_r4655162119


##########
spark/src/main/scala/org/apache/comet/expressions/CometCast.scala:
##########
@@ -338,6 +340,11 @@ object CometCast
               isSupported(from_map.keyType, to_map.keyType, timeZoneId, 
evalMode),
               isSupported(from_map.valueType, to_map.valueType, timeZoneId, 
evalMode)))
         }
+      case (DataTypes.DateType, DataTypes.TimestampType)
+          if !CometTimeZone.hasNativeFixedOffset(timeZoneId) =>

Review Comment:
   `TIMESTAMP_NTZ` to `TIMESTAMP` does the same local-to-instant conversion 
through chrono-tz and stays `Compatible`. `date_trunc` handles the same horizon 
with `Incompatible` plus dispatch, so users can opt back into native. This case 
gets neither.
   
   The horizon is also narrower than it looks. In chrono-tz 0.10.4 the last LA 
transition is 2099-11-01 and the last Sydney one is 2099-10-03. So a sentinel 
like `9999-12-31` already matches Java in both hemispheres. What actually 
diverges is post-2099 dates in the other half of the year, plus years past 
262142. Meanwhile every region-zone session pays the dispatch cost, including 
the implicit casts in date/timestamp comparisons.
   
   Could the native path stay, using the last span's offset when a date is 
beyond chrono's range? The horizon could then be left to #6335 together with 
the sibling casts. If you'd rather keep dispatch, could you measure it on this 
head and add an opt-out?



##########
native/spark-expr/src/conversion_funcs/cast.rs:
##########
@@ -462,14 +476,31 @@ pub(crate) fn cast_array(
                 list_array.nulls().cloned(),
             )) as ArrayRef)
         }
-        (Map(_, _), Map(_, _)) => Ok(cast_map_to_map(&array, &from_type, 
to_type, cast_options)?),
+        (Map(_, _), Map(_, _)) => Ok(cast_map_to_map(
+            &array,
+            &from_type,
+            to_type,
+            cast_options,
+            &children,
+        )?),
         (UInt8 | UInt16 | UInt32 | UInt64, Int8 | Int16 | Int32 | Int64)
             if cast_options.allow_cast_unsigned_ints =>
         {
             Ok(cast_with_options(&array, to_type, &CAST_OPTIONS)?)
         }
         (Binary, Utf8) => Ok(cast_binary_to_string::<i32>(&array, 
cast_options)?),
-        (Date32, Timestamp(_, tz)) => Ok(cast_date_to_timestamp(&array, 
cast_options, tz)?),
+        (Date32, Timestamp(_, tz)) => {

Review Comment:
   Only `Date32` leaves read the parent visibility. Under ANSI, `CAST(IF(flag, 
named_struct('a', s), NULL) AS STRUCT<a: INT>)` still evaluates a malformed 
hidden `s` and throws, where Spark returns NULL. Could leaves that can fail in 
the current eval mode use the same mask? If that's out of scope, could you open 
an issue for it?



##########
native/core/src/parquet/parquet_support.rs:
##########
@@ -302,20 +307,42 @@ fn parquet_convert_array_impl(
             //
             // Filtered scans retain safe conversion until DataFusion can 
mirror Spark's
             // pruning paths, including nested predicates.
-            let millis = array.as_primitive::<TimestampMillisecondType>();
-            // Ignore values hidden by null ancestors or by sliced list/map 
offsets.
-            // Restore the original child validity: required fields must 
remain non-null.
-            let micros = arrow::array::TimestampMillisecondArray::new(
-                millis.values().clone(), visible)
-                .try_unary::<_, TimestampMicrosecondType, _>(|value| {
-                    value.checked_mul(1_000).ok_or_else(|| 
SparkError::ParquetTimestampOverflow {
-                        file_path: String::new(),
-                    })
-                })?;
-            let micros = arrow::array::TimestampMicrosecondArray::new(
-                micros.values().clone(), millis.nulls().cloned())
-                .with_timezone_opt(target_tz.clone());
-            Ok(Arc::new(micros))
+            checked_micros(
+                array.as_primitive::<TimestampMillisecondType>(),
+                parent_nulls.as_ref(),
+                1_000,
+                target_tz.clone(),
+            )
+        }
+        (Date32, Timestamp(TimeUnit::Microsecond, None)) => {
+            // Spark 4.x's DateToTimestampNTZUpdater calls daysToMicros at UTC.
+            checked_micros(
+                array.as_primitive::<Date32Type>(),
+                parent_nulls.as_ref(),
+                86_400_000_000,
+                None,
+            )
+        }
+        (Date64, Timestamp(TimeUnit::Microsecond, None)) => {

Review Comment:
   `main` never handled a Date64 hint read as NTZ. This arm, together with the 
INT64 check it needs in `eager_page_index_reader_factory.rs`, covers a separate 
case. Could it move to its own PR? Or could `with_spark_arrow_schema`'s 
physical inference cover it, and if not, what rules that out?



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