codetyri0n commented on code in PR #18417:
URL: https://github.com/apache/datafusion/pull/18417#discussion_r2511809106


##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -193,12 +201,64 @@ impl ScalarUDFImpl for DatePartFunc {
             ColumnarValue::Scalar(scalar) => scalar.to_array()?,
         };
 
+        let (is_timezone_aware, tz_str_opt) = match array.data_type() {
+            Timestamp(_, Some(tz_str)) => (true, Some(Arc::clone(tz_str))),
+            _ => (false, None),
+        };
+
         let part_trim = part_normalization(&part);
+        let is_epoch = is_epoch(&part);
+
+        // Epoch is timezone-independent - it always returns seconds since 
1970-01-01 UTC
+        let array = if is_epoch {
+            array
+        } else if is_timezone_aware {
+            // For timezone-aware timestamps, extract in their own timezone
+            let tz_str = tz_str_opt.as_ref().unwrap();
+            let tz = match tz_str.parse::<Tz>() {
+                Ok(tz) => tz,
+                Err(_) => return exec_err!("Invalid timezone"),
+            };
+            match array.data_type() {
+                Timestamp(time_unit, _) => match time_unit {
+                    Nanosecond => {
+                        
adjust_timestamp_array::<TimestampNanosecondType>(&array, tz)?
+                    }
+                    Microsecond => {
+                        
adjust_timestamp_array::<TimestampMicrosecondType>(&array, tz)?
+                    }
+                    Millisecond => {
+                        
adjust_timestamp_array::<TimestampMillisecondType>(&array, tz)?
+                    }
+                    Second => 
adjust_timestamp_array::<TimestampSecondType>(&array, tz)?,
+                },
+                _ => array,
+            }
+        } else if let Timestamp(time_unit, None) = array.data_type() {
+            // For naive timestamps, interpret in session timezone
+            let tz: Tz = 
config.execution.time_zone.as_str().parse().map_err(|_| {

Review Comment:
   this is confusing since the commits with extract as a separate function had 
this and it seemed to be alright with the CI : 
   ```
    let tz = match config.execution.time_zone.parse::<Tz>() {
                   Ok(tz) => tz,
                   Err(_) => return exec_err!("Invalid timezone"),
   ```



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