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(datatype): datatype timestamp with precision #4997

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion common/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ common-functions = { path = "../functions" }
# TODO (andylokandy): Use the version from crates.io once
# https://github.com/brendanzab/codespan/pull/331 is released.
codespan-reporting = { git = "https://github.com/brendanzab/codespan", rev = "c84116f5" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fee0056" }

# Crates.io dependencies
async-trait = "0.1.53"
Expand Down
2 changes: 1 addition & 1 deletion common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ tonic = "=0.6.2"

# Github dependencies
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fee0056" }
2 changes: 1 addition & 1 deletion common/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde_json = "1.0.79"
sha1 = "0.10.1"
sha2 = "0.10.2"
simdutf8 = "0.1.4"
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fee0056" }
strength_reduce = "0.2.3"
twox-hash = "1.6.2"
uuid = { version = "0.8.2", features = ["v4"] }
Expand Down
2 changes: 1 addition & 1 deletion query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ common-tracing = { path = "../common/tracing" }
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
opensrv-clickhouse = { git = "https://github.com/datafuselabs/opensrv", rev = "9690be9", package = "opensrv-clickhouse" }
opensrv-mysql = { git = "https://github.com/datafuselabs/opensrv", rev = "967477f1", package = "opensrv-mysql" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "fee0056" }

# Crates.io dependencies
ahash = "0.7.6"
Expand Down
17 changes: 15 additions & 2 deletions query/src/sql/sql_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,26 @@ impl SQLCommon {
SQLDataType::Real | SQLDataType::Double => Ok(f64::to_data_type()),
SQLDataType::Boolean => Ok(bool::to_data_type()),
SQLDataType::Date => Ok(DateType::arc()),
SQLDataType::Timestamp | SQLDataType::DateTime(None) => Ok(DateTimeType::arc(0, None)),
// default precision is 6, microseconds
SQLDataType::Timestamp(None) | SQLDataType::DateTime(None) => {
Ok(DateTimeType::arc(6, None))
}
SQLDataType::Timestamp(Some(precision)) => {
if *precision <= 9 {
Ok(DateTimeType::arc(*precision as usize, None))
} else {
Err(ErrorCode::IllegalDataType(format!(
"The SQL data type TIMESTAMP(n), n only ranges from 0~9, {} is invalid",
precision
)))
}
}
SQLDataType::DateTime(Some(precision)) => {
if *precision <= 9 {
Ok(DateTimeType::arc(*precision as usize, None))
} else {
Err(ErrorCode::IllegalDataType(format!(
"The SQL data type DateTime(n), n only ranges from 0~9, {} is invalid",
"The SQL data type DATETIME(n), n only ranges from 0~9, {} is invalid",
precision
)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SELECT parse_json('"test"')::float32; -- {ErrorCode 1010}
SELECT parse_json('"test"')::float64; -- {ErrorCode 1010}
SELECT parse_json('null')::float64; -- {ErrorCode 1010}
SELECT parse_json('"2022-01-01"')::date;
SELECT parse_json('"2022-01-01 01:01:01"')::datetime;
SELECT parse_json('"2022-01-01 01:01:01"')::datetime(0);
SELECT parse_json('"test"')::date; -- {ErrorCode 1010}
SELECT parse_json('"test"')::datetime; -- {ErrorCode 1010}
SELECT parse_json('null')::datetime; -- {ErrorCode 1010}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
drop table if exists funnel_test;

create table funnel_test (timestamp UInt32, d Date, dt DateTime, event UInt32) engine=Memory;
create table funnel_test (timestamp UInt32, d Date, dt DateTime(0), event UInt32) engine=Memory;
insert into funnel_test values
(0, '2021-01-01', '2021-01-01 00:00:00', 1000),
(1, '2021-01-02', '2021-01-01 00:00:01', 1001),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@
1
===INSERT===
1
2022-04-02 15:10:28 2022-04-02 15:10:28.000
2022-04-02 15:10:28 2022-04-02 15:10:28.221
2022-04-02 15:10:28.000000 2022-04-02 15:10:28.000
2022-04-02 15:10:28.221000 2022-04-02 15:10:28.221
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ NULL 2 3
==GROUP BY DATETIMES==
2022-04-01 5
2022-04-02 5
2022-04-01 00:00:00 5
2022-04-01 00:00:01 5
2022-04-01 00:00:00.000000 5
2022-04-01 00:00:01.000000 5
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 2 3 4 2021-08-15 2021-09-15 2021-08-15 10:00:00 string1234
5 6 7 8 2021-10-15 2021-11-15 2021-11-15 10:00:00 string5678
1 2 3 4 2021-08-15 2021-09-15 2021-08-15 10:00:00.000000 string1234
5 6 7 8 2021-10-15 2021-11-15 2021-11-15 10:00:00.000000 string5678
5
7
9
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-1 33 2021-08-15 10:00:00 string1234
101 67 2021-11-15 10:00:00 string5678
-1 33 2021-08-15 10:00:00.000000 string1234
101 67 2021-11-15 10:00:00.000000 string5678
100 100
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ bigint_unsigned BIGINT UNSIGNED NO 0
float FLOAT NO 0
double DOUBLE NO 0
date DATE NO 0
datetime DATETIME NO 0
ts DATETIME NO 0
datetime DATETIME(6) NO 0
ts DATETIME(6) NO 0
str VARCHAR NO 3
bool BOOLEAN NO false
array ARRAY NO []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
2 2 "2"-"2"
3
3
1 2021-09-07 21:38:35 2021-09-07
0 2021-09-07 21:38:35 2021-09-07
1 2021-09-07 21:38:35.000000 2021-09-07
0 2021-09-07 21:38:35.000000 2021-09-07
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SELECT * FROM t1;
SELECT sum(a) from t1;
SELECT sum(b) from t1;

CREATE TABLE IF NOT EXISTS t2(a Boolean, b Datetime, c Date) Engine = fuse;
INSERT INTO t2 (a,b,c) values(true, '2021-09-07 21:38:35', '2021-09-07'), (false, 1631050715, 18877);
CREATE TABLE IF NOT EXISTS t2(a Boolean, b TimeStamp, c Date) Engine = fuse;
INSERT INTO t2 (a,b,c) values(true, '2021-09-07 21:38:35.000000', '2021-09-07'), (false, 1631050715000000, 18877);
SELECT * FROM t2;

DROP TABLE t1;
Expand Down