From 11d658ec4541fcf2c470c64e745a0c8c79ecfb32 Mon Sep 17 00:00:00 2001 From: kevinyhzou <37431499+KevinyhZou@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:44:49 +0800 Subject: [PATCH] remove least and greatest function (#8091) --- .../Functions/FunctionGreatestLeast.h | 80 ------------------- .../Functions/SparkFunctionGreatest.cpp | 38 --------- .../Functions/SparkFunctionLeast.cpp | 38 --------- .../CommonScalarFunctionParser.cpp | 4 +- .../clickhouse/ClickHouseTestSettings.scala | 2 - .../clickhouse/ClickHouseTestSettings.scala | 2 - .../clickhouse/ClickHouseTestSettings.scala | 2 - .../clickhouse/ClickHouseTestSettings.scala | 2 - 8 files changed, 2 insertions(+), 166 deletions(-) delete mode 100644 cpp-ch/local-engine/Functions/FunctionGreatestLeast.h delete mode 100644 cpp-ch/local-engine/Functions/SparkFunctionGreatest.cpp delete mode 100644 cpp-ch/local-engine/Functions/SparkFunctionLeast.cpp diff --git a/cpp-ch/local-engine/Functions/FunctionGreatestLeast.h b/cpp-ch/local-engine/Functions/FunctionGreatestLeast.h deleted file mode 100644 index e9b66df84ef0..000000000000 --- a/cpp-ch/local-engine/Functions/FunctionGreatestLeast.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once -#include -#include -#include -#include -#include - -namespace DB -{ -namespace ErrorCodes -{ - extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; -} -} -namespace local_engine -{ -template -class FunctionGreatestestLeast : public DB::FunctionLeastGreatestGeneric -{ -public: - bool useDefaultImplementationForNulls() const override { return false; } - virtual String getName() const = 0; - -private: - DB::DataTypePtr getReturnTypeImpl(const DB::DataTypes & types) const override - { - if (types.empty()) - throw DB::Exception(DB::ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} cannot be called without arguments", getName()); - return makeNullable(getLeastSupertype(types)); - } - - DB::ColumnPtr executeImpl(const DB::ColumnsWithTypeAndName & arguments, const DB::DataTypePtr & result_type, size_t input_rows_count) const override - { - size_t num_arguments = arguments.size(); - DB::Columns converted_columns(num_arguments); - for (size_t arg = 0; arg < num_arguments; ++arg) - converted_columns[arg] = castColumn(arguments[arg], result_type)->convertToFullColumnIfConst(); - auto result_column = result_type->createColumn(); - result_column->reserve(input_rows_count); - for (size_t row_num = 0; row_num < input_rows_count; ++row_num) - { - size_t best_arg = 0; - for (size_t arg = 1; arg < num_arguments; ++arg) - { - if constexpr (kind == DB::LeastGreatest::Greatest) - { - auto cmp_result = converted_columns[arg]->compareAt(row_num, row_num, *converted_columns[best_arg], -1); - if (cmp_result > 0) - best_arg = arg; - } - else - { - auto cmp_result = converted_columns[arg]->compareAt(row_num, row_num, *converted_columns[best_arg], 1); - if (cmp_result < 0) - best_arg = arg; - } - } - result_column->insertFrom(*converted_columns[best_arg], row_num); - } - return result_column; - } -}; - -} diff --git a/cpp-ch/local-engine/Functions/SparkFunctionGreatest.cpp b/cpp-ch/local-engine/Functions/SparkFunctionGreatest.cpp deleted file mode 100644 index 920fe1b9c9cc..000000000000 --- a/cpp-ch/local-engine/Functions/SparkFunctionGreatest.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -namespace local_engine -{ -class SparkFunctionGreatest : public FunctionGreatestestLeast -{ -public: - static constexpr auto name = "sparkGreatest"; - static DB::FunctionPtr create(DB::ContextPtr) { return std::make_shared(); } - SparkFunctionGreatest() = default; - ~SparkFunctionGreatest() override = default; - String getName() const override - { - return name; - } -}; - -REGISTER_FUNCTION(SparkGreatest) -{ - factory.registerFunction(); -} -} diff --git a/cpp-ch/local-engine/Functions/SparkFunctionLeast.cpp b/cpp-ch/local-engine/Functions/SparkFunctionLeast.cpp deleted file mode 100644 index 70aafdf07209..000000000000 --- a/cpp-ch/local-engine/Functions/SparkFunctionLeast.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -namespace local_engine -{ -class SparkFunctionLeast : public FunctionGreatestestLeast -{ -public: - static constexpr auto name = "sparkLeast"; - static DB::FunctionPtr create(DB::ContextPtr) { return std::make_shared(); } - SparkFunctionLeast() = default; - ~SparkFunctionLeast() override = default; - String getName() const override - { - return name; - } -}; - -REGISTER_FUNCTION(SparkLeast) -{ - factory.registerFunction(); -} -} diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/CommonScalarFunctionParser.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/CommonScalarFunctionParser.cpp index ec8b4e0d12bf..e4a56194c171 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/CommonScalarFunctionParser.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/CommonScalarFunctionParser.cpp @@ -98,8 +98,8 @@ REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Unhex, unhex, unhex); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Hypot, hypot, hypot); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Sign, sign, sign); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Radians, radians, radians); -REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Greatest, greatest, sparkGreatest); -REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Least, least, sparkLeast); +REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Greatest, greatest, greatest); +REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Least, least, least); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Rand, rand, randCanonical); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Bin, bin, sparkBin); REGISTER_COMMON_SCALAR_FUNCTION_PARSER(Rint, rint, sparkRint); diff --git a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala index 2eb5bd11ffbe..36d5b5177c6b 100644 --- a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala +++ b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala @@ -554,8 +554,6 @@ class ClickHouseTestSettings extends BackendTestSettings { .exclude("SPARK-17617: % (Remainder) double % double on super big double") .exclude("Abs") .exclude("pmod") - .exclude("function least") - .exclude("function greatest") .exclude("SPARK-28322: IntegralDivide supports decimal type") .exclude("SPARK-33008: division by zero on divide-like operations returns incorrect result") .exclude("SPARK-34920: error class") diff --git a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala index a7bf5d4da903..b9bf4e1ac40f 100644 --- a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala +++ b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala @@ -570,8 +570,6 @@ class ClickHouseTestSettings extends BackendTestSettings { .exclude("SPARK-17617: % (Remainder) double % double on super big double") .exclude("Abs") .exclude("pmod") - .exclude("function least") - .exclude("function greatest") .exclude("SPARK-28322: IntegralDivide supports decimal type") .exclude("SPARK-33008: division by zero on divide-like operations returns incorrect result") .exclude("SPARK-34920: error class") diff --git a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala index b7e3905740fb..a407c5d68247 100644 --- a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala +++ b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala @@ -513,8 +513,6 @@ class ClickHouseTestSettings extends BackendTestSettings { .exclude("SPARK-17617: % (Remainder) double % double on super big double") .exclude("Abs") .exclude("pmod") - .exclude("function least") - .exclude("function greatest") .exclude("SPARK-28322: IntegralDivide supports decimal type") .exclude("SPARK-33008: division by zero on divide-like operations returns incorrect result") .exclude("SPARK-34920: error class") diff --git a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala index 8ce145735dc3..9c22af0434af 100644 --- a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala +++ b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala @@ -513,8 +513,6 @@ class ClickHouseTestSettings extends BackendTestSettings { .exclude("SPARK-17617: % (Remainder) double % double on super big double") .exclude("Abs") .exclude("pmod") - .exclude("function least") - .exclude("function greatest") .exclude("SPARK-28322: IntegralDivide supports decimal type") .exclude("SPARK-33008: division by zero on divide-like operations returns incorrect result") .exclude("SPARK-34920: error class")