This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 3fd775470e98418306e6a9649f8aaa5584ff7609
Author: zhannngchen <48427519+zhannngc...@users.noreply.github.com>
AuthorDate: Tue Mar 15 11:43:18 2022 +0800

    [improvement](ut) add unit tests for min/max function, and cleaned up some 
unused code (#8458)
---
 .../aggregate_function_min_max.h                   |  87 ----------------
 be/test/vec/aggregate_functions/CMakeLists.txt     |   3 +-
 .../vec/aggregate_functions/agg_min_max_test.cpp   | 109 +++++++++++++++++++++
 3 files changed, 110 insertions(+), 89 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_min_max.h 
b/be/src/vec/aggregate_functions/aggregate_function_min_max.h
index 9c2f097..2b769e5 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_min_max.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_min_max.h
@@ -76,35 +76,6 @@ public:
         value = to.value;
     }
 
-    bool change_first_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        if (!has()) {
-            change(column, row_num, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_first_time(const Self& to, Arena* arena) {
-        if (!has() && to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_every_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        change(column, row_num, arena);
-        return true;
-    }
-
-    bool change_every_time(const Self& to, Arena* arena) {
-        if (to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
     bool change_if_less(const IColumn& column, size_t row_num, Arena* arena) {
         if (!has() || assert_cast<const 
ColumnVector<T>&>(column).get_data()[row_num] < value) {
             change(column, row_num, arena);
@@ -192,35 +163,6 @@ public:
         value = to.value;
     }
 
-    bool change_first_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        if (!has()) {
-            change(column, row_num, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_first_time(const Self& to, Arena* arena) {
-        if (!has() && to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_every_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        change(column, row_num, arena);
-        return true;
-    }
-
-    bool change_every_time(const Self& to, Arena* arena) {
-        if (to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
     bool change_if_less(const IColumn& column, size_t row_num, Arena* arena) {
         if (!has() ||
             assert_cast<const 
ColumnDecimal<Decimal128>&>(column).get_data()[row_num] < value) {
@@ -387,35 +329,6 @@ public:
             return false;
     }
 
-    bool change_first_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        if (!has()) {
-            change(column, row_num, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_first_time(const Self& to, Arena* arena) {
-        if (!has() && to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
-    bool change_every_time(const IColumn& column, size_t row_num, Arena* 
arena) {
-        change(column, row_num, arena);
-        return true;
-    }
-
-    bool change_every_time(const Self& to, Arena* arena) {
-        if (to.has()) {
-            change(to, arena);
-            return true;
-        } else
-            return false;
-    }
-
     bool change_if_less(const Self& to, Arena* arena) {
         if (to.has() && (!has() || to.get_string_ref() < get_string_ref())) {
             change(to, arena);
diff --git a/be/test/vec/aggregate_functions/CMakeLists.txt 
b/be/test/vec/aggregate_functions/CMakeLists.txt
index e3dc095..5c7c278 100644
--- a/be/test/vec/aggregate_functions/CMakeLists.txt
+++ b/be/test/vec/aggregate_functions/CMakeLists.txt
@@ -19,5 +19,4 @@
 set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/test/vec/aggregate_functions")
 
 ADD_BE_TEST(agg_test)
-
-
+ADD_BE_TEST(agg_min_max_test)
diff --git a/be/test/vec/aggregate_functions/agg_min_max_test.cpp 
b/be/test/vec/aggregate_functions/agg_min_max_test.cpp
new file mode 100644
index 0000000..a76f8db
--- /dev/null
+++ b/be/test/vec/aggregate_functions/agg_min_max_test.cpp
@@ -0,0 +1,109 @@
+// 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 <memory>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
+#include "vec/aggregate_functions/aggregate_function_min_max.h"
+#include "vec/columns/column_vector.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/data_types/data_type_string.h"
+
+const int agg_test_batch_size = 4096;
+
+namespace doris::vectorized {
+// declare function
+void register_aggregate_function_minmax(AggregateFunctionSimpleFactory& 
factory);
+
+class AggMinMaxTest : public ::testing::TestWithParam<std::string> {};
+
+TEST_P(AggMinMaxTest, min_max_test) {
+    std::string min_max_type = GetParam();
+    // Prepare test data.
+    auto column_vector_int32 = ColumnVector<Int32>::create();
+    for (int i = 0; i < agg_test_batch_size; i++) {
+        column_vector_int32->insert(cast_to_nearest_field_type(i));
+    }
+
+    // Prepare test function and parameters.
+    AggregateFunctionSimpleFactory factory;
+    register_aggregate_function_minmax(factory);
+    DataTypes data_types = {std::make_shared<DataTypeInt32>()};
+    Array array;
+    auto agg_function = factory.get(min_max_type, data_types, array);
+    std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
+    AggregateDataPtr place = memory.get();
+    agg_function->create(place);
+
+    // Do aggregation.
+    const IColumn* column[1] = {column_vector_int32.get()};
+    for (int i = 0; i < agg_test_batch_size; i++) {
+        agg_function->add(place, column, i, nullptr);
+    }
+
+    // Check result.
+    ColumnInt32 ans;
+    agg_function->insert_result_into(place, ans);
+    ASSERT_EQ(min_max_type == "min" ? 0 : agg_test_batch_size - 1, 
ans.get_element(0));
+    agg_function->destroy(place);
+}
+
+TEST_P(AggMinMaxTest, min_max_string_test) {
+    std::string min_max_type = GetParam();
+    // Prepare test data.
+    auto column_vector_str = ColumnString::create();
+    std::vector<std::string> str_data = {"", "xyz", "z", "zzz", "abc", "foo", 
"bar"};
+    for (const auto& s : str_data) {
+        column_vector_str->insert_data(s.c_str(), s.length());
+    }
+
+    // Prepare test function and parameters.
+    AggregateFunctionSimpleFactory factory;
+    register_aggregate_function_minmax(factory);
+    DataTypes data_types = {std::make_shared<DataTypeString>()};
+    Array array;
+    auto agg_function = factory.get(min_max_type, data_types, array);
+    std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
+    AggregateDataPtr place = memory.get();
+    agg_function->create(place);
+
+    // Do aggregation.
+    const IColumn* column[1] = {column_vector_str.get()};
+    for (int i = 0; i < str_data.size(); i++) {
+        agg_function->add(place, column, i, nullptr);
+    }
+
+    // Check result.
+    ColumnString ans;
+    agg_function->insert_result_into(place, ans);
+    ASSERT_EQ(min_max_type == "min" ? StringRef("") : StringRef("zzz"), 
ans.get_data_at(0));
+    agg_function->destroy(place);
+}
+
+INSTANTIATE_TEST_SUITE_P(Params, AggMinMaxTest,
+                         ::testing::ValuesIn(std::vector<std::string> {"min", 
"max"}));
+
+} // namespace doris::vectorized
+
+int main(int argc, char** argv) {
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to