From 65f0a901493a5091466173aba0141df03fd05a32 Mon Sep 17 00:00:00 2001 From: leiysky Date: Sat, 28 May 2022 00:15:33 +0800 Subject: [PATCH] support tuple in new planner --- query/src/sql/planner/semantic/type_check.rs | 25 +++++++++++++++++++ .../it/servers/http/http_query_handlers.rs | 2 +- .../it/sql/parsers/parser_select_table_at.rs | 20 +++------------ query/tests/it/storages/fuse/meta/snapshot.rs | 4 +-- .../20+_others/20_0001_planner_v2.result | 6 +++++ .../20+_others/20_0001_planner_v2.sql | 3 +++ 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/query/src/sql/planner/semantic/type_check.rs b/query/src/sql/planner/semantic/type_check.rs index ec3b6aaa9edd..ce8a83a5fa88 100644 --- a/query/src/sql/planner/semantic/type_check.rs +++ b/query/src/sql/planner/semantic/type_check.rs @@ -35,6 +35,7 @@ use common_exception::Result; use common_functions::aggregates::AggregateFunctionFactory; use common_functions::scalars::CastFunction; use common_functions::scalars::FunctionFactory; +use common_functions::scalars::TupleFunction; use crate::sessions::QueryContext; use crate::sql::binder::Binder; @@ -429,6 +430,8 @@ impl<'a> TypeChecker<'a> { .await } + Expr::Tuple { exprs, .. } => self.resolve_tuple(exprs).await, + _ => Err(ErrorCode::UnImplement(format!( "Unsupported expr: {:?}", expr @@ -908,4 +911,26 @@ impl<'a> TypeChecker<'a> { data_type, )) } + + async fn resolve_tuple(&mut self, exprs: &[Expr<'a>]) -> Result<(Scalar, DataTypeImpl)> { + let mut args = Vec::with_capacity(exprs.len()); + let mut arg_types = Vec::with_capacity(exprs.len()); + for expr in exprs { + let (arg, data_type) = self.resolve(expr, None).await?; + args.push(arg); + arg_types.push(data_type); + } + let arg_types_ref: Vec<&DataTypeImpl> = arg_types.iter().collect(); + let tuple_func = TupleFunction::try_create_func("", &arg_types_ref)?; + Ok(( + FunctionCall { + arguments: args, + func_name: "tuple".to_string(), + arg_types, + return_type: tuple_func.return_type(), + } + .into(), + tuple_func.return_type(), + )) + } } diff --git a/query/tests/it/servers/http/http_query_handlers.rs b/query/tests/it/servers/http/http_query_handlers.rs index 3634ce265752..b67b504096fd 100644 --- a/query/tests/it/servers/http/http_query_handlers.rs +++ b/query/tests/it/servers/http/http_query_handlers.rs @@ -536,7 +536,7 @@ async fn test_query_log() -> Result<()> { assert_eq!(status, StatusCode::OK, "{:?}", result); assert!(result.error.is_none(), "{:?}", result); - let response = get_uri(&ep, &result.kill_uri.as_ref().unwrap()).await; + let response = get_uri(&ep, result.kill_uri.as_ref().unwrap()).await; assert_eq!(response.status(), StatusCode::OK, "{:?}", result); let sql = "select query_text, exception_code, exception_text, stack_trace from system.query_log where log_type=4"; diff --git a/query/tests/it/sql/parsers/parser_select_table_at.rs b/query/tests/it/sql/parsers/parser_select_table_at.rs index ec34d3ecbcf7..0f9f5ce14494 100644 --- a/query/tests/it/sql/parsers/parser_select_table_at.rs +++ b/query/tests/it/sql/parsers/parser_select_table_at.rs @@ -12,18 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashMap; - use common_exception::Result; -use databend_query::sql::statements::AlterTableAction; -use databend_query::sql::statements::DfAlterTable; -use databend_query::sql::statements::DfCreateTable; -use databend_query::sql::statements::DfDescribeTable; -use databend_query::sql::statements::DfDropTable; use databend_query::sql::statements::DfQueryStatement; -use databend_query::sql::statements::DfRenameTable; -use databend_query::sql::statements::DfShowCreateTable; -use databend_query::sql::statements::DfTruncateTable; use databend_query::sql::*; use sqlparser::ast::*; @@ -37,12 +27,10 @@ fn select_table_at() -> Result<()> { distinct: false, from: vec![TableWithJoins { relation: TableFactor::Table { - name: ObjectName { - 0: vec![Ident { - value: "t".to_owned(), - quote_style: None, - }], - }, + name: ObjectName(vec![Ident { + value: "t".to_owned(), + quote_style: None, + }]), alias: None, args: vec![], with_hints: vec![], diff --git a/query/tests/it/storages/fuse/meta/snapshot.rs b/query/tests/it/storages/fuse/meta/snapshot.rs index d8485aaaff76..bb61b4aa3fdf 100644 --- a/query/tests/it/storages/fuse/meta/snapshot.rs +++ b/query/tests/it/storages/fuse/meta/snapshot.rs @@ -39,7 +39,7 @@ fn snapshot_timestamp_monotonic_increase() { let current = TableSnapshot::new( uuid, &prev.timestamp, - prev.prev_snapshot_id.clone(), + prev.prev_snapshot_id, schema, Default::default(), vec![], @@ -61,7 +61,7 @@ fn snapshot_timestamp_time_skew_tolerance() { let current = TableSnapshot::new( uuid, &prev.timestamp, - prev.prev_snapshot_id.clone(), + prev.prev_snapshot_id, schema, Default::default(), vec![], diff --git a/tests/suites/0_stateless/20+_others/20_0001_planner_v2.result b/tests/suites/0_stateless/20+_others/20_0001_planner_v2.result index b9c31b0fb9e5..8d9a030f0da8 100644 --- a/tests/suites/0_stateless/20+_others/20_0001_planner_v2.result +++ b/tests/suites/0_stateless/20+_others/20_0001_planner_v2.result @@ -319,3 +319,9 @@ BuildHashTable × 1 processor 4 0 2 +====Tuple==== +('field', 0) +('field', 1) +('field', 2) +('field', 3) +('field', 4) diff --git a/tests/suites/0_stateless/20+_others/20_0001_planner_v2.sql b/tests/suites/0_stateless/20+_others/20_0001_planner_v2.sql index 5f19da46c6ca..5610a675c8c4 100644 --- a/tests/suites/0_stateless/20+_others/20_0001_planner_v2.sql +++ b/tests/suites/0_stateless/20+_others/20_0001_planner_v2.sql @@ -259,4 +259,7 @@ insert into t values ('foo'); select POSITION('o' IN t.a) from t; drop table t; +select '====Tuple===='; +select ('field', number) from numbers(5); + set enable_planner_v2 = 0;