harsh-ande commented on code in PR #26129:
URL: https://github.com/apache/datafusion/pull/26129#discussion_r4366459736
##########
datafusion/sqllogictest/test_files/spark/datetime/unix.slt:
##########
@@ -132,3 +132,51 @@ NULL
query error Function 'unix_seconds' requires Timestamp, but received String
\(DataType: Utf8View\)
SELECT unix_seconds('1970-01-01 00:00:01Z'::string);
+
+# Spark floors (Math.floorDiv) when converting to a coarser unit, so pre-epoch
+# timestamps with a sub-unit remainder round toward negative infinity.
+statement ok
+CREATE TABLE unix_floor_us AS SELECT arrow_cast(column1,
'Timestamp(Microsecond, None)') AS ts FROM (VALUES
+ (-1), (-1000), (-1001), (-1000000), (-1000001), (1500), (NULL)
+);
+
+query III
+SELECT arrow_cast(ts, 'Int64'), unix_millis(ts), unix_seconds(ts) FROM
unix_floor_us;
+----
+-1 -1 -1
+-1000 -1 -1
+-1001 -2 -1
+-1000000 -1000 -1
+-1000001 -1001 -2
+1500 1 0
+NULL NULL NULL
+
+statement ok
+DROP TABLE unix_floor_us;
+
+# Same results when the expressions are constant-folded
+query II
+SELECT
+ unix_millis(arrow_cast(-1001, 'Timestamp(Microsecond, None)')),
+ unix_seconds(arrow_cast(-1000001, 'Timestamp(Microsecond, None)'));
+----
+-2 -2
+
+# Other input units: nanoseconds floor too, milliseconds to seconds floors,
+# and conversions to a finer unit are unchanged
+query IIII
+SELECT
+ unix_millis(arrow_cast(-1, 'Timestamp(Nanosecond, None)')),
Review Comment:
Added both cases: `-1000000001` nanoseconds returns `-2` seconds, and the
exact multiple `-1000000000` returns `-1`.
--
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]