Skip to content

Commit

Permalink
Test: port some of delta-merge test into ut, part 1 (#6160)
Browse files Browse the repository at this point in the history
ref #4609
  • Loading branch information
ywqzzy authored Oct 24, 2022
1 parent 6bdb42e commit bd29c38
Show file tree
Hide file tree
Showing 15 changed files with 751 additions and 982 deletions.
17 changes: 12 additions & 5 deletions dbms/src/Debug/dbgFuncCoprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,18 @@ std::tuple<QueryTasks, MakeResOutputStream> compileQuery(
return std::make_shared<UniqRawResReformatBlockOutputStream>(in);
};

/// finalize
std::unordered_set<String> used_columns;
for (auto & schema : root_executor->output_schema)
used_columns.emplace(schema.first);
root_executor->columnPrune(used_columns);

// we will not prune column in executor test
// since it doesn't call initOutputInfo in DAGContext
if (!context.isExecutorTest())
{
/// finalize
std::unordered_set<String> used_columns;
for (auto & schema : root_executor->output_schema)
used_columns.emplace(schema.first);

root_executor->columnPrune(used_columns);
}

return std::make_tuple(queryPlanToQueryTasks(properties, root_executor, executor_index, context), func_wrap_output_stream);
}
Expand Down
182 changes: 182 additions & 0 deletions dbms/src/Flash/tests/gtest_query_executor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Copyright 2022 PingCAP, Ltd.
//
// Licensed 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 <TestUtils/ExecutorTestUtils.h>

namespace DB
{
namespace tests
{
class QueryExecutorTestRunner : public DB::tests::ExecutorTest
{
public:
void initializeContext() override
{
ExecutorTest::initializeContext();
context.addMockTable({"default", "test"},
{{"col_1", TiDB::TP::TypeString}, {"col_2", TiDB::TP::TypeLongLong}},
{toNullableVec<String>("col_1", {"test1", "test2", "test3"}),
toNullableVec<Int64>("col_2", {666, 666, 777})});

context.addMockTable({"default", "test2"},
{{"col_1", TiDB::TP::TypeString}, {"col_2", TiDB::TP::TypeLongLong}},
{toNullableVec<String>("col_1", {"test1", "test2"}),
toNullableVec<Int64>("col_2", {666, 777})});

context.addMockTable({"default", "test3"},
{{"col_1", TiDB::TP::TypeString}, {"col_2", TiDB::TP::TypeLongLong}},
{toNullableVec<String>("col_1", {"test1", "test1"}),
toNullableVec<Int64>("col_2", {666, 666})});

auto const date_type_ptr = std::make_shared<DataTypeMyDate>();
auto date_col_ptr = createColumn<DataTypeMyDate::FieldType>(
{MyDate(2021, 1, 1).toPackedUInt(),
MyDate(2020, 12, 31).toPackedUInt()})
.column;
auto date_col = ColumnWithTypeAndName(date_col_ptr, date_type_ptr, "col_2");
context.addMockTable({"default", "test4"},
{{"col_1", TiDB::TP::TypeString}, {"col_2", TiDB::TP::TypeDate}},
{toNullableVec<String>("col_1", {"test1", "test2"}),
date_col});

context.addMockTable({"default", "test5"},
{{"col_1", TiDB::TP::TypeString}, {"col_2", TiDB::TP::TypeLongLong}},
{toNullableVec<String>("col_1", {"test1", "test2", {}}),
toNullableVec<Int64>("col_2", {666, 777, {}})});
}
};


TEST_F(QueryExecutorTestRunner, aggregation)
try
{
{
auto cols = {toVec<UInt64>({2, 1}), toNullableVec<Int64>({666, 777})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select count(col_1), col_2 from default.test group by col_2"));
}

{
auto cols = {toVec<UInt64>({2, 1}), toVec<UInt64>({2, 1}), toNullableVec<Int64>({666, 777})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select count(col_1),count(col_1),col_2 from default.test group by col_2"));
}

{
auto cols = {toVec<UInt64>({2}), toNullableVec<Int64>({666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select count(col_1),col_2 from default.test where col_2 = 666 group by col_2"));
}
}
CATCH

TEST_F(QueryExecutorTestRunner, filter)
try
{
{
auto cols = {toNullableVec<String>({"test1"}), toNullableVec<Int64>({666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select * from default.test2 where col_2 = 666"));
}

{
auto cols = {toNullableVec<Int64>({777})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select col_2 from default.test2 where col_1 = 'test2'"));
}

{
auto cols = {toNullableVec<Int64>({666, 777}), toNullableVec<String>({"test1", "test2"}), toNullableVec<Int64>({666, 777})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select col_2, col_1, col_2 from default.test2 where col_1 = 'test2' or col_2 = 666"));
}

{
auto cols = {toNullableVec<String>({"test1"}), toNullableVec<Int64>({666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select * from default.test2 where col_2 < 777 or col_2 > 888"));
}

{
auto cols = {toNullableVec<Int64>({777}), toNullableVec<String>({"test2"}), toNullableVec<Int64>({777})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select col_2, col_1, col_2 from default.test2 where col_1 = 'test2' and col_2 = 777"));
}
}
CATCH

TEST_F(QueryExecutorTestRunner, limit)
try
{
{
auto cols = {toNullableVec<Int64>({666}), toNullableVec<String>({"test1"}), toNullableVec<Int64>({666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select col_2, col_1, col_2 from default.test3 where col_2 = 666 limit 1"));
}
}
CATCH

TEST_F(QueryExecutorTestRunner, project)
try
{
{
auto cols = {toNullableVec<String>({"2021-01", "2020-12"})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select date_format(col_2, \'%Y-%m\') from default.test4"));
}
}
CATCH

TEST_F(QueryExecutorTestRunner, topn)
try
{
{
auto cols = {toNullableVec<String>({{}, "test1"}), toNullableVec<Int64>({{}, 666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select * from default.test5 order by col_2 limit 2"));
}

{
auto cols = {toNullableVec<Int64>({777, 666}), toNullableVec<String>({"test2", "test1"}), toNullableVec<Int64>({777, 666})};
ASSERT_COLUMNS_EQ_UR(
cols,
executeRawQuery(
"select col_2, col_1, col_2 from default.test5 where col_1 = 'test2' or col_2 = 666 order by col_1 desc limit 2"));
}
}
CATCH
} // namespace tests
} // namespace DB
Loading

0 comments on commit bd29c38

Please sign in to comment.