diff --git a/src/query/sql/src/executor/table_read_plan.rs b/src/query/sql/src/executor/table_read_plan.rs index 2d401e806503..9cf4daa64f1d 100644 --- a/src/query/sql/src/executor/table_read_plan.rs +++ b/src/query/sql/src/executor/table_read_plan.rs @@ -35,8 +35,6 @@ use databend_common_expression::Scalar; use databend_common_expression::TableField; use databend_common_license::license::Feature::DataMask; use databend_common_license::license_manager::LicenseManagerSwitch; -use databend_common_meta_app::tenant::Tenant; -use databend_common_settings::Settings; use databend_common_users::UserApiProvider; use databend_enterprise_data_mask_feature::get_datamask_handler; use log::info; @@ -117,7 +115,8 @@ impl ToReadDataSourcePlan for dyn Table { }); // We need the partition sha256 to specify the result cache. - if ctx.get_settings().get_enable_query_result_cache()? { + let settings = ctx.get_settings(); + if settings.get_enable_query_result_cache()? { let sha = parts.compute_sha256()?; ctx.add_partitions_sha(sha); } @@ -221,10 +220,8 @@ impl ToReadDataSourcePlan for dyn Table { let body = &policy.body; let tokens = tokenize_sql(body)?; - let ast_expr = - parse_expr(&tokens, ctx.get_settings().get_sql_dialect()?)?; + let ast_expr = parse_expr(&tokens, settings.get_sql_dialect()?)?; let mut bind_context = BindContext::new(); - let settings = Settings::create(Tenant::new_literal("dummy")); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; let metadata = Arc::new(RwLock::new(Metadata::default())); diff --git a/src/query/sql/src/planner/expression_parser.rs b/src/query/sql/src/planner/expression_parser.rs index e031ec01a406..aa098e43e5d6 100644 --- a/src/query/sql/src/planner/expression_parser.rs +++ b/src/query/sql/src/planner/expression_parser.rs @@ -41,8 +41,6 @@ use databend_common_expression::TableField; use databend_common_expression::TableSchemaRef; use databend_common_functions::BUILTIN_FUNCTIONS; use databend_common_meta_app::schema::TableInfo; -use databend_common_meta_app::tenant::Tenant; -use databend_common_settings::Settings; use derive_visitor::DriveMut; use parking_lot::RwLock; @@ -118,9 +116,8 @@ pub fn parse_exprs( sql: &str, ) -> Result> { let (mut bind_context, metadata) = bind_table(table_meta)?; - let settings = Settings::create(Tenant::new_literal("dummy")); + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; - let sql_dialect = ctx.get_settings().get_sql_dialect().unwrap_or_default(); let mut type_checker = TypeChecker::try_create( &mut bind_context, ctx, @@ -131,6 +128,7 @@ pub fn parse_exprs( )?; let tokens = tokenize_sql(sql)?; + let sql_dialect = settings.get_sql_dialect().unwrap_or_default(); let ast_exprs = parse_comma_separated_exprs(&tokens, sql_dialect)?; let exprs = ast_exprs .iter() @@ -187,7 +185,6 @@ pub fn parse_computed_expr( schema: DataSchemaRef, sql: &str, ) -> Result { - let settings = Settings::create(Tenant::new_literal("dummy")); let mut bind_context = BindContext::new(); let mut metadata = Metadata::default(); let table_schema = infer_table_schema(&schema)?; @@ -212,8 +209,8 @@ pub fn parse_computed_expr( ); } + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; - let sql_dialect = ctx.get_settings().get_sql_dialect()?; let mut type_checker = TypeChecker::try_create( &mut bind_context, ctx, @@ -224,6 +221,7 @@ pub fn parse_computed_expr( )?; let tokens = tokenize_sql(sql)?; + let sql_dialect = settings.get_sql_dialect()?; let mut asts = parse_comma_separated_exprs(&tokens, sql_dialect)?; if asts.len() != 1 { return Err(ErrorCode::BadDataValueType(format!( @@ -242,10 +240,10 @@ pub fn parse_default_expr_to_string( field: &TableField, ast: &AExpr, ) -> Result<(String, bool)> { - let settings = Settings::create(Tenant::new_literal("dummy")); let mut bind_context = BindContext::new(); let metadata = Metadata::default(); + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; let mut type_checker = TypeChecker::try_create( &mut bind_context, @@ -285,7 +283,6 @@ pub fn parse_computed_expr_to_string( field: &TableField, ast: &AExpr, ) -> Result { - let settings = Settings::create(Tenant::new_literal("dummy")); let mut bind_context = BindContext::new(); let mut metadata = Metadata::default(); for (index, field) in table_schema.fields().iter().enumerate() { @@ -309,6 +306,7 @@ pub fn parse_computed_expr_to_string( ); } + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; let mut type_checker = TypeChecker::try_create( &mut bind_context, @@ -355,7 +353,6 @@ pub fn parse_lambda_expr( columns: &[(String, DataType)], ast: &AExpr, ) -> Result> { - let settings = Settings::create(Tenant::new_literal("dummy")); let metadata = Metadata::default(); bind_context.set_expr_context(ExprContext::InLambdaFunction); @@ -372,6 +369,7 @@ pub fn parse_lambda_expr( ); } + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; let mut type_checker = TypeChecker::try_create( &mut bind_context, @@ -391,9 +389,8 @@ pub fn parse_cluster_keys( cluster_key_str: &str, ) -> Result> { let (mut bind_context, metadata) = bind_table(table_meta)?; - let settings = Settings::create(Tenant::new_literal("dummy")); + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; - let sql_dialect = ctx.get_settings().get_sql_dialect().unwrap_or_default(); let mut type_checker = TypeChecker::try_create( &mut bind_context, ctx, @@ -404,6 +401,7 @@ pub fn parse_cluster_keys( )?; let tokens = tokenize_sql(cluster_key_str)?; + let sql_dialect = settings.get_sql_dialect().unwrap_or_default(); let mut ast_exprs = parse_comma_separated_exprs(&tokens, sql_dialect)?; // unwrap tuple. if ast_exprs.len() == 1 { @@ -468,9 +466,8 @@ pub fn parse_hilbert_cluster_key( cluster_key_str: &str, ) -> Result> { let (mut bind_context, metadata) = bind_table(table_meta)?; - let settings = Settings::create(Tenant::new_literal("dummy")); + let settings = ctx.get_settings(); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; - let sql_dialect = ctx.get_settings().get_sql_dialect().unwrap_or_default(); let mut type_checker = TypeChecker::try_create( &mut bind_context, ctx, @@ -481,6 +478,7 @@ pub fn parse_hilbert_cluster_key( )?; let tokens = tokenize_sql(cluster_key_str)?; + let sql_dialect = settings.get_sql_dialect().unwrap_or_default(); let mut ast_exprs = parse_comma_separated_exprs(&tokens, sql_dialect)?; // unwrap tuple. if ast_exprs.len() == 1 { @@ -611,7 +609,8 @@ pub fn analyze_cluster_keys( table_meta: Arc, sql: &str, ) -> Result<(String, Vec)> { - let sql_dialect = ctx.get_settings().get_sql_dialect().unwrap_or_default(); + let settings = ctx.get_settings(); + let sql_dialect = settings.get_sql_dialect().unwrap_or_default(); let tokens = tokenize_sql(sql)?; let mut ast_exprs = parse_comma_separated_exprs(&tokens, sql_dialect)?; // unwrap tuple. @@ -622,7 +621,6 @@ pub fn analyze_cluster_keys( } let (mut bind_context, metadata) = bind_table(table_meta)?; - let settings = Settings::create(Tenant::new_literal("dummy")); let name_resolution_ctx = NameResolutionContext::try_from(settings.as_ref())?; let mut type_checker = TypeChecker::try_create( &mut bind_context, diff --git a/tests/sqllogictests/suites/query/case_sensitivity/name_hit.test b/tests/sqllogictests/suites/query/case_sensitivity/name_hit.test index 8a8426a8f442..5469549f66da 100644 --- a/tests/sqllogictests/suites/query/case_sensitivity/name_hit.test +++ b/tests/sqllogictests/suites/query/case_sensitivity/name_hit.test @@ -39,3 +39,18 @@ delete from student statement error (?s)1025,.*Unknown table `default`\.`default`\.student \. select * from student + +# ISSUE 17094 +statement ok +CREATE OR REPLACE TABLE T_17094 (City VARCHAR(255), Temperature DECIMAL(10, 2)) + +statement ok +alter table T_17094 cluster by(City) + +query TTIIT +select cluster_key, type, total_block_count, constant_block_count, block_depth_histogram from clustering_information('default','T_17094') +---- +(City) linear 0 0 {} + +statement ok +drop table T_17094 all