Skip to content

Commit f8a68b7

Browse files
xxhZswcy-fdu
authored and
lmatz
committed
feat(types): support ns timestamp (#19827)
Co-authored-by: congyi wang <[email protected]>
1 parent 074c1f8 commit f8a68b7

File tree

10 files changed

+349
-86
lines changed

10 files changed

+349
-86
lines changed

Cargo.lock

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
statement ok
2+
SET RW_IMPLICIT_FLUSH TO true;
3+
4+
statement ok
5+
create table t1(v1 int, v2 timestamp);
6+
7+
statement ok
8+
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');
9+
10+
query T rowsort
11+
select * from t1;
12+
----
13+
1 2013-01-01 01:01:01.123456789
14+
2 2012-01-01 01:01:01.123456
15+
3 0001-01-01 01:01:01.123456789 BC
16+
4 2213-01-01 01:01:01.123456789
17+
5 NULL
18+
6 2013-01-01 01:01:01.123456789
19+
20+
query T
21+
select * from t1 where v2 is null;
22+
----
23+
5 NULL
24+
25+
query T rowsort
26+
select v1, v2,
27+
case
28+
when extract(year from v2) < 2000 then 'Before 2000'
29+
when extract(year from v2) >= 2000 and extract(year from v2) < 2100 then '21st Century'
30+
else 'Future'
31+
end as time_period
32+
from t1;
33+
----
34+
1 2013-01-01 01:01:01.123456789 21st Century
35+
2 2012-01-01 01:01:01.123456 21st Century
36+
3 0001-01-01 01:01:01.123456789 BC Before 2000
37+
4 2213-01-01 01:01:01.123456789 Future
38+
5 NULL Future
39+
6 2013-01-01 01:01:01.123456789 21st Century
40+
41+
query T rowsort
42+
select v1, v2, coalesce(v2, '1900-01-01 00:00:00') as coalesce_v2 from t1;
43+
----
44+
1 2013-01-01 01:01:01.123456789 2013-01-01 01:01:01.123456789
45+
2 2012-01-01 01:01:01.123456 2012-01-01 01:01:01.123456
46+
3 0001-01-01 01:01:01.123456789 BC 0001-01-01 01:01:01.123456789 BC
47+
4 2213-01-01 01:01:01.123456789 2213-01-01 01:01:01.123456789
48+
5 NULL 1900-01-01 00:00:00
49+
6 2013-01-01 01:01:01.123456789 2013-01-01 01:01:01.123456789
50+
51+
query T
52+
select count(v2) as total_rows from t1;
53+
----
54+
5
55+
56+
query T rowsort
57+
select * from t1 where v2 >= '2012-01-01 01:01:01.123456';
58+
----
59+
1 2013-01-01 01:01:01.123456789
60+
2 2012-01-01 01:01:01.123456
61+
4 2213-01-01 01:01:01.123456789
62+
6 2013-01-01 01:01:01.123456789
63+
64+
query T rowsort
65+
select v1, cast(v2 as date) as date_v2, cast(v2 as timestamp with time zone) as timestamptz_v2 from t1;
66+
----
67+
1 2013-01-01 2013-01-01 01:01:01.123456+00:00
68+
2 2012-01-01 2012-01-01 01:01:01.123456+00:00
69+
3 0001-01-01 BC 0001-01-01 01:01:01.123456+00:00 BC
70+
4 2213-01-01 2213-01-01 01:01:01.123456+00:00
71+
5 NULL NULL
72+
6 2013-01-01 2013-01-01 01:01:01.123456+00:00
73+
74+
query T rowsort
75+
select v1, date_trunc('day', v2) AS truncated_v2 from t1;
76+
----
77+
1 2013-01-01 00:00:00
78+
2 2012-01-01 00:00:00
79+
3 0001-01-01 00:00:00 BC
80+
4 2213-01-01 00:00:00
81+
5 NULL
82+
6 2013-01-01 00:00:00
83+
84+
query T rowsort
85+
select v1, v2 at time zone 'UTC' as v2_utc from t1;
86+
----
87+
1 2013-01-01 01:01:01.123456+00:00
88+
2 2012-01-01 01:01:01.123456+00:00
89+
3 0001-01-01 01:01:01.123456+00:00 BC
90+
4 2213-01-01 01:01:01.123456+00:00
91+
5 NULL
92+
6 2013-01-01 01:01:01.123456+00:00
93+
94+
query T rowsort
95+
select v1, to_char(v2, 'YYYY-MM-DD HH24:MI:SS.NS') as formatted_v2 from t1;
96+
----
97+
1 2013-01-01 01:01:01.123456789
98+
2 2012-01-01 01:01:01.123456000
99+
3 0000-01-01 01:01:01.123456789
100+
4 2213-01-01 01:01:01.123456789
101+
5 NULL
102+
6 2013-01-01 01:01:01.123456789
103+
104+
query T rowsort
105+
select generate_series('2013-01-01 01:01:01.123456789'::timestamp,'2013-01-01 01:01:05.123456790'::timestamp, '1 s');
106+
----
107+
2013-01-01 01:01:01.123456789
108+
2013-01-01 01:01:02.123456789
109+
2013-01-01 01:01:03.123456789
110+
2013-01-01 01:01:04.123456789
111+
2013-01-01 01:01:05.123456789
112+
113+
query T rowsort
114+
select DISTINCT v2 FROM t1;
115+
----
116+
0001-01-01 01:01:01.123456789 BC
117+
2012-01-01 01:01:01.123456
118+
2013-01-01 01:01:01.123456789
119+
2213-01-01 01:01:01.123456789
120+
NULL
121+
122+
query T rowsort
123+
select v2, count(*) from t1 group by v2;
124+
----
125+
0001-01-01 01:01:01.123456789 BC 1
126+
2012-01-01 01:01:01.123456 1
127+
2013-01-01 01:01:01.123456789 2
128+
2213-01-01 01:01:01.123456789 1
129+
NULL 1
130+
131+
query T
132+
select * from t1 order by v2 desc , v1 desc;
133+
----
134+
5 NULL
135+
4 2213-01-01 01:01:01.123456789
136+
6 2013-01-01 01:01:01.123456789
137+
1 2013-01-01 01:01:01.123456789
138+
2 2012-01-01 01:01:01.123456
139+
3 0001-01-01 01:01:01.123456789 BC
140+
141+
query T rowsort
142+
select max(v2) from t1;
143+
----
144+
2213-01-01 01:01:01.123456789
145+
146+
query T rowsort
147+
select v1, extract(epoch from v2) from t1;
148+
----
149+
1 1357002061.123456789
150+
2 1325379661.123456000
151+
3 -62167215538.876544
152+
4 7668349261.123456789
153+
5 NULL
154+
6 1357002061.123456789
155+
156+
query T rowsort
157+
select v1, extract(second from v2) from t1;
158+
----
159+
1 1.123456789
160+
2 1.123456000
161+
3 1.123456789
162+
4 1.123456789
163+
5 NULL
164+
6 1.123456789
165+
166+
query T rowsort
167+
select v1, extract(millisecond from v2) from t1;
168+
----
169+
1 1123.456789
170+
2 1123.456000
171+
3 1123.456789
172+
4 1123.456789
173+
5 NULL
174+
6 1123.456789
175+
176+
query T rowsort
177+
select v1, extract(microsecond from v2) from t1;
178+
----
179+
1 1123456.789
180+
2 1123456.000
181+
3 1123456.789
182+
4 1123456.789
183+
5 NULL
184+
6 1123456.789
185+
186+
query T rowsort
187+
select v1, extract(nanosecond from v2) from t1;
188+
----
189+
1 1123456789
190+
2 1123456000
191+
3 1123456789
192+
4 1123456789
193+
5 NULL
194+
6 1123456789
195+
196+
query T rowsort
197+
select make_timestamp(2013, 01, 01, 01, 01, 1.123456789);
198+
----
199+
2013-01-01 01:01:01.123456789
200+
201+
statement ok
202+
drop table t1;

src/common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ humantime = "2.1"
5656
hytra = { workspace = true }
5757
itertools = { workspace = true }
5858
itoa = "1.0"
59+
jiff = "0.1.15"
5960
jsonbb = { workspace = true }
6061
lru = { workspace = true }
6162
memcomparable = { version = "0.2", features = ["decimal"] }

0 commit comments

Comments
 (0)