From 72186b8e06737f3bdc8d177f6311a74970e8d657 Mon Sep 17 00:00:00 2001 From: taiyang-li <654010905@qq.com> Date: Tue, 5 Dec 2023 17:07:05 +0800 Subject: [PATCH 1/5] fix code style --- .../scalar_function_parser/elementAt.cpp | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/elementAt.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/elementAt.cpp index 956ef162f1a9..eb369a373bf5 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/elementAt.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/elementAt.cpp @@ -21,27 +21,25 @@ namespace local_engine { - class FunctionParserElementAt : public FunctionParserArrayElement - { - public: - explicit FunctionParserElementAt(SerializedPlanParser * plan_parser_) : FunctionParserArrayElement(plan_parser_) { } - ~FunctionParserElementAt() override = default; - static constexpr auto name = "element_at"; - String getName() const override { return name; } +class FunctionParserElementAt : public FunctionParserArrayElement +{ +public: + explicit FunctionParserElementAt(SerializedPlanParser * plan_parser_) : FunctionParserArrayElement(plan_parser_) { } + ~FunctionParserElementAt() override = default; + static constexpr auto name = "element_at"; + String getName() const override { return name; } - const ActionsDAG::Node * parse( - const substrait::Expression_ScalarFunction & substrait_func, - ActionsDAGPtr & actions_dag) const override - { - auto parsed_args = parseFunctionArguments(substrait_func, "", actions_dag); - if (parsed_args.size() != 2) - throw Exception(DB::ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires exactly two arguments", getName()); - if (isMap(removeNullable(parsed_args[0]->result_type))) - return toFunctionNode(actions_dag, "arrayElement", parsed_args); - else - return FunctionParserArrayElement::parse(substrait_func, actions_dag); - } - }; + const ActionsDAG::Node * parse(const substrait::Expression_ScalarFunction & substrait_func, ActionsDAGPtr & actions_dag) const override + { + auto parsed_args = parseFunctionArguments(substrait_func, "", actions_dag); + if (parsed_args.size() != 2) + throw Exception(DB::ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires exactly two arguments", getName()); + if (isMap(removeNullable(parsed_args[0]->result_type))) + return toFunctionNode(actions_dag, "arrayElement", parsed_args); + else + return FunctionParserArrayElement::parse(substrait_func, actions_dag); + } +}; - static FunctionParserRegister register_element_at; +static FunctionParserRegister register_element_at; } From 7708c1942d0f8ff8a6f5e3f53aa1693a44ca4516 Mon Sep 17 00:00:00 2001 From: taiyang-li <654010905@qq.com> Date: Tue, 5 Dec 2023 17:07:19 +0800 Subject: [PATCH 2/5] add uts for element_at --- .../GlutenFunctionValidateSuite.scala | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala index e7e5e317a9b9..9971d75bc6e0 100644 --- a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala +++ b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala @@ -485,4 +485,31 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS "select * from date_table where to_date(from_unixtime(ts)) = '2019-01-01'", noFallBack = true) { _ => } } + + test("test element_at function") { + withSQLConf( + SQLConf.OPTIMIZER_EXCLUDED_RULES.key -> + (ConstantFolding.ruleName + "," + NullPropagation.ruleName)) { + // input type is array> + runQueryAndCompare( + "SELECT array(array(1,2,3), array(4,5,6))[1], " + + "array(array(id,id+1,id+2), array(id+3,id+4,id+5)) from range(100)", + noFallBack = false + )(checkOperatorMatch[ProjectExecTransformer]) + + // input type is array> + runQueryAndCompare( + "SELECT array(array('1','2','3'), array('4','5','6'))[1], " + + "array(array('1','2',cast(id as string)), array('4','5',cast(id as string)))[1] " + + "from range(100)", + noFallBack = false + )(checkOperatorMatch[ProjectExecTransformer]) + + // input type is array> + runQueryAndCompare( + "SELECT array(map(cast(id as string), id), map(cast(id+1 as string), id+1))[1] " + + "from range(100)" noFallBack = false + )(checkOperatorMatch[ProjectExecTransformer]) + } + } } From a4e5792628103172445d111d2ac085da1a783eec Mon Sep 17 00:00:00 2001 From: taiyang-li <654010905@qq.com> Date: Wed, 6 Dec 2023 16:22:56 +0800 Subject: [PATCH 3/5] update clickhouse version --- cpp-ch/clickhouse.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-ch/clickhouse.version b/cpp-ch/clickhouse.version index c796051ded7b..313612fc558c 100644 --- a/cpp-ch/clickhouse.version +++ b/cpp-ch/clickhouse.version @@ -1,3 +1,3 @@ CH_ORG=Kyligence CH_BRANCH=rebase_ch/20231206 -CH_COMMIT=5a611598662 +CH_COMMIT=6bd969f2c79 From 67ad0f89926c5f16d8636186a2477440092ddf6f Mon Sep 17 00:00:00 2001 From: taiyang-li <654010905@qq.com> Date: Wed, 6 Dec 2023 18:12:28 +0800 Subject: [PATCH 4/5] fix building error --- .../glutenproject/execution/GlutenFunctionValidateSuite.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala index 9971d75bc6e0..cbf1d1ca8a81 100644 --- a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala +++ b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala @@ -508,7 +508,8 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS // input type is array> runQueryAndCompare( "SELECT array(map(cast(id as string), id), map(cast(id+1 as string), id+1))[1] " + - "from range(100)" noFallBack = false + "from range(100)", + noFallBack = false )(checkOperatorMatch[ProjectExecTransformer]) } } From 1d39539f2012abbd1539db4536e5a42a401587da Mon Sep 17 00:00:00 2001 From: taiyang-li <654010905@qq.com> Date: Wed, 6 Dec 2023 19:55:33 +0800 Subject: [PATCH 5/5] fix failed uts --- .../execution/GlutenFunctionValidateSuite.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala index cbf1d1ca8a81..b204c9ac3cde 100644 --- a/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala +++ b/backends-clickhouse/src/test/scala/io/glutenproject/execution/GlutenFunctionValidateSuite.scala @@ -494,7 +494,7 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS runQueryAndCompare( "SELECT array(array(1,2,3), array(4,5,6))[1], " + "array(array(id,id+1,id+2), array(id+3,id+4,id+5)) from range(100)", - noFallBack = false + noFallBack = true )(checkOperatorMatch[ProjectExecTransformer]) // input type is array> @@ -502,14 +502,14 @@ class GlutenFunctionValidateSuite extends GlutenClickHouseWholeStageTransformerS "SELECT array(array('1','2','3'), array('4','5','6'))[1], " + "array(array('1','2',cast(id as string)), array('4','5',cast(id as string)))[1] " + "from range(100)", - noFallBack = false + noFallBack = true )(checkOperatorMatch[ProjectExecTransformer]) // input type is array> runQueryAndCompare( "SELECT array(map(cast(id as string), id), map(cast(id+1 as string), id+1))[1] " + "from range(100)", - noFallBack = false + noFallBack = true )(checkOperatorMatch[ProjectExecTransformer]) } }