Skip to content

Commit

Permalink
Refine test framework code and tests (#5261)
Browse files Browse the repository at this point in the history
close #5262
  • Loading branch information
Willendless authored Jul 6, 2022
1 parent b2d8d50 commit 57d001c
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 196 deletions.
124 changes: 58 additions & 66 deletions dbms/src/Flash/tests/gtest_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ try
.filter(eq(col("s1"), col("s2")))
.build(context);
{
executeStreams(request,
{toNullableVec<String>({"banana"}),
toNullableVec<String>({"banana"})});
ASSERT_COLUMNS_EQ_R(executeStreams(request),
createColumns({toNullableVec<String>({"banana"}),
toNullableVec<String>({"banana"})}));
}

request = context.receive("exchange1")
.filter(eq(col("s1"), col("s2")))
.build(context);
{
executeStreams(request,
{toNullableVec<String>({"banana"}),
toNullableVec<String>({"banana"})});
ASSERT_COLUMNS_EQ_R(executeStreams(request),
createColumns({toNullableVec<String>({"banana"}),
toNullableVec<String>({"banana"})}));
}
}
CATCH
Expand All @@ -99,25 +99,23 @@ try
" table_scan_0 | {<0, String>, <1, String>}\n"
" table_scan_1 | {<0, String>, <1, String>}\n";
ASSERT_DAGREQUEST_EQAUL(expected, request);
executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
2);

executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
5);

executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})});
ASSERT_COLUMNS_EQ_R(executeStreams(request, 2),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));

ASSERT_COLUMNS_EQ_R(executeStreams(request, 5),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));

ASSERT_COLUMNS_EQ_R(executeStreams(request),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));
}
request = context
.scan("test_db", "l_table")
Expand All @@ -132,10 +130,9 @@ try
" table_scan_0 | {<0, String>, <1, String>}\n"
" table_scan_1 | {<0, String>, <1, String>}\n";
ASSERT_DAGREQUEST_EQAUL(expected, request);
executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
2);
ASSERT_COLUMNS_EQ_R(executeStreams(request, 2),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));
}

request = context
Expand All @@ -149,18 +146,16 @@ try
" table_scan_0 | {<0, String>, <1, String>}\n"
" table_scan_1 | {<0, String>, <1, String>}\n";
ASSERT_DAGREQUEST_EQAUL(expected, request);
executeStreams(request,
{toNullableVec<String>({"banana", "banana", "banana", "banana"}),
toNullableVec<String>({"apple", "apple", "apple", "banana"}),
toNullableVec<String>({"banana", "banana", "banana", {}}),
toNullableVec<String>({"apple", "apple", "apple", {}})},
2);
executeStreams(request,
{toNullableVec<String>({"banana", "banana", "banana", "banana"}),
toNullableVec<String>({"apple", "apple", "apple", "banana"}),
toNullableVec<String>({"banana", "banana", "banana", {}}),
toNullableVec<String>({"apple", "apple", "apple", {}})},
3);
ASSERT_COLUMNS_EQ_R(executeStreams(request, 2),
createColumns({toNullableVec<String>({"banana", "banana", "banana", "banana"}),
toNullableVec<String>({"apple", "apple", "apple", "banana"}),
toNullableVec<String>({"banana", "banana", "banana", {}}),
toNullableVec<String>({"apple", "apple", "apple", {}})}));
ASSERT_COLUMNS_EQ_R(executeStreams(request, 3),
createColumns({toNullableVec<String>({"banana", "banana", "banana", "banana"}),
toNullableVec<String>({"apple", "apple", "apple", "banana"}),
toNullableVec<String>({"banana", "banana", "banana", {}}),
toNullableVec<String>({"apple", "apple", "apple", {}})}));
}
}
CATCH
Expand All @@ -179,25 +174,23 @@ try
" exchange_receiver_0 | type:PassThrough, {<0, String>, <1, String>}\n"
" exchange_receiver_1 | type:PassThrough, {<0, String>, <1, String>}\n";
ASSERT_DAGREQUEST_EQAUL(expected, request);
executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
2);

executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
5);

executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})});
ASSERT_COLUMNS_EQ_R(executeStreams(request, 2),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));

ASSERT_COLUMNS_EQ_R(executeStreams(request, 5),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));

ASSERT_COLUMNS_EQ_R(executeStreams(request),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));
}
}
CATCH
Expand All @@ -216,12 +209,11 @@ try
" table_scan_0 | {<0, String>, <1, String>}\n"
" exchange_receiver_1 | type:PassThrough, {<0, String>, <1, String>}\n";
ASSERT_DAGREQUEST_EQAUL(expected, request);
executeStreams(request,
{toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})},
2);
ASSERT_COLUMNS_EQ_R(executeStreams(request, 2),
createColumns({toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"}),
toNullableVec<String>({"banana", "banana"}),
toNullableVec<String>({"apple", "banana"})}));
}
}
CATCH
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/tests/gtest_limit_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ try
else
expect_cols = {toNullableVec<String>(col_name, ColumnWithData(col0.begin(), col0.begin() + limit_num))};

executeStreams(request, expect_cols);
ASSERT_COLUMNS_EQ_R(executeStreams(request), expect_cols);
}
}
CATCH
Expand Down
41 changes: 20 additions & 21 deletions dbms/src/Flash/tests/gtest_projection_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ class ExecutorProjectionTestRunner : public DB::tests::ExecutorTest
}

template <typename T>
std::shared_ptr<tipb::DAGRequest> buildDAGRequest(T param, const String & sort_col)
std::shared_ptr<tipb::DAGRequest> buildDAGRequest(T param)
{
/// topN is introduced, so that we can get stable results in concurrency environment.
return context.scan(db_name, table_name).project(param).topN(sort_col, false, 100).build(context);
return context.scan(db_name, table_name).project(param).build(context);
};

void executeWithConcurrency(const std::shared_ptr<tipb::DAGRequest> & request, const ColumnsWithTypeAndName & expect_columns)
{
for (size_t i = 1; i < 10; i += 2)
{
executeStreams(request, expect_columns, i);
ASSERT_COLUMNS_EQ_UR(executeStreams(request, i), expect_columns);
}
}

Expand Down Expand Up @@ -87,26 +86,26 @@ TEST_F(ExecutorProjectionTestRunner, Projection)
try
{
/// Check single column
auto request = buildDAGRequest<MockColumnNames>({col_names[4]}, col_names[4]);
auto request = buildDAGRequest<MockColumnNames>({col_names[4]});
executeWithConcurrency(request, {toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Check multi columns
request = buildDAGRequest<MockColumnNames>({col_names[0], col_names[4]}, col_names[4]);
request = buildDAGRequest<MockColumnNames>({col_names[0], col_names[4]});
executeWithConcurrency(request,
{
toNullableVec<String>(col_names[0], col0_sorted_asc),
toNullableVec<Int32>(col_names[4], col4_sorted_asc),
});

/// Check multi columns
request = buildDAGRequest<MockColumnNames>({col_names[0], col_names[1], col_names[4]}, col_names[4]);
request = buildDAGRequest<MockColumnNames>({col_names[0], col_names[1], col_names[4]});
executeWithConcurrency(request,
{toNullableVec<String>(col_names[0], col0_sorted_asc),
toNullableVec<String>(col_names[1], col1_sorted_asc),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Check duplicate columns
request = buildDAGRequest<MockColumnNames>({col_names[4], col_names[4], col_names[4]}, col_names[4]);
request = buildDAGRequest<MockColumnNames>({col_names[4], col_names[4], col_names[4]});
executeWithConcurrency(request,
{toNullableVec<Int32>(col_names[4], col4_sorted_asc),
toNullableVec<Int32>(col_names[4], col4_sorted_asc),
Expand All @@ -125,7 +124,7 @@ try
columns.push_back(expect_column);
}

request = buildDAGRequest<MockColumnNamesVec>(projection_input, col_names[4]);
request = buildDAGRequest<MockColumnNamesVec>(projection_input);
executeWithConcurrency(request, columns);
}
}
Expand All @@ -139,18 +138,18 @@ try
/// Test "equal" function

/// Data type: TypeString
request = buildDAGRequest<MockAsts>({eq(col(col_names[0]), col(col_names[0])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({eq(col(col_names[0]), col(col_names[0])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 1, 1, 1, 1, 1, 1}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

request = buildDAGRequest<MockAsts>({eq(col(col_names[0]), col(col_names[1])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({eq(col(col_names[0]), col(col_names[1])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 1, 0, {}, 0, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Data type: TypeLong
request = buildDAGRequest<MockAsts>({eq(col(col_names[3]), col(col_names[4])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({eq(col(col_names[3]), col(col_names[4])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 0, 0, {}, 1, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});
Expand All @@ -159,23 +158,23 @@ try
/// Test "greater" function

/// Data type: TypeString
request = buildDAGRequest<MockAsts>({gt(col(col_names[0]), col(col_names[1])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({gt(col(col_names[0]), col(col_names[1])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 0, 0, {}, 0, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

request = buildDAGRequest<MockAsts>({gt(col(col_names[1]), col(col_names[0])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({gt(col(col_names[1]), col(col_names[0])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 1, 0, 1, {}, 1, 1}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Data type: TypeLong
request = buildDAGRequest<MockAsts>({gt(col(col_names[3]), col(col_names[4])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({gt(col(col_names[3]), col(col_names[4])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 1, 1, {}, 0, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

request = buildDAGRequest<MockAsts>({gt(col(col_names[4]), col(col_names[3])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({gt(col(col_names[4]), col(col_names[3])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 1, 0, 0, {}, 0, 1}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});
Expand All @@ -184,34 +183,34 @@ try
/// Test "and" function

/// Data type: TypeString
request = buildDAGRequest<MockAsts>({And(col(col_names[0]), col(col_names[0])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({And(col(col_names[0]), col(col_names[0])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 0, 0, 0, 0, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

request = buildDAGRequest<MockAsts>({And(col(col_names[0]), col(col_names[1])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({And(col(col_names[0]), col(col_names[1])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({0, 0, 0, 0, 0, 0, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Data type: TypeLong
request = buildDAGRequest<MockAsts>({And(col(col_names[3]), col(col_names[4])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({And(col(col_names[3]), col(col_names[4])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 1, 0, 0, {}, 1, 0}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Test "not" function

/// Data type: TypeString
request = buildDAGRequest<MockAsts>({NOT(col(col_names[0])), NOT(col(col_names[1])), NOT(col(col_names[2])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({NOT(col(col_names[0])), NOT(col(col_names[1])), NOT(col(col_names[2])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 1, 1, 1, 1, 1, 1}),
toNullableVec<UInt64>({1, 1, 1, 1, {}, 1, 1}),
toNullableVec<UInt64>({1, {}, 1, 1, 1, 1, {}}),
toNullableVec<Int32>(col_names[4], col4_sorted_asc)});

/// Data type: TypeLong
request = buildDAGRequest<MockAsts>({NOT(col(col_names[3])), NOT(col(col_names[4])), col(col_names[4])}, col_names[4]);
request = buildDAGRequest<MockAsts>({NOT(col(col_names[3])), NOT(col(col_names[4])), col(col_names[4])});
executeWithConcurrency(request,
{toNullableVec<UInt64>({{}, 0, 1, 0, {}, 0, 1}),
toNullableVec<UInt64>({{}, 0, 0, 1, 0, 0, 0}),
Expand Down
Loading

0 comments on commit 57d001c

Please sign in to comment.