alamb commented on code in PR #25409:
URL: https://github.com/apache/datafusion/pull/25409#discussion_r4050479720


##########
datafusion/sqllogictest/test_files/datetime/timestamps.slt:
##########
@@ -1655,7 +1655,53 @@ SELECT DATE_TRUNC('day', arrow_cast(TIMESTAMP 
'2023-08-03 14:38:50Z', 'Timestamp
 2023-08-03T14:38:50
 2023-08-03T14:38:50
 
-# date_trunc with data with timezones
+# date_trunc must not propagate ordering across named timezone transitions
+query II
+SELECT
+  arrow_cast(ts, 'Int64') AS input_epoch,
+  arrow_cast(date_trunc('hour', ts), 'Int64') AS truncated
+FROM (
+  SELECT
+    arrow_cast(
+      column1,
+      'Timestamp(Second, Some("America/Goose_Bay"))'
+    ) AS ts
+  FROM (
+    VALUES
+      (562129260::bigint),
+      (562129259::bigint)
+  )
+  ORDER BY ts
+  LIMIT 2
+)
+ORDER BY date_trunc('hour', ts);
+----
+562129260 562125600
+562129259 562129200
+
+# An unknown range from a child function may hide a timezone-aware timestamp
+query II
+SELECT
+  c,
+  arrow_cast(
+    date_trunc('hour', from_unixtime(c, 'America/Goose_Bay')),
+    'Int64'
+  ) AS truncated
+FROM (
+  SELECT column1 AS c
+  FROM (
+    VALUES
+      (562129260::bigint),
+      (562129259::bigint)
+  )
+  ORDER BY c
+  LIMIT 2
+)
+ORDER BY date_trunc('hour', from_unixtime(c, 'America/Goose_Bay'));
+----
+562129260 562125600

Review Comment:
   🙏 



##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -431,11 +431,15 @@ impl ScalarUDFImpl for DateTruncFunc {
     }
 
     fn output_ordering(&self, input: &[ExprProperties]) -> 
Result<SortProperties> {
-        // The DATE_TRUNC function preserves the order of its second argument.
         let precision = &input[0];
         let date_value = &input[1];
 
-        if precision.sort_properties.eq(&SortProperties::Singleton) {
+        let order_safe_input = matches!(

Review Comment:
   it is a bummer we have to turn it off but I agree it is needed for correctess



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