Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: wrap some API for aggregation function tests #5787

Closed
wants to merge 10 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove useless api.
ywqzzy committed Sep 5, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Urhengulas Johann Hemmann
commit ca8f03f19932b1f4d1cdc4f4046c6168829603c5
7 changes: 2 additions & 5 deletions dbms/src/Flash/tests/gtest_aggregation_executor.cpp
Original file line number Diff line number Diff line change
@@ -358,13 +358,10 @@ CATCH
TEST_F(ExecutorAggTestRunner, TestFramwork)
try
{
executeGroupByAndAssert({toNullableVec<Int8>("tinyint_", col_tinyint)}, {toNullableVec<Int8>(ColumnWithNullableInt8{-1, 2, {}, 0, 1, 3, -2})});
executeGroupByAndAssertWithTable(db_name, table_types, {types_col_name[2]}, {toNullableVec<Int8>(ColumnWithNullableInt8{-1, 2, {}, 0, 1, 3, -2})});

executeGroupByAndAssert({toNullableVec<Int8>("tinyint_", col_tinyint)}, {toNullableVec<Int8>({-1, 2, {}, 0, 1, 3, -2})});
executeGroupByAndAssert({toNullableVec<Int8>("tinyint_", col_tinyint), toNullableVec<Int16>("smallint_", col_smallint)}, {toNullableVec<Int8>({0, 2, 0, -1, 1, -2, 3, {}, {}}), toNullableVec<Int16>({-1, 3, -2, 4, 2, 0, {}, {}, 0})});
executeAggFunctionAndAssert({"Max"}, toNullableVec<Int8>("tinyint_", col_tinyint), {toNullableVec<Int8>(ColumnWithNullableInt8{3})});
executeAggFunctionAndAssert({"Max", "Min"}, toNullableVec<Int8>("tinyint_", col_tinyint), {toNullableVec<Int8>(ColumnWithNullableInt8{3}), toNullableVec<Int8>(ColumnWithNullableInt8{-2})});
executeAggFunctionAndAssertWithTable("test_db", "types", {"Max"}, {types_col_name[2]}, {toNullableVec<Int8>(ColumnWithNullableInt8{3})});
executeAggFunctionAndAssertWithTable("test_db", "types", {"Max", "Min"}, {types_col_name[2], types_col_name[2]}, {toNullableVec<Int8>(ColumnWithNullableInt8{3}), toNullableVec<Int8>(ColumnWithNullableInt8{-2})});
}
CATCH

39 changes: 3 additions & 36 deletions dbms/src/TestUtils/AggregationTestUtils.cpp
Original file line number Diff line number Diff line change
@@ -14,10 +14,6 @@

#include <TestUtils/AggregationTestUtils.h>

#include <cstddef>

#include "Parsers/IAST.h"

namespace DB::tests
{
void AggregationTest::SetUpTestCase()
@@ -64,22 +60,10 @@ void AggregationTest::executeAggFunctionAndAssert(const std::vector<String> & fu
checkResult(request, expected_cols);
}

void AggregationTest::executeAggFunctionAndAssertWithTable(const String & db_name, const String & table_name, const std::vector<String> & func_names, const std::vector<String> & col_names, const ColumnsWithTypeAndName & expected_cols)
{
std::vector<ASTPtr> agg_funcs;

for (size_t i = 0; i < func_names.size(); ++i)
agg_funcs.push_back(aggFunctionBuilder(func_names[i], col_names[i]));

auto request = context.scan(db_name, table_name)
.aggregation(agg_funcs, {})
.build(context);

checkResult(request, expected_cols);
}

void AggregationTest::executeGroupByAndAssert(const ColumnsWithTypeAndName & cols, const ColumnsWithTypeAndName & expected_cols)
{
RUNTIME_CHECK_MSG(cols.size() == expected_cols.size(), "number of group_by columns don't match number of expected columns");

String db_name = "test_group";
String table_name = "test_table_group";
MockAstVec group_by_cols;
@@ -102,29 +86,12 @@ void AggregationTest::executeGroupByAndAssert(const ColumnsWithTypeAndName & col
checkResult(request, expected_cols);
}

void AggregationTest::executeGroupByAndAssertWithTable(const String & db_name, const String & table_name, const std::vector<String> & group_by_cols, const ColumnsWithTypeAndName & expected_cols)
{
MockAstVec group_by_col_asts;
MockColumnNameVec proj_names;
for (const auto & col : group_by_cols)
{
group_by_col_asts.push_back(col(col));
proj_names.push_back(col);
}

auto request = context.scan(db_name, table_name)
.aggregation({}, group_by_col_asts)
.project(proj_names)
.build(context);

checkResult(request, expected_cols);
}

void AggregationTest::checkResult(std::shared_ptr<tipb::DAGRequest> request, const ColumnsWithTypeAndName & expected_cols)
{
for (size_t i = 1; i <= 10; ++i)
ASSERT_COLUMNS_EQ_UR(expected_cols, executeStreams(request, i)) << "expected_cols: " << getColumnsContent(expected_cols) << ", actual_cols: " << getColumnsContent(executeStreams(request, i));
}

ASTPtr AggregationTest::aggFunctionBuilder(const String & func_name, const String & col_name)
{
ASTPtr func;
17 changes: 8 additions & 9 deletions dbms/src/TestUtils/AggregationTestUtils.h
Original file line number Diff line number Diff line change
@@ -26,17 +26,16 @@ class AggregationTest : public ExecutorTest
static ::testing::AssertionResult checkAggReturnType(const String & agg_name, const DataTypes & data_types, const DataTypePtr & expect_type);

// Test one aggregation functions without group by.
void executeAggFunctionAndAssert(const std::vector<String> & func_names, const ColumnWithTypeAndName & column, const ColumnsWithTypeAndName & expected_cols);

// Prequisite: add a mock table in MockDAGRequestContext.
// func_names: agg functions which are going to execute.
// col_names: columns each agg function executed on.
void executeAggFunctionAndAssertWithTable(const String & db_name, const String & table_name, const std::vector<String> & func_names, const std::vector<String> & col_names, const ColumnsWithTypeAndName & expected_cols);
void executeAggFunctionAndAssert(
const std::vector<String> & func_names,
const ColumnWithTypeAndName & column,
const ColumnsWithTypeAndName & expected_cols);

// Test group by columns
void executeGroupByAndAssert(const ColumnsWithTypeAndName & cols, const ColumnsWithTypeAndName & expected_cols);
// Prequisite: add a mock table in MockDAGRequestContext.
void executeGroupByAndAssertWithTable(const String & db_name, const String & table_name, const std::vector<String> & group_by_cols, const ColumnsWithTypeAndName & expected_cols);
// Note that we must give columns in cols a name.
void executeGroupByAndAssert(
const ColumnsWithTypeAndName & cols,
const ColumnsWithTypeAndName & expected_cols);

static void SetUpTestCase();