Skip to content

Commit 7ee9f9b

Browse files
committed
minors
1 parent 4806bde commit 7ee9f9b

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

datafusion/sql/src/expr/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
230230
let expr =
231231
self.sql_expr_to_logical_expr(*expr, schema, planner_context)?;
232232

233-
// int/floats input should be treated as seconds rather as nanoseconds
233+
// numeric constants are treated as seconds (rather as nanoseconds)
234+
// to align with postgres / duckdb semantics
234235
let expr = match &dt {
235236
DataType::Timestamp(TimeUnit::Nanosecond, tz)
236237
if expr.get_type(schema)? == DataType::Int64 =>

datafusion/sql/tests/sql_integration.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,14 +597,18 @@ fn select_neg_filter() {
597597
fn select_compound_filter() {
598598
let sql = "SELECT id, first_name, last_name \
599599
FROM person WHERE state = 'CO' AND age >= 21 AND age <= 65";
600-
let expected = "Projection: person.id, person.first_name, person.last_name\n Filter: person.state = Utf8(\"CO\") AND person.age >= Int64(21) AND person.age <= Int64(65)\n TableScan: person";
600+
let expected = "Projection: person.id, person.first_name, person.last_name\
601+
\n Filter: person.state = Utf8(\"CO\") AND person.age >= Int64(21) AND person.age <= Int64(65)\
602+
\n TableScan: person";
601603
quick_test(sql, expected);
602604
}
603605

604606
#[test]
605607
fn test_timestamp_filter() {
606608
let sql = "SELECT state FROM person WHERE birth_date < CAST (158412331400600000 as timestamp)";
607-
let expected = "Projection: person.state\n Filter: person.birth_date < CAST(CAST(Int64(158412331400600000) AS Timestamp(Second, None)) AS Timestamp(Nanosecond, None))\n TableScan: person";
609+
let expected = "Projection: person.state\
610+
\n Filter: person.birth_date < CAST(CAST(Int64(158412331400600000) AS Timestamp(Second, None)) AS Timestamp(Nanosecond, None))\
611+
\n TableScan: person";
608612
quick_test(sql, expected);
609613
}
610614

datafusion/sqllogictest/test_files/timestamps.slt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,17 +1794,23 @@ SELECT to_timestamp(null), to_timestamp(0), to_timestamp(1926632005), to_timesta
17941794
----
17951795
NULL 1970-01-01T00:00:00 2031-01-19T23:33:25 1970-01-01T00:00:01 1969-12-31T23:59:59 1969-12-31T23:59:59
17961796

1797-
# verify timestamp cast with integer input timestamp literal syntax
1798-
query PPPPPP
1799-
SELECT null::timestamp, 0::timestamp, 1926632005::timestamp, 1::timestamp, -1::timestamp, (0-1)::timestamp
1800-
----
1801-
NULL 1970-01-01T00:00:00 2031-01-19T23:33:25 1970-01-01T00:00:01 1969-12-31T23:59:59 1969-12-31T23:59:59
1802-
1803-
# verify timestamp cast with integer input timestamp literal syntax using CAST syntax
1804-
query PPPPPP
1805-
SELECT cast(null as timestamp), cast(0 as timestamp), cast(1926632005 as timestamp), cast(1 as timestamp), cast(-1 as timestamp), cast(0-1 as timestamp)
1806-
----
1807-
NULL 1970-01-01T00:00:00 2031-01-19T23:33:25 1970-01-01T00:00:01 1969-12-31T23:59:59 1969-12-31T23:59:59
1797+
# verify timestamp syntax stlyes are consistent
1798+
query BBBBBBBBBBBBB
1799+
SELECT to_timestamp(null) is null as c1,
1800+
null::timestamp is null as c2,
1801+
cast(null as timestamp) is null as c3,
1802+
to_timestamp(0) = 0::timestamp as c4,
1803+
to_timestamp(1926632005) = 1926632005::timestamp as c5,
1804+
to_timestamp(1) = 1::timestamp as c6,
1805+
to_timestamp(-1) = -1::timestamp as c7,
1806+
to_timestamp(0-1) = (0-1)::timestamp as c8,
1807+
to_timestamp(0) = cast(0 as timestamp) as c9,
1808+
to_timestamp(1926632005) = cast(1926632005 as timestamp) as c10,
1809+
to_timestamp(1) = cast(1 as timestamp) as c11,
1810+
to_timestamp(-1) = cast(-1 as timestamp) as c12,
1811+
to_timestamp(0-1) = cast(0-1 as timestamp) as c13
1812+
----
1813+
true true true true true true true true true true true true true
18081814

18091815
# verify timestamp output types
18101816
query TTT
@@ -1813,17 +1819,15 @@ SELECT arrow_typeof(to_timestamp(1)), arrow_typeof(to_timestamp(null)), arrow_ty
18131819
Timestamp(Nanosecond, None) Timestamp(Nanosecond, None) Timestamp(Nanosecond, None)
18141820

18151821
# verify timestamp output types using timestamp literal syntax
1816-
query TTT
1817-
SELECT arrow_typeof(1::timestamp), arrow_typeof(null::timestamp), arrow_typeof('2023-01-10 12:34:56.000'::timestamp)
1818-
----
1819-
Timestamp(Nanosecond, None) Timestamp(Nanosecond, None) Timestamp(Nanosecond, None)
1820-
1821-
# verify timestamp output types using CAST syntax
1822-
query TTT
1823-
SELECT arrow_typeof(cast(1 as timestamp)), arrow_typeof(cast(null as timestamp)), arrow_typeof(cast('2023-01-10 12:34:56.000' as timestamp))
1824-
----
1825-
Timestamp(Nanosecond, None) Timestamp(Nanosecond, None) Timestamp(Nanosecond, None)
1826-
1822+
query BBBBBB
1823+
SELECT arrow_typeof(to_timestamp(1)) = arrow_typeof(1::timestamp) as c1,
1824+
arrow_typeof(to_timestamp(null)) = arrow_typeof(null::timestamp) as c2,
1825+
arrow_typeof(to_timestamp('2023-01-10 12:34:56.000')) = arrow_typeof('2023-01-10 12:34:56.000'::timestamp) as c3,
1826+
arrow_typeof(to_timestamp(1)) = arrow_typeof(cast(1 as timestamp)) as c4,
1827+
arrow_typeof(to_timestamp(null)) = arrow_typeof(cast(null as timestamp)) as c5,
1828+
arrow_typeof(to_timestamp('2023-01-10 12:34:56.000')) = arrow_typeof(cast('2023-01-10 12:34:56.000' as timestamp)) as c6
1829+
----
1830+
true true true true true true
18271831

18281832
# known issues. currently overflows (expects default precision to be microsecond instead of nanoseconds. Work pending)
18291833
#verify extreme values

0 commit comments

Comments
 (0)