Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): support ns timestamp #19827

Merged
merged 16 commits into from
Dec 30, 2024
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

212 changes: 212 additions & 0 deletions e2e_test/batch/types/timestamp_ns.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
create table t1(v1 int, v2 timestamp);

statement ok
insert into t1 values(1,'2013-01-01 01:01:01.123456789'),(2,'2012-01-01 01:01:01.123456'),(3,'0000-01-01 01:01:01.123456789'),(4,'2213-01-01 01:01:01.123456789'),(5,null),(6,'2013-01-01 01:01:01.123456789');

query T rowsort
select * from t1;
----
1 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456
3 0001-01-01 01:01:01.123456789 BC
4 2213-01-01 01:01:01.123456789
5 NULL
6 2013-01-01 01:01:01.123456789

query T
select * from t1 where v2 is null;
----
5 NULL

query T rowsort
select v1, v2,
case
when extract(year from v2) < 2000 then 'Before 2000'
when extract(year from v2) >= 2000 and extract(year from v2) < 2100 then '21st Century'
else 'Future'
end as time_period
from t1;
----
1 2013-01-01 01:01:01.123456789 21st Century
2 2012-01-01 01:01:01.123456 21st Century
3 0001-01-01 01:01:01.123456789 BC Before 2000
4 2213-01-01 01:01:01.123456789 Future
5 NULL Future
6 2013-01-01 01:01:01.123456789 21st Century

query T rowsort
select v1, v2, coalesce(v2, '1900-01-01 00:00:00') as coalesce_v2 from t1;
----
1 2013-01-01 01:01:01.123456789 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456 2012-01-01 01:01:01.123456
3 0001-01-01 01:01:01.123456789 BC 0001-01-01 01:01:01.123456789 BC
4 2213-01-01 01:01:01.123456789 2213-01-01 01:01:01.123456789
5 NULL 1900-01-01 00:00:00
6 2013-01-01 01:01:01.123456789 2013-01-01 01:01:01.123456789

query T
select count(v2) as total_rows from t1;
----
4

query T rowsort
select * from t1 order by v2;
----
1 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456
3 0001-01-01 01:01:01.123456789 BC
4 2213-01-01 01:01:01.123456789
5 NULL
6 2013-01-01 01:01:01.123456789

query T rowsort
select * from t1 where v2 >= '2012-01-01 01:01:01.123456';
----
1 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456
4 2213-01-01 01:01:01.123456789
6 2013-01-01 01:01:01.123456789

query T rowsort
select v1, cast(v2 as date) as date_v2, cast(v2 as timestamp with time zone) as timestamptz_v2 from t1;
----
1 2013-01-01 2013-01-01 01:01:01.123456+00:00
2 2012-01-01 2012-01-01 01:01:01.123456+00:00
3 0001-01-01 BC 0001-01-01 01:01:01.123456+00:00 BC
4 2213-01-01 2213-01-01 01:01:01.123456+00:00
5 NULL NULL
6 2013-01-01 2013-01-01 01:01:01.123456+00:00

query T rowsort
select v1, date_trunc('day', v2) AS truncated_v2 from t1;
----
1 2013-01-01 00:00:00
2 2012-01-01 00:00:00
3 0001-01-01 00:00:00 BC
4 2213-01-01 00:00:00
5 NULL
6 2013-01-01 00:00:00

query T rowsort
select v1, v2 at time zone 'UTC' as v2_utc from t1;
----
1 2013-01-01 01:01:01.123456+00:00
2 2012-01-01 01:01:01.123456+00:00
3 0001-01-01 01:01:01.123456+00:00 BC
4 2213-01-01 01:01:01.123456+00:00
5 NULL
6 2013-01-01 01:01:01.123456+00:00

query T rowsort
select v1, to_char(v2, 'YYYY-MM-DD HH24:MI:SS.NS') as formatted_v2 from t1;
----
1 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456000
3 0000-01-01 01:01:01.123456789
4 2213-01-01 01:01:01.123456789
5 NULL
6 2013-01-01 01:01:01.123456789

query T rowsort
select generate_series('2013-01-01 01:01:01.123456789'::timestamp,'2013-01-01 01:01:05.123456790'::timestamp, '1 s');
----
2013-01-01 01:01:01.123456789
2013-01-01 01:01:02.123456789
2013-01-01 01:01:03.123456789
2013-01-01 01:01:04.123456789
2013-01-01 01:01:05.123456789

query T rowsort
select DISTINCT v2 FROM t1;
----
0001-01-01 01:01:01.123456789 BC
2012-01-01 01:01:01.123456
2013-01-01 01:01:01.123456789
2213-01-01 01:01:01.123456789
NULL

query T rowsort
select v2, count(*) from t1 group by v2;
----
0001-01-01 01:01:01.123456789 BC 1
2012-01-01 01:01:01.123456 1
2013-01-01 01:01:01.123456789 2
2213-01-01 01:01:01.123456789 1
null 1

query T rowsort
select * from t1 order by v2 desc;
----
5 NULL
4 2213-01-01 01:01:01.123456789
6 2013-01-01 01:01:01.123456789
1 2013-01-01 01:01:01.123456789
2 2012-01-01 01:01:01.123456
3 0001-01-01 01:01:01.123456789 BC

query T rowsort
select max(v2) from t1;
----
2213-01-01 01:01:01.123456789

query T rowsort
select v1, extract(epoch from v2) from t1;
----
1 1357002061.123456789
2 1325379661.123456000
3 -62167215538.876544
4 7668349261.123456789
5 NULL
6 1357002061.123456789

query T rowsort
select v1, extract(second from v2) from t1;
----
1 1.123456789
2 1.123456000
3 1.123456789
4 1.123456789
5 NULL
6 1.123456789

query T rowsort
select v1, extract(millisecond from v2) from t1;
----
1 1123.456789
2 1123.456000
3 1123.456789
4 1123.456789
5 NULL
6 1123.456789

query T rowsort
select v1, extract(microsecond from v2) from t1;
----
1 1123456.789
2 1123456.000
3 1123456.789
4 1123456.789
5 NULL
6 1123456.789

query T rowsort
select v1, extract(nanosecond from v2) from t1;
----
1 1123456789
2 1123456000
3 1123456789
4 1123456789
5 NULL
6 1123456789

query T rowsort
select make_timestamp(2013, 01, 01, 01, 01, 1.123456789);
----
2013-01-01 01:01:01.123456789

statement ok
drop table t1;
1 change: 1 addition & 0 deletions src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ humantime = "2.1"
hytra = { workspace = true }
itertools = { workspace = true }
itoa = "1.0"
jiff = "0.1.15"
jsonbb = { workspace = true }
lru = { workspace = true }
memcomparable = { version = "0.2", features = ["decimal"] }
Expand Down
Loading
Loading