@@ -1728,7 +1728,7 @@ physical_plan
1728172802)--SortExec: TopK(fetch=2), expr=[column1@0 ASC NULLS LAST], preserve_partitioning=[false]
1729172903)----DataSourceExec: partitions=1, partition_sizes=[1]
17301730
1731- # Typed bounds allow date_trunc to propagate ordering through timezone-free date_bin
1731+ # date_bin remains conservatively unordered because per-row failures become NULL
17321732query TT
17331733EXPLAIN SELECT date_trunc('hour', date_bin(INTERVAL '1 minute', ts)) AS truncated
17341734FROM (
@@ -1750,10 +1750,31 @@ logical_plan
1750175004)------Projection: CAST(column1 AS Timestamp(s)) AS ts
1751175105)--------Values: (Int64(7200)), (Int64(3600))
17521752physical_plan
1753- 01)ProjectionExec: expr=[date_trunc(hour, date_bin(IntervalMonthDayNano { months: 0, days: 0, nanoseconds: 60000000000 }, ts@0)) as truncated]
1754- 02)--SortExec: TopK(fetch=2), expr=[ts@0 ASC NULLS LAST], preserve_partitioning=[false]
1755- 03)----ProjectionExec: expr=[CAST(column1@0 AS Timestamp(s)) as ts]
1756- 04)------DataSourceExec: partitions=1, partition_sizes=[1]
1753+ 01)SortExec: expr=[truncated@0 ASC NULLS LAST], preserve_partitioning=[false]
1754+ 02)--ProjectionExec: expr=[date_trunc(hour, date_bin(IntervalMonthDayNano { months: 0, days: 0, nanoseconds: 60000000000 }, ts@0)) as truncated]
1755+ 03)----SortExec: TopK(fetch=2), expr=[ts@0 ASC NULLS LAST], preserve_partitioning=[false]
1756+ 04)------ProjectionExec: expr=[CAST(column1@0 AS Timestamp(s)) as ts]
1757+ 05)--------DataSourceExec: partitions=1, partition_sizes=[1]
1758+
1759+ # date_bin can return NULL for out-of-range values, so its output does not
1760+ # necessarily preserve the source's NULL ordering.
1761+ query P
1762+ SELECT date_trunc('second', date_bin(INTERVAL '1 second', ts)) AS b
1763+ FROM (
1764+ SELECT arrow_cast(column1, 'Timestamp(Second)') AS ts
1765+ FROM (VALUES
1766+ (-10000000000::bigint),
1767+ (0::bigint),
1768+ (10000000000::bigint)
1769+ )
1770+ ORDER BY ts
1771+ LIMIT 3
1772+ )
1773+ ORDER BY b ASC NULLS LAST
1774+ ----
1775+ 1970-01-01T00:00:00
1776+ NULL
1777+ NULL
17571778
17581779statement ok
17591780CREATE TABLE timestamp_strings(ts varchar)
0 commit comments