-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Xinhao Xu <[email protected]> Co-authored-by: congyi wang <[email protected]>
- Loading branch information
1 parent
c8819a9
commit 34d0c23
Showing
10 changed files
with
349 additions
and
86 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
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; | ||
---- | ||
5 | ||
|
||
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 | ||
select * from t1 order by v2 desc , v1 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.