From 7691b38164e90b19ed95f6ab953fd8685c739f08 Mon Sep 17 00:00:00 2001 From: baishen Date: Wed, 27 Sep 2023 13:49:30 +0800 Subject: [PATCH] fix(query): fix get field with float value (#13041) --- src/query/sql/src/planner/binder/distinct.rs | 17 ++++++++++------- .../sql/src/planner/semantic/type_check.rs | 11 ++++++++++- .../base/03_common/03_0022_select_distinct | 4 ++++ .../base/03_common/03_0026_insert_into_tuple | 3 +++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/query/sql/src/planner/binder/distinct.rs b/src/query/sql/src/planner/binder/distinct.rs index 4c9f3d67ccc4..e6da2b4d5d88 100644 --- a/src/query/sql/src/planner/binder/distinct.rs +++ b/src/query/sql/src/planner/binder/distinct.rs @@ -30,6 +30,7 @@ use crate::plans::ScalarExpr; use crate::plans::ScalarItem; use crate::BindContext; use crate::IndexType; +use crate::WindowChecker; impl Binder { pub fn bind_distinct( @@ -43,16 +44,18 @@ impl Binder { let scalar_items: Vec = scalar_items .drain() .map(|(_, item)| { + let mut scalar = item.scalar; if bind_context.in_grouping { let group_checker = GroupingChecker::new(bind_context); - let scalar = group_checker.resolve(&item.scalar, None)?; - Ok(ScalarItem { - scalar, - index: item.index, - }) - } else { - Ok(item) + scalar = group_checker.resolve(&scalar, None)?; + } else if !bind_context.windows.window_functions.is_empty() { + let window_checker = WindowChecker::new(bind_context); + scalar = window_checker.resolve(&scalar)?; } + Ok(ScalarItem { + scalar, + index: item.index, + }) }) .collect::>()?; diff --git a/src/query/sql/src/planner/semantic/type_check.rs b/src/query/sql/src/planner/semantic/type_check.rs index 839b1d187755..953876a4ad60 100644 --- a/src/query/sql/src/planner/semantic/type_check.rs +++ b/src/query/sql/src/planner/semantic/type_check.rs @@ -1011,7 +1011,16 @@ impl<'a> TypeChecker<'a> { let path = match accessor { MapAccessor::Bracket { key: box Expr::Literal { lit, .. }, - } => lit.clone(), + } => { + if !matches!(lit, Literal::UInt64(_) | Literal::String(_)) { + return Err(ErrorCode::SemanticError(format!( + "Unsupported accessor: {:?}", + lit + )) + .set_span(*span)); + } + lit.clone() + } MapAccessor::Dot { key } | MapAccessor::Colon { key } => { Literal::String(key.name.clone()) } diff --git a/tests/sqllogictests/suites/base/03_common/03_0022_select_distinct b/tests/sqllogictests/suites/base/03_common/03_0022_select_distinct index 8374f822bb5f..c7dd625af6e0 100644 --- a/tests/sqllogictests/suites/base/03_common/03_0022_select_distinct +++ b/tests/sqllogictests/suites/base/03_common/03_0022_select_distinct @@ -22,3 +22,7 @@ SELECT count(distinct number %3) c FROM numbers(1000) where number > 3; ---- 3 +query I +SELECT DISTINCT row_number() OVER (PARTITION BY number) FROM numbers(100) +---- +1 diff --git a/tests/sqllogictests/suites/base/03_common/03_0026_insert_into_tuple b/tests/sqllogictests/suites/base/03_common/03_0026_insert_into_tuple index 42ab2718003f..bd8a41dcded6 100644 --- a/tests/sqllogictests/suites/base/03_common/03_0026_insert_into_tuple +++ b/tests/sqllogictests/suites/base/03_common/03_0026_insert_into_tuple @@ -25,6 +25,9 @@ select t.1, t.2, t.3, t.4, t.5, t.6 from t1 1 100 12.34 abc 2020-01-01 2020-01-01 00:00:00.000000 0 200 -25.73 xyz 2022-06-01 2022-06-01 12:00:00.000000 +statement error 1065 +select t[1.1] from t1 + statement error 1005 CREATE TABLE IF NOT EXISTS t2(t Tuple(a Bool, Int64)) Engine = Fuse