diff --git a/.github/licenserc.yml b/.github/licenserc.yml index 3621f075f39..48945d1795d 100644 --- a/.github/licenserc.yml +++ b/.github/licenserc.yml @@ -34,6 +34,7 @@ header: - '**/NOTICE' - 'dbms/src/IO/tests/limit_read_buffer.reference' - 'dbms/src/IO/tests/DevicePixelRatio' + - 'dbms/src/Flash/tests/gtest_*.out' - 'Cargo.lock' - 'Cargo.toml' - 'rust-toolchain' diff --git a/dbms/src/Flash/tests/gtest_interpreter.cpp b/dbms/src/Flash/tests/gtest_interpreter.cpp index 72b46dbea0a..e129c5587a5 100644 --- a/dbms/src/Flash/tests/gtest_interpreter.cpp +++ b/dbms/src/Flash/tests/gtest_interpreter.cpp @@ -12,22 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include namespace DB { namespace tests { -class InterpreterExecuteTest : public DB::tests::ExecutorTest +class InterpreterExecuteTest : public DB::tests::InterpreterTestUtils { public: void initializeContext() override { - ExecutorTest::initializeContext(); + InterpreterTestUtils::initializeContext(); enablePlanner(false); + // The following steps update the expected results of cases in bulk + // 1. manually delete the gtest_interpreter.out + // 2. call setRecord() + // 3. ./gtests_dbms --gtest_filter=InterpreterExecuteTest.* + // setRecord(); + context.addMockTable({"test_db", "test_table"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "test_table_1"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}, {"s3", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "r_table"}, {{"r_a", TiDB::TP::TypeLong}, {"r_b", TiDB::TP::TypeString}, {"join_c", TiDB::TP::TypeString}}); @@ -50,23 +56,7 @@ try .filter(eq(col("s2"), col("s3"))) .topN("s2", false, 10) .build(context); - { - String expected = R"( -Union: - SharedQuery x 10: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Filter: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .filter(eq(col("s2"), col("s3"))) @@ -75,23 +65,7 @@ Union: .limit(10) .build(context); - { - String expected = R"( -Union: - SharedQuery x 10: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Expression: - Expression: - Filter: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -103,40 +77,14 @@ try .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - Expression: - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) .topN({{"s1", true}, {"s2", false}}, 10) .project({"s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -145,25 +93,7 @@ Union: .aggregation({Max(col("s1"))}, {col("s1"), col("s2")}) .project({"max(s1)", "s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -175,52 +105,13 @@ Union: .project({"max(s1)", "s1"}) .limit(10) .build(context); - { - String expected = R"( -Union: - SharedQuery x 10: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Expression: - Expression: - Expression: - Expression: - Filter: - Expression: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } - + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - Expression: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) @@ -228,20 +119,7 @@ Union: .project({"s1"}) .exchangeSender(tipb::Broadcast) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - Expression: - Expression: - Expression: - Expression: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -253,44 +131,14 @@ try .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Expression: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table") .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - SharedQuery: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Expression: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .sort({{"s1", true}, {"s2", false}}, true) @@ -298,27 +146,7 @@ Union: .window(RowNumber(), {"s1", true}, {"s1", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "s3", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - SharedQuery: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Union: - Expression x 10: - Expression: - SharedQuery: - Expression: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -331,35 +159,13 @@ try .sort({{"s1", true}, {"s2", false}}, true, enable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), enable) .build(context); - { - String expected = R"( -Union: - Expression x 8: - Expression: - Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Expression: - MergeSorting: , limit = 0 - PartialSorting: : limit = 0 - Expression: - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); auto topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - String topn_expected = R"( -Union: - SharedQuery x 10: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); // fine-grained shuffle is disabled. request = context @@ -367,28 +173,13 @@ Union: .sort({{"s1", true}, {"s2", false}}, true, disable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), disable) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Expression: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - Expression: - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); } CATCH @@ -408,20 +199,7 @@ try enable) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 8: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { // Join Source. @@ -435,20 +213,7 @@ CreatingSets enable) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 8: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 5: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { // Join Source. @@ -461,21 +226,7 @@ CreatingSets {col("join_c")}, disable) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -489,12 +240,7 @@ try auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, enable) .build(context); - String expected = R"( -Union: - Expression x 8: - Aggregating: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -502,13 +248,7 @@ Union: auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, disable) .build(context); - String expected = R"( -Union: - Expression x 10: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - MockExchangeReceiver x 10)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -535,28 +275,7 @@ try {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -576,29 +295,7 @@ CreatingSets tipb::JoinType::TypeLeftOuterJoin, {col("join_c")}) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -619,30 +316,7 @@ CreatingSets {col("join_c")}) .exchangeSender(tipb::PassThrough) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 10 - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -661,22 +335,7 @@ try {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -690,23 +349,7 @@ CreatingSets {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Right - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - HashJoinProbe: - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -722,29 +365,7 @@ CreatingSets .exchangeSender(tipb::PassThrough) .limit(10) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 20: , join_kind = Right - Expression: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 20 - SharedQuery: - Limit, limit = 10 - Union: - Limit x 20, limit = 10 - Expression: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - HashJoinProbe: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH @@ -759,14 +380,7 @@ try .aggregation(Max(col("s1")), col("s2")) .limit(10) .build(context, DAGRequestType::list); - String expected = R"( -Limit, limit = 10 - Expression: - Aggregating - Expression: - Filter: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); + runAndAssert(request, 1); } { @@ -776,19 +390,7 @@ Limit, limit = 10 .aggregation(Max(col("s1")), col("s2")) .topN("s2", false, 10) .build(context, DAGRequestType::list); - String expected = R"( -Union: - SharedQuery x 20: - Expression: - MergeSorting, limit = 10 - Union: - PartialSorting x 20: limit = 10 - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - Filter: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH diff --git a/dbms/src/Flash/tests/gtest_interpreter.out b/dbms/src/Flash/tests/gtest_interpreter.out new file mode 100644 index 00000000000..89e323ef5e8 --- /dev/null +++ b/dbms/src/Flash/tests/gtest_interpreter.out @@ -0,0 +1,463 @@ +~test_suite_name: SingleQueryBlock +~result_index: 0 +~result: +Union: + SharedQuery x 10: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Filter: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter: + MockTableScan +@ +~test_suite_name: SingleQueryBlock +~result_index: 1 +~result: +Union: + SharedQuery x 10: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Expression: + Expression: + Filter: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 0 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + Expression: + Expression: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 2 +~result: +Union: + Expression x 10: + Expression: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 3 +~result: +Union: + SharedQuery x 10: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Expression: + Expression: + Expression: + Expression: + Filter: + Expression: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 4 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + Expression: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 5 +~result: +Union: + MockExchangeSender x 10 + Expression: + Expression: + Expression: + Expression: + Expression: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: Window +~result_index: 0 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Expression: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + Expression: + MockTableScan +@ +~test_suite_name: Window +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + SharedQuery: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Expression: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + Expression: + MockTableScan +@ +~test_suite_name: Window +~result_index: 2 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + SharedQuery: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Union: + Expression x 10: + Expression: + SharedQuery: + Expression: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + Expression: + MockTableScan +@ +~test_suite_name: FineGrainedShuffle +~result_index: 0 +~result: +Union: + Expression x 8: + Expression: + Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Expression: + MergeSorting: , limit = 0 + PartialSorting: : limit = 0 + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 1 +~result: +Union: + SharedQuery x 10: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 2 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Expression: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 3 +~result: +Union: + SharedQuery x 10: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 8: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 8: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 5: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 0 +~result: +Union: + Expression x 8: + Aggregating: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + MockExchangeReceiver x 10 +@ +~test_suite_name: Join +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: Join +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: Join +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 10 + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: JoinThenAgg +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Right + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + HashJoinProbe: + Expression: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 20: , join_kind = Right + Expression: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 20 + SharedQuery: + Limit, limit = 10 + Union: + Limit x 20, limit = 10 + Expression: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + HashJoinProbe: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: ListBase +~result_index: 0 +~result: +Limit, limit = 10 + Expression: + Aggregating + Expression: + Filter: + MockTableScan +@ +~test_suite_name: ListBase +~result_index: 1 +~result: +Union: + SharedQuery x 20: + Expression: + MergeSorting, limit = 10 + Union: + PartialSorting x 20: limit = 10 + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + Filter: + MockTableScan +@ diff --git a/dbms/src/Flash/tests/gtest_pipeline_interpreter.cpp b/dbms/src/Flash/tests/gtest_pipeline_interpreter.cpp index 022c06d0a20..fde4fd38763 100644 --- a/dbms/src/Flash/tests/gtest_pipeline_interpreter.cpp +++ b/dbms/src/Flash/tests/gtest_pipeline_interpreter.cpp @@ -12,23 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include namespace DB { namespace tests { -class PipelineInterpreterExecuteTest : public DB::tests::ExecutorTest +class PipelineInterpreterExecuteTest : public DB::tests::InterpreterTestUtils { public: void initializeContext() override { - ExecutorTest::initializeContext(); + InterpreterTestUtils::initializeContext(); enablePlanner(true); enablePipeline(true); + // The following steps update the expected results of cases in bulk + // 1. manually delete the gtest_pipeline_interpreter.out + // 2. call setRecord() + // 3. ./gtests_dbms --gtest_filter=PipelineInterpreterExecuteTest.* + // setRecord(); + context.addMockTable({"test_db", "test_table"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "test_table_1"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}, {"s3", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "r_table"}, {{"r_a", TiDB::TP::TypeLong}, {"r_b", TiDB::TP::TypeString}, {"join_c", TiDB::TP::TypeString}}); @@ -47,45 +53,21 @@ try .filter(eq(col("s1"), col("s3"))) .filter(eq(col("s1"), col("s2"))) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Filter|selection_1 -> Filter|selection_2 -> Filter|selection_3 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .limit(10) .limit(9) .limit(8) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Limit|limit_2 -> Limit|limit_3 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .topN("s3", false, 10) .topN("s2", false, 9) .topN("s1", false, 8) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 8 - Union: - PartialSorting x 10: limit = 8 - SharedQuery: - MergeSorting, limit = 9 - Union: - PartialSorting x 10: limit = 9 - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -98,24 +80,7 @@ try .filter(eq(col("s2"), col("s3"))) .topN("s2", false, 10) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .filter(eq(col("s2"), col("s3"))) @@ -123,24 +88,7 @@ Union: .filter(eq(col("s2"), col("s3"))) .limit(10) .build(context); - - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -151,72 +99,32 @@ try auto request = context.scan("test_db", "test_table_1") .limit(10) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Projection|project_1 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 5, final: true - MockTableScan x 5)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .build(context); - { - String expected = R"( -Expression: - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 5: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .filter(eq(col("s2"), col("s3"))) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Filter|selection_1 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); /// other cases request = context.scan("test_db", "test_table_1") @@ -224,170 +132,50 @@ Union: .project({"s1", "s2", "s3"}) .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - SharedQuery x 10: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - Limit, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .project({"s1", "s2", "s3"}) .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - SharedQuery x 10: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .project({"s2", "s3"}) .aggregation({Max(col("s2"))}, {col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - MockTableScan x 10)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - MockTableScan x 10)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -MockExchangeSender - Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -MockExchangeSender - Expression: - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .limit(10) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator -> MockExchangeSender|exchange_sender_2"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); DAGRequestBuilder table1 = context.scan("test_db", "r_table"); DAGRequestBuilder table2 = context.scan("test_db", "l_table"); request = table1.join(table2.limit(1), tipb::JoinType::TypeLeftOuterJoin, {col("join_c")}).build(context); - { - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - SharedQuery: - Limit, limit = 1 - Union: - Limit x 10, limit = 1 - MockTableScan - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -399,29 +187,14 @@ try .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = "pipeline#0: MockTableScan|table_scan_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) .topN({{"s1", true}, {"s2", false}}, 10) .project({"s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -430,22 +203,7 @@ Union: .aggregation({Max(col("s1"))}, {col("s1"), col("s2")}) .project({"max(s1)", "s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -457,38 +215,14 @@ Union: .project({"max(s1)", "s1"}) .limit(10) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = "pipeline#0: MockExchangeReceiver|exchange_receiver_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) @@ -496,10 +230,7 @@ Union: .project({"s1"}) .exchangeSender(tipb::Broadcast) .build(context); - { - String expected = "pipeline#0: MockExchangeReceiver|exchange_receiver_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator -> MockExchangeSender|exchange_sender_4"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -511,38 +242,14 @@ try .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table") .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .sort({{"s1", true}, {"s2", false}}, true) @@ -550,21 +257,7 @@ Union: .window(RowNumber(), {"s1", true}, {"s1", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "s3", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Union: - SharedQuery x 10: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -579,33 +272,13 @@ try .sort({{"s1", true}, {"s2", false}}, true, enable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), enable) .build(context); - { - String expected = R"( -Union: - Expression x 8: - Expression: - Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting: , limit = 0 - PartialSorting: : limit = 0 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); auto topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - String topn_expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); // fine-grained shuffle is disabled. request = context @@ -613,26 +286,13 @@ Union: .sort({{"s1", true}, {"s2", false}}, true, disable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), disable) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); } CATCH @@ -653,21 +313,7 @@ try {col("join_c")}, enable) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 8: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { // Join Source. @@ -680,21 +326,7 @@ CreatingSets {col("join_c")}, disable) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -710,14 +342,7 @@ try auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, enable) .build(context); - String expected = R"( -Union: - Expression x 8: - Expression: - Aggregating: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -725,15 +350,7 @@ Union: auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, disable) .build(context); - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -760,28 +377,7 @@ try {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -801,29 +397,7 @@ CreatingSets tipb::JoinType::TypeLeftOuterJoin, {col("join_c")}) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -845,29 +419,7 @@ CreatingSets .exchangeSender(tipb::PassThrough) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 10 - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -886,24 +438,7 @@ try {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -917,25 +452,7 @@ CreatingSets {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Right - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - HashJoinProbe: - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -951,30 +468,7 @@ CreatingSets .limit(10) .exchangeSender(tipb::PassThrough) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 20: , join_kind = Right - Expression: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 20 - Expression: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 20, limit = 10 - Expression: - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - Expression: - HashJoinProbe: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH @@ -990,16 +484,7 @@ try .filter(eq(col("s2"), lit(Field("1", 1)))) .limit(10) .build(context, DAGRequestType::list); - String expected = R"( -Expression: - Limit, limit = 10 - Filter - Expression: - Aggregating - Expression: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); + runAndAssert(request, 1); } { @@ -1010,22 +495,7 @@ Expression: .filter(eq(col("s2"), lit(Field("1", 1)))) .topN("s2", false, 10) .build(context, DAGRequestType::list); - String expected = R"( -Union: - Expression x 20: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 20: limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH diff --git a/dbms/src/Flash/tests/gtest_pipeline_interpreter.out b/dbms/src/Flash/tests/gtest_pipeline_interpreter.out new file mode 100644 index 00000000000..82700ed7b47 --- /dev/null +++ b/dbms/src/Flash/tests/gtest_pipeline_interpreter.out @@ -0,0 +1,650 @@ +~test_suite_name: StrangeQuery +~result_index: 0 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Filter|selection_1 -> Filter|selection_2 -> Filter|selection_3 -> Projection|NonTiDBOperator +@ +~test_suite_name: StrangeQuery +~result_index: 1 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Limit|limit_2 -> Limit|limit_3 -> Projection|NonTiDBOperator +@ +~test_suite_name: StrangeQuery +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 8 + Union: + PartialSorting x 10: limit = 8 + SharedQuery: + MergeSorting, limit = 9 + Union: + PartialSorting x 10: limit = 9 + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: SingleQueryBlock +~result_index: 0 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter + MockTableScan +@ +~test_suite_name: SingleQueryBlock +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 0 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 1 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 2 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Projection|project_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 3 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Projection|project_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 4 +~result: +Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 5 +~result: +Union: + Expression x 5: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 5, final: true + MockTableScan x 5 +@ +~test_suite_name: ParallelQuery +~result_index: 6 +~result: +Expression: + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 7 +~result: +Union: + Expression x 5: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 5: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 8 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Filter|selection_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 9 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Filter|selection_1 -> Projection|NonTiDBOperator +@ +~test_suite_name: ParallelQuery +~result_index: 10 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + SharedQuery x 10: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 11 +~result: +Expression: + Expression: + Aggregating + Limit, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 12 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + SharedQuery x 10: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 13 +~result: +Expression: + Expression: + Aggregating + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 14 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + MockTableScan x 10 +@ +~test_suite_name: ParallelQuery +~result_index: 15 +~result: +Expression: + Expression: + Aggregating + Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 16 +~result: +Union: + MockExchangeSender x 10 + Expression: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + MockTableScan x 10 +@ +~test_suite_name: ParallelQuery +~result_index: 17 +~result: +MockExchangeSender + Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 18 +~result: +Union: + MockExchangeSender x 10 + Expression: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 19 +~result: +MockExchangeSender + Expression: + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 20 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator -> MockExchangeSender|exchange_sender_2 +@ +~test_suite_name: ParallelQuery +~result_index: 21 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Limit|limit_1 -> Projection|NonTiDBOperator -> MockExchangeSender|exchange_sender_2 +@ +~test_suite_name: ParallelQuery +~result_index: 22 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + SharedQuery: + Limit, limit = 1 + Union: + Limit x 10, limit = 1 + MockTableScan + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 0 +~result: +pipeline#0: MockTableScan|table_scan_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 2 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 3 +~result: +Union: + Expression x 10: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 4 +~result: +pipeline#0: MockExchangeReceiver|exchange_receiver_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 5 +~result: +pipeline#0: MockExchangeReceiver|exchange_receiver_0 -> Projection|project_1 -> Projection|project_2 -> Projection|project_3 -> Projection|NonTiDBOperator -> MockExchangeSender|exchange_sender_4 +@ +~test_suite_name: Window +~result_index: 0 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: Window +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: Window +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Union: + SharedQuery x 10: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: FineGrainedShuffle +~result_index: 0 +~result: +Union: + Expression x 8: + Expression: + Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting: , limit = 0 + PartialSorting: : limit = 0 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 3 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 8: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 0 +~result: +Union: + Expression x 8: + Expression: + Aggregating: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + MockExchangeReceiver +@ +~test_suite_name: Join +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: Join +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: Join +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 10 + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: JoinThenAgg +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Right + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + HashJoinProbe: + Expression: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 20: , join_kind = Right + Expression: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 20 + Expression: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 20, limit = 10 + Expression: + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + Expression: + HashJoinProbe: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: ListBase +~result_index: 0 +~result: +Expression: + Limit, limit = 10 + Filter + Expression: + Aggregating + Expression: + Filter + MockTableScan +@ +~test_suite_name: ListBase +~result_index: 1 +~result: +Union: + Expression x 20: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 20: limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + Filter + MockTableScan +@ diff --git a/dbms/src/Flash/tests/gtest_planner_interpreter.cpp b/dbms/src/Flash/tests/gtest_planner_interpreter.cpp index f8edd651008..f4fd9be7613 100644 --- a/dbms/src/Flash/tests/gtest_planner_interpreter.cpp +++ b/dbms/src/Flash/tests/gtest_planner_interpreter.cpp @@ -12,23 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include namespace DB { namespace tests { -class PlannerInterpreterExecuteTest : public DB::tests::ExecutorTest +class PlannerInterpreterExecuteTest : public DB::tests::InterpreterTestUtils { public: void initializeContext() override { - ExecutorTest::initializeContext(); + InterpreterTestUtils::initializeContext(); enablePlanner(true); enablePipeline(false); + // The following steps update the expected results of cases in bulk + // 1. manually delete the gtest_planner_interpreter.out + // 2. call setRecord() + // 3. ./gtests_dbms --gtest_filter=PlannerInterpreterExecuteTest.* + // setRecord(); + context.addMockTable({"test_db", "test_table"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "test_table_1"}, {{"s1", TiDB::TP::TypeString}, {"s2", TiDB::TP::TypeString}, {"s3", TiDB::TP::TypeString}}); context.addMockTable({"test_db", "r_table"}, {{"r_a", TiDB::TP::TypeLong}, {"r_b", TiDB::TP::TypeString}, {"join_c", TiDB::TP::TypeString}}); @@ -47,66 +53,21 @@ try .filter(eq(col("s1"), col("s3"))) .filter(eq(col("s1"), col("s2"))) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Filter - Filter - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .limit(10) .limit(9) .limit(8) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Limit, limit = 8 - Union: - Limit x 10, limit = 8 - SharedQuery: - Limit, limit = 9 - Union: - Limit x 10, limit = 9 - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .topN("s3", false, 10) .topN("s2", false, 9) .topN("s1", false, 8) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 8 - Union: - PartialSorting x 10: limit = 8 - SharedQuery: - MergeSorting, limit = 9 - Union: - PartialSorting x 10: limit = 9 - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -119,24 +80,7 @@ try .filter(eq(col("s2"), col("s3"))) .topN("s2", false, 10) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .filter(eq(col("s2"), col("s3"))) @@ -144,24 +88,7 @@ Union: .filter(eq(col("s2"), col("s3"))) .limit(10) .build(context); - - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -172,100 +99,32 @@ try auto request = context.scan("test_db", "test_table_1") .limit(10) .build(context); - { - String expected = R"( -Expression: - Limit, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 5, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) .build(context); - { - String expected = R"( -Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 5, final: true - MockTableScan x 5)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .build(context); - { - String expected = R"( -Expression: - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 5: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); request = context.scan("test_db", "test_table_1") .filter(eq(col("s2"), col("s3"))) .build(context); - { - String expected = R"( -Expression: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - - expected = R"( -Union: - Expression x 5: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 5); - } + runAndAssert(request, 1); + runAndAssert(request, 5); /// other cases request = context.scan("test_db", "test_table_1") @@ -273,184 +132,50 @@ Union: .project({"s1", "s2", "s3"}) .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - SharedQuery x 10: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - Limit, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .project({"s1", "s2", "s3"}) .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - SharedQuery x 10: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .project({"s2", "s3"}) .aggregation({Max(col("s2"))}, {col("s3")}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - MockTableScan x 10)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -Expression: - Expression: - Aggregating - Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .aggregation({Max(col("s1"))}, {col("s2"), col("s3")}) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - MockTableScan x 10)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -MockExchangeSender - Expression: - Expression: - Aggregating - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .topN("s2", false, 10) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -MockExchangeSender - Expression: - MergeSorting, limit = 10 - PartialSorting: limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); request = context.scan("test_db", "test_table_1") .limit(10) .exchangeSender(tipb::PassThrough) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - - expected = R"( -MockExchangeSender - Expression: - Limit, limit = 10 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); - } + runAndAssert(request, 10); + runAndAssert(request, 1); DAGRequestBuilder table1 = context.scan("test_db", "r_table"); DAGRequestBuilder table2 = context.scan("test_db", "l_table"); request = table1.join(table2.limit(1), tipb::JoinType::TypeLeftOuterJoin, {col("join_c")}).build(context); - { - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - SharedQuery: - Limit, limit = 1 - Union: - Limit x 10, limit = 1 - MockTableScan - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -462,35 +187,14 @@ try .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) .topN({{"s1", true}, {"s2", false}}, 10) .project({"s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -499,22 +203,7 @@ Union: .aggregation({Max(col("s1"))}, {col("s1"), col("s2")}) .project({"max(s1)", "s1", "s2"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .project({"s1", "s2", "s3"}) @@ -526,44 +215,14 @@ Union: .project({"max(s1)", "s1"}) .limit(10) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 10, limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) .project({"s1", "s2"}) .project({"s1"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - Expression: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.receive("sender_1") .project({"s1", "s2", "s3"}) @@ -571,17 +230,7 @@ Union: .project({"s1"}) .exchangeSender(tipb::Broadcast) .build(context); - { - String expected = R"( -Union: - MockExchangeSender x 10 - Expression: - Expression: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -593,38 +242,14 @@ try .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table") .sort({{"s1", true}, {"s2", false}}, true) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); request = context.scan("test_db", "test_table_1") .sort({{"s1", true}, {"s2", false}}, true) @@ -632,21 +257,7 @@ Union: .window(RowNumber(), {"s1", true}, {"s1", false}, buildDefaultRowsFrame()) .project({"s1", "s2", "s3", "RowNumber()"}) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - Union: - SharedQuery x 10: - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); } CATCH @@ -661,33 +272,13 @@ try .sort({{"s1", true}, {"s2", false}}, true, enable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), enable) .build(context); - { - String expected = R"( -Union: - Expression x 8: - Expression: - Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting: , limit = 0 - PartialSorting: : limit = 0 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); auto topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - String topn_expected = R"( -Union: - Expression x 10: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 10: limit = 10 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); // fine-grained shuffle is disabled. request = context @@ -695,26 +286,13 @@ Union: .sort({{"s1", true}, {"s2", false}}, true, disable) .window(RowNumber(), {"s1", true}, {"s2", false}, buildDefaultRowsFrame(), disable) .build(context); - { - String expected = R"( -Union: - Expression x 10: - SharedQuery: - Expression: - Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} - MergeSorting, limit = 0 - Union: - PartialSorting x 10: limit = 0 - MockExchangeReceiver - )"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); - } + runAndAssert(request, 10); topn_request = context .receive("sender_1") .topN("s2", false, 10) .build(context); - ASSERT_BLOCKINPUTSTREAM_EQAUL(topn_expected, topn_request, 10); + runAndAssert(topn_request, 10); } CATCH @@ -735,21 +313,7 @@ try {col("join_c")}, enable) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 8: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { // Join Source. @@ -762,21 +326,7 @@ CreatingSets {col("join_c")}, disable) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -792,14 +342,7 @@ try auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, enable) .build(context); - String expected = R"( -Union: - Expression x 8: - Expression: - Aggregating: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -807,15 +350,7 @@ Union: auto request = receiver1 .aggregation({Max(col("s1"))}, {col("s2")}, disable) .build(context); - String expected = R"( -Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -842,28 +377,7 @@ try {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -883,29 +397,7 @@ CreatingSets tipb::JoinType::TypeLeftOuterJoin, {col("join_c")}) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -926,30 +418,7 @@ CreatingSets {col("join_c")}) .exchangeSender(tipb::PassThrough) .build(context); - - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockExchangeReceiver - Union x 2: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 10 - Expression: - Expression: - HashJoinProbe: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } } CATCH @@ -968,24 +437,7 @@ try {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Left - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - HashJoinProbe: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -999,25 +451,7 @@ CreatingSets {col("join_c")}) .aggregation({Max(col("r_a"))}, {col("join_c")}) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 10: , join_kind = Right - Expression: - Expression: - MockTableScan - Union: - Expression x 10: - Expression: - SharedQuery: - ParallelAggregating, max_threads: 10, final: true - Expression x 10: - Expression: - HashJoinProbe: - Expression: - Expression: - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 10); + runAndAssert(request, 10); } { @@ -1033,30 +467,7 @@ CreatingSets .limit(10) .exchangeSender(tipb::PassThrough) .build(context); - String expected = R"( -CreatingSets - Union: - HashJoinBuild x 20: , join_kind = Right - Expression: - Expression: - MockExchangeReceiver - Union: - MockExchangeSender x 20 - Expression: - SharedQuery: - Limit, limit = 10 - Union: - Limit x 20, limit = 10 - Expression: - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - Expression: - HashJoinProbe: - Expression: - Expression: - MockExchangeReceiver)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH @@ -1072,16 +483,7 @@ try .filter(eq(col("s2"), lit(Field("1", 1)))) .limit(10) .build(context, DAGRequestType::list); - String expected = R"( -Expression: - Limit, limit = 10 - Filter - Expression: - Aggregating - Expression: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 1); + runAndAssert(request, 1); } { @@ -1092,22 +494,7 @@ Expression: .filter(eq(col("s2"), lit(Field("1", 1)))) .topN("s2", false, 10) .build(context, DAGRequestType::list); - String expected = R"( -Union: - Expression x 20: - SharedQuery: - MergeSorting, limit = 10 - Union: - PartialSorting x 20: limit = 10 - Expression: - Filter - Expression: - SharedQuery: - ParallelAggregating, max_threads: 20, final: true - Expression x 20: - Filter - MockTableScan)"; - ASSERT_BLOCKINPUTSTREAM_EQAUL(expected, request, 20); + runAndAssert(request, 20); } } CATCH diff --git a/dbms/src/Flash/tests/gtest_planner_interpreter.out b/dbms/src/Flash/tests/gtest_planner_interpreter.out new file mode 100644 index 00000000000..8c46e98de28 --- /dev/null +++ b/dbms/src/Flash/tests/gtest_planner_interpreter.out @@ -0,0 +1,711 @@ +~test_suite_name: StrangeQuery +~result_index: 0 +~result: +Union: + Expression x 10: + Filter + Filter + Filter + MockTableScan +@ +~test_suite_name: StrangeQuery +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + Limit, limit = 8 + Union: + Limit x 10, limit = 8 + SharedQuery: + Limit, limit = 9 + Union: + Limit x 10, limit = 9 + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + MockTableScan +@ +~test_suite_name: StrangeQuery +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 8 + Union: + PartialSorting x 10: limit = 8 + SharedQuery: + MergeSorting, limit = 9 + Union: + PartialSorting x 10: limit = 9 + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: SingleQueryBlock +~result_index: 0 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter + MockTableScan +@ +~test_suite_name: SingleQueryBlock +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Filter + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 0 +~result: +Expression: + Limit, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 1 +~result: +Union: + Expression x 5: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 5, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 2 +~result: +Expression: + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 3 +~result: +Union: + Expression x 5: + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 4 +~result: +Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 5 +~result: +Union: + Expression x 5: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 5, final: true + MockTableScan x 5 +@ +~test_suite_name: ParallelQuery +~result_index: 6 +~result: +Expression: + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 7 +~result: +Union: + Expression x 5: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 5: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 8 +~result: +Expression: + Filter + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 9 +~result: +Union: + Expression x 5: + Filter + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 10 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + SharedQuery x 10: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 11 +~result: +Expression: + Expression: + Aggregating + Limit, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 12 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + SharedQuery x 10: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 13 +~result: +Expression: + Expression: + Aggregating + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 14 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + MockTableScan x 10 +@ +~test_suite_name: ParallelQuery +~result_index: 15 +~result: +Expression: + Expression: + Aggregating + Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 16 +~result: +Union: + MockExchangeSender x 10 + Expression: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + MockTableScan x 10 +@ +~test_suite_name: ParallelQuery +~result_index: 17 +~result: +MockExchangeSender + Expression: + Expression: + Aggregating + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 18 +~result: +Union: + MockExchangeSender x 10 + Expression: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 19 +~result: +MockExchangeSender + Expression: + MergeSorting, limit = 10 + PartialSorting: limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 20 +~result: +Union: + MockExchangeSender x 10 + Expression: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 21 +~result: +MockExchangeSender + Expression: + Limit, limit = 10 + MockTableScan +@ +~test_suite_name: ParallelQuery +~result_index: 22 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + SharedQuery: + Limit, limit = 1 + Union: + Limit x 10, limit = 1 + MockTableScan + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 0 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 2 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 3 +~result: +Union: + Expression x 10: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 10, limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + Expression: + MockTableScan +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 4 +~result: +Union: + Expression x 10: + Expression: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: MultipleQueryBlockWithSource +~result_index: 5 +~result: +Union: + MockExchangeSender x 10 + Expression: + Expression: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: Window +~result_index: 0 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: Window +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: Window +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + Union: + SharedQuery x 10: + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockTableScan +@ +~test_suite_name: FineGrainedShuffle +~result_index: 0 +~result: +Union: + Expression x 8: + Expression: + Window: , function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting: , limit = 0 + PartialSorting: : limit = 0 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 1 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 2 +~result: +Union: + Expression x 10: + SharedQuery: + Expression: + Window, function: {row_number}, frame: {type: Rows, boundary_begin: Current, boundary_end: Current} + MergeSorting, limit = 0 + Union: + PartialSorting x 10: limit = 0 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffle +~result_index: 3 +~result: +Union: + Expression x 10: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 10: limit = 10 + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 8: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleJoin +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 0 +~result: +Union: + Expression x 8: + Expression: + Aggregating: + Expression: + MockExchangeReceiver +@ +~test_suite_name: FineGrainedShuffleAgg +~result_index: 1 +~result: +Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + MockExchangeReceiver +@ +~test_suite_name: Join +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: Join +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: Join +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockExchangeReceiver + Union x 2: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 10 + Expression: + Expression: + HashJoinProbe: + Expression: + MockExchangeReceiver +@ +~test_suite_name: JoinThenAgg +~result_index: 0 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Left + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + HashJoinProbe: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 1 +~result: +CreatingSets + Union: + HashJoinBuild x 10: , join_kind = Right + Expression: + Expression: + MockTableScan + Union: + Expression x 10: + Expression: + SharedQuery: + ParallelAggregating, max_threads: 10, final: true + Expression x 10: + Expression: + HashJoinProbe: + Expression: + Expression: + MockTableScan +@ +~test_suite_name: JoinThenAgg +~result_index: 2 +~result: +CreatingSets + Union: + HashJoinBuild x 20: , join_kind = Right + Expression: + Expression: + MockExchangeReceiver + Union: + MockExchangeSender x 20 + Expression: + SharedQuery: + Limit, limit = 10 + Union: + Limit x 20, limit = 10 + Expression: + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + Expression: + HashJoinProbe: + Expression: + Expression: + MockExchangeReceiver +@ +~test_suite_name: ListBase +~result_index: 0 +~result: +Expression: + Limit, limit = 10 + Filter + Expression: + Aggregating + Expression: + Filter + MockTableScan +@ +~test_suite_name: ListBase +~result_index: 1 +~result: +Union: + Expression x 20: + SharedQuery: + MergeSorting, limit = 10 + Union: + PartialSorting x 20: limit = 10 + Expression: + Filter + Expression: + SharedQuery: + ParallelAggregating, max_threads: 20, final: true + Expression x 20: + Filter + MockTableScan +@ diff --git a/dbms/src/Flash/tests/gtest_scan_concurrency_hint.cpp b/dbms/src/Flash/tests/gtest_scan_concurrency_hint.cpp index 7e00b49fe4e..9736dc26381 100644 --- a/dbms/src/Flash/tests/gtest_scan_concurrency_hint.cpp +++ b/dbms/src/Flash/tests/gtest_scan_concurrency_hint.cpp @@ -23,11 +23,6 @@ namespace tests { class ScanConcurrencyHintTest : public DB::tests::ExecutorTest { -public: - void initializeContext() override - { - ExecutorTest::initializeContext(); - } }; TEST_F(ScanConcurrencyHintTest, InvalidHint) diff --git a/dbms/src/TestUtils/InterpreterTestUtils.cpp b/dbms/src/TestUtils/InterpreterTestUtils.cpp new file mode 100644 index 00000000000..0afc7f4de43 --- /dev/null +++ b/dbms/src/TestUtils/InterpreterTestUtils.cpp @@ -0,0 +1,163 @@ +// Copyright 2023 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 +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace DB::tests +{ +namespace +{ +std::vector stringSplit(const String & str, char delim) +{ + std::stringstream ss(str); + std::string item; + std::vector elems; + while (std::getline(ss, item, delim)) + { + if (!item.empty()) + elems.push_back(item); + } + return elems; +} + +String getOutputPath() +{ + const auto & test_info = testing::UnitTest::GetInstance()->current_test_info(); + assert(test_info); + String file_name = test_info->file(); + auto out_path = file_name.replace(file_name.find(".cpp"), 4, ".out"); + Poco::File file(out_path); + if (!file.exists()) + file.createFile(); + return out_path; +} +} // namespace + +void InterpreterTestUtils::initExpectResults() +{ + if (just_record) + { + case_expect_results.clear(); + return; + } + + auto out_path = getOutputPath(); + Poco::FileInputStream fis(out_path); + String buf; + while (std::getline(fis, buf, '@')) + { + buf = Poco::trim(buf); + if (!buf.empty()) + { + auto spilts = stringSplit(buf, '~'); + assert(spilts.size() == 3); + auto suite_key = fmt::format("~{}", Poco::trim(spilts[0])); + auto unit_result = fmt::format("~{}", Poco::trim(spilts[2])); + case_expect_results[suite_key].push_back(unit_result); + } + } +} + +void InterpreterTestUtils::appendExpectResults() +{ + if (!just_record) + return; + + auto out_path = getOutputPath(); + Poco::FileOutputStream fos(out_path, std::ios::out | std::ios::app); + for (const auto & suite_entry : case_expect_results) + { + const auto & suite_key = suite_entry.first; + for (size_t i = 0; i < suite_entry.second.size(); ++i) + { + fos << suite_key << "\n~result_index: " << i << '\n' + << suite_entry.second[i] << "\n@\n"; + } + } +} + +void InterpreterTestUtils::SetUp() +{ + ExecutorTest::SetUp(); + initExpectResults(); +} + +void InterpreterTestUtils::TearDown() +{ + appendExpectResults(); + ExecutorTest::TearDown(); +} + +void InterpreterTestUtils::runAndAssert( + const std::shared_ptr & request, + size_t concurrency) +{ + const auto & test_info = testing::UnitTest::GetInstance()->current_test_info(); + assert(test_info); + String test_suite_name = test_info->name(); + assert(!test_suite_name.empty()); + auto dag_request_str = Poco::trim(ExecutorSerializer().serialize(request.get())); + auto test_info_msg = [&]() { + return fmt::format( + "test info:\n" + " file: {}\n" + " line: {}\n" + " test_case_name: {}\n" + " test_suite_name: {}\n" + " dag_request: \n{}", + test_info->file(), + test_info->line(), + test_info->test_case_name(), + test_suite_name, + dag_request_str); + }; + auto suite_key = fmt::format("~test_suite_name: {}", test_suite_name); + + DAGContext dag_context( + *request, + "interpreter_test", + concurrency); + TiFlashTestEnv::setUpTestContext(context.context, &dag_context, context.mockStorage(), TestType::INTERPRETER_TEST); + // Don't care regions information in interpreter tests. + auto query_executor = queryExecute(context.context, /*internal=*/true); + auto compare_result = fmt::format("~result:\n{}", Poco::trim(query_executor->toString())); + auto cur_result_index = expect_result_index++; + + if (just_record) + { + assert(case_expect_results[suite_key].size() == cur_result_index); + case_expect_results[suite_key].push_back(compare_result); + return; + } + + auto it = case_expect_results.find(suite_key); + if (it == case_expect_results.end()) + FAIL() << "can not find expect result\n" + << test_info_msg(); + + const auto & func_expect_results = it->second; + assert(func_expect_results.size() > cur_result_index); + String expect_string = func_expect_results[cur_result_index]; + ASSERT_EQ(expect_string, compare_result) << test_info_msg(); +} +} // namespace DB::tests diff --git a/dbms/src/TestUtils/InterpreterTestUtils.h b/dbms/src/TestUtils/InterpreterTestUtils.h new file mode 100644 index 00000000000..9fb0cd9efbb --- /dev/null +++ b/dbms/src/TestUtils/InterpreterTestUtils.h @@ -0,0 +1,52 @@ +// 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. + +#pragma once + +#include + +#include +#include + +namespace DB::tests +{ +class InterpreterTestUtils : public ExecutorTest +{ +public: + void runAndAssert( + const std::shared_ptr & request, + size_t concurrency); + +protected: + void initExpectResults(); + void appendExpectResults(); + + void SetUp() override; + void TearDown() override; + + void setRecord() { just_record = true; } + +private: + // The following steps update the expected results of cases in bulk + // 1. manually delete the *.out file + // 2. call setRecord() + // 3. run unit test cases + bool just_record = false; + + // > + std::unordered_map> case_expect_results; + size_t expect_result_index = 0; +}; + +} // namespace DB::tests diff --git a/dbms/src/WindowFunctions/tests/gtest_lead_lag.cpp b/dbms/src/WindowFunctions/tests/gtest_lead_lag.cpp index 911ff2869b6..1955cefacf9 100644 --- a/dbms/src/WindowFunctions/tests/gtest_lead_lag.cpp +++ b/dbms/src/WindowFunctions/tests/gtest_lead_lag.cpp @@ -35,7 +35,6 @@ class LeadLag : public DB::tests::ExecutorTest void executeWithConcurrencyAndBlockSize(const std::shared_ptr & request, const ColumnsWithTypeAndName & expect_columns) { - WRAP_FOR_TEST_BEGIN std::vector block_sizes{1, 2, 3, 4, DEFAULT_BLOCK_SIZE}; for (auto block_size : block_sizes) { @@ -44,7 +43,6 @@ class LeadLag : public DB::tests::ExecutorTest ASSERT_COLUMNS_EQ_UR(expect_columns, executeStreams(request, 2)); ASSERT_COLUMNS_EQ_UR(expect_columns, executeStreams(request, max_concurrency_level)); } - WRAP_FOR_TEST_END } void executeFunctionAndAssert(