From c2f29cf6d558eff47492b4a7339504adabb2543d Mon Sep 17 00:00:00 2001 From: Veeupup Date: Fri, 22 Apr 2022 11:32:29 +0800 Subject: [PATCH 1/2] feat: datetype timestamp with precision Signed-off-by: Veeupup --- Cargo.lock | 2 +- common/ast/Cargo.toml | 2 +- common/exception/Cargo.toml | 2 +- common/functions/Cargo.toml | 2 +- query/Cargo.toml | 2 +- query/src/sql/sql_common.rs | 15 +++++++++++++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bae15ca38b43..c723991b7a6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5691,7 +5691,7 @@ dependencies = [ [[package]] name = "sqlparser" version = "0.13.1-alpha.0" -source = "git+https://github.com/datafuse-extras/sqlparser-rs?rev=49f4ec2#49f4ec2628de4eec25c56c40952e6fb35a2593d0" +source = "git+https://github.com/datafuse-extras/sqlparser-rs?rev=fee0056#fee00567b17af62cfe43bc8e9cfe528084a3ab76" dependencies = [ "hashbrown 0.12.0", "log", diff --git a/common/ast/Cargo.toml b/common/ast/Cargo.toml index 96612d26628b..477cfc30c4a6 100644 --- a/common/ast/Cargo.toml +++ b/common/ast/Cargo.toml @@ -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" diff --git a/common/exception/Cargo.toml b/common/exception/Cargo.toml index caeacf8781d2..c4c6a2ab923d 100644 --- a/common/exception/Cargo.toml +++ b/common/exception/Cargo.toml @@ -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" } diff --git a/common/functions/Cargo.toml b/common/functions/Cargo.toml index 9aff2e70228f..cb0fee2fc441 100644 --- a/common/functions/Cargo.toml +++ b/common/functions/Cargo.toml @@ -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"] } diff --git a/query/Cargo.toml b/query/Cargo.toml index 52c85185e150..c33372043409 100644 --- a/query/Cargo.toml +++ b/query/Cargo.toml @@ -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" diff --git a/query/src/sql/sql_common.rs b/query/src/sql/sql_common.rs index 63e9bffaad31..0088f0597816 100644 --- a/query/src/sql/sql_common.rs +++ b/query/src/sql/sql_common.rs @@ -41,13 +41,24 @@ 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 ))) } From 84a5fc72d3fdfa4c2a3c98d5745a423b91a67072 Mon Sep 17 00:00:00 2001 From: Veeupup Date: Fri, 22 Apr 2022 11:57:04 +0800 Subject: [PATCH 2/2] fix stateless-test Signed-off-by: Veeupup --- query/src/sql/sql_common.rs | 4 +++- .../suites/0_stateless/02_function/02_0002_function_cast.sql | 2 +- .../02_function/02_0011_function_window_funnel.sql | 2 +- .../0_stateless/02_function/02_0012_function_datetimes.result | 4 ++-- .../suites/0_stateless/03_dml/03_0003_select_group_by.result | 4 ++-- .../0_stateless/03_dml/03_0014_insert_into_select.result | 4 ++-- .../0_stateless/03_dml/03_0016_insert_into_values.result | 4 ++-- .../0_stateless/05_ddl/05_0000_ddl_create_tables.result | 4 ++-- .../0_stateless/09_fuse_engine/09_0001_remote_insert.result | 4 ++-- .../0_stateless/09_fuse_engine/09_0001_remote_insert.sql | 4 ++-- 10 files changed, 19 insertions(+), 17 deletions(-) diff --git a/query/src/sql/sql_common.rs b/query/src/sql/sql_common.rs index 0088f0597816..99c2c0669d1b 100644 --- a/query/src/sql/sql_common.rs +++ b/query/src/sql/sql_common.rs @@ -42,7 +42,9 @@ impl SQLCommon { SQLDataType::Boolean => Ok(bool::to_data_type()), SQLDataType::Date => Ok(DateType::arc()), // default precision is 6, microseconds - SQLDataType::Timestamp(None) | SQLDataType::DateTime(None) => Ok(DateTimeType::arc(6, None)), + 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)) diff --git a/tests/suites/0_stateless/02_function/02_0002_function_cast.sql b/tests/suites/0_stateless/02_function/02_0002_function_cast.sql index 404da2cb1369..71dab59c70bb 100644 --- a/tests/suites/0_stateless/02_function/02_0002_function_cast.sql +++ b/tests/suites/0_stateless/02_function/02_0002_function_cast.sql @@ -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} diff --git a/tests/suites/0_stateless/02_function/02_0011_function_window_funnel.sql b/tests/suites/0_stateless/02_function/02_0011_function_window_funnel.sql index b7b760a89784..f0a19819e26e 100644 --- a/tests/suites/0_stateless/02_function/02_0011_function_window_funnel.sql +++ b/tests/suites/0_stateless/02_function/02_0011_function_window_funnel.sql @@ -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), diff --git a/tests/suites/0_stateless/02_function/02_0012_function_datetimes.result b/tests/suites/0_stateless/02_function/02_0012_function_datetimes.result index c89230d2f627..36ce160cf58d 100644 --- a/tests/suites/0_stateless/02_function/02_0012_function_datetimes.result +++ b/tests/suites/0_stateless/02_function/02_0012_function_datetimes.result @@ -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 diff --git a/tests/suites/0_stateless/03_dml/03_0003_select_group_by.result b/tests/suites/0_stateless/03_dml/03_0003_select_group_by.result index 21a30bdc1660..df7e2dce67d9 100644 --- a/tests/suites/0_stateless/03_dml/03_0003_select_group_by.result +++ b/tests/suites/0_stateless/03_dml/03_0003_select_group_by.result @@ -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 diff --git a/tests/suites/0_stateless/03_dml/03_0014_insert_into_select.result b/tests/suites/0_stateless/03_dml/03_0014_insert_into_select.result index 03fbf8419566..c1012ac566bd 100644 --- a/tests/suites/0_stateless/03_dml/03_0014_insert_into_select.result +++ b/tests/suites/0_stateless/03_dml/03_0014_insert_into_select.result @@ -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 diff --git a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result index a47232124af5..9db01e1cc133 100644 --- a/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result +++ b/tests/suites/0_stateless/03_dml/03_0016_insert_into_values.result @@ -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 diff --git a/tests/suites/0_stateless/05_ddl/05_0000_ddl_create_tables.result b/tests/suites/0_stateless/05_ddl/05_0000_ddl_create_tables.result index ec4d6a9a977c..f1c5e6e6a6c6 100644 --- a/tests/suites/0_stateless/05_ddl/05_0000_ddl_create_tables.result +++ b/tests/suites/0_stateless/05_ddl/05_0000_ddl_create_tables.result @@ -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 [] diff --git a/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.result b/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.result index fa5dde9484c9..0320ad1c71c8 100644 --- a/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.result +++ b/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.result @@ -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 diff --git a/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.sql b/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.sql index ed46af673582..4b1430837944 100644 --- a/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.sql +++ b/tests/suites/0_stateless/09_fuse_engine/09_0001_remote_insert.sql @@ -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;