diff --git a/dbms/src/Flash/tests/gtest_interpreter.cpp b/dbms/src/Flash/tests/gtest_interpreter.cpp index 7f4ff2808ed..ff0d2f05e34 100644 --- a/dbms/src/Flash/tests/gtest_interpreter.cpp +++ b/dbms/src/Flash/tests/gtest_interpreter.cpp @@ -640,7 +640,7 @@ try .filter(eq(col("s1"), col("s2"))) .aggregation(Max(col("s1")), col("s2")) .limit(10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( Limit, limit = 10 Expression: @@ -658,7 +658,7 @@ Limit, limit = 10 .filter(eq(col("s1"), col("s2"))) .aggregation(Max(col("s1")), col("s2")) .topN("s2", false, 10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( Union: SharedQuery x 20: diff --git a/dbms/src/Flash/tests/gtest_planner_interpreter.cpp b/dbms/src/Flash/tests/gtest_planner_interpreter.cpp index 0e733e2ed2a..744126d5f7c 100644 --- a/dbms/src/Flash/tests/gtest_planner_interpreter.cpp +++ b/dbms/src/Flash/tests/gtest_planner_interpreter.cpp @@ -994,7 +994,7 @@ try .aggregation(Max(col("s1")), col("s2")) .filter(eq(col("s2"), lit(Field("1", 1)))) .limit(10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( Expression: Limit, limit = 10 @@ -1015,7 +1015,7 @@ Expression: .aggregation(Max(col("s1")), col("s2")) .filter(eq(col("s2"), lit(Field("1", 1)))) .topN("s2", false, 10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( Union: Expression x 20: diff --git a/dbms/src/TestUtils/mockExecutor.cpp b/dbms/src/TestUtils/mockExecutor.cpp index be17678f1fd..4ed72917436 100644 --- a/dbms/src/TestUtils/mockExecutor.cpp +++ b/dbms/src/TestUtils/mockExecutor.cpp @@ -85,8 +85,9 @@ void DAGRequestBuilder::initDAGRequest(tipb::DAGRequest & dag_request) } // traval the AST tree to build tipb::Executor recursively. -std::shared_ptr DAGRequestBuilder::build(MockDAGRequestContext & mock_context) +std::shared_ptr DAGRequestBuilder::build(MockDAGRequestContext & mock_context, DAGRequestType type) { + // build tree struct base executor MPPInfo mpp_info(properties.start_ts, -1, -1, {}, mock_context.receiver_source_task_ids_map); std::shared_ptr dag_request_ptr = std::make_shared(); tipb::DAGRequest & dag_request = *dag_request_ptr; @@ -94,20 +95,20 @@ std::shared_ptr DAGRequestBuilder::build(MockDAGRequestContext root->toTiPBExecutor(dag_request.mutable_root_executor(), properties.collator, mpp_info, mock_context.context); root.reset(); executor_index = 0; - return dag_request_ptr; -} -std::shared_ptr DAGRequestBuilder::buildToListStruct(MockDAGRequestContext & mock_context) -{ - auto dag_request_ptr = build(mock_context); - auto & mutable_executors = *dag_request_ptr->mutable_executors(); - traverseExecutorsReverse(dag_request_ptr.get(), [&](const tipb::Executor & executor) -> bool { - auto * mutable_executor = mutable_executors.Add(); - (*mutable_executor) = executor; - mutable_executor->clear_executor_id(); - return true; - }); - dag_request_ptr->release_root_executor(); + // convert to list struct base executor + if (type == DAGRequestType::list) + { + auto & mutable_executors = *dag_request_ptr->mutable_executors(); + traverseExecutorsReverse(dag_request_ptr.get(), [&](const tipb::Executor & executor) -> bool { + auto * mutable_executor = mutable_executors.Add(); + (*mutable_executor) = executor; + mutable_executor->clear_executor_id(); + return true; + }); + dag_request_ptr->release_root_executor(); + } + return dag_request_ptr; } diff --git a/dbms/src/TestUtils/mockExecutor.h b/dbms/src/TestUtils/mockExecutor.h index fe133569c0c..0b6850669fb 100644 --- a/dbms/src/TestUtils/mockExecutor.h +++ b/dbms/src/TestUtils/mockExecutor.h @@ -43,6 +43,12 @@ inline int32_t convertToTiDBCollation(int32_t collation) return -(abs(collation)); } +enum class DAGRequestType +{ + tree, + list, +}; + /** Responsible for Hand write tipb::DAGRequest * Use this class to mock DAGRequest, then feed the DAGRequest into * the Interpreter for test purpose. @@ -70,8 +76,7 @@ class DAGRequestBuilder return root; } - std::shared_ptr build(MockDAGRequestContext & mock_context); - std::shared_ptr buildToListStruct(MockDAGRequestContext & mock_context); + std::shared_ptr build(MockDAGRequestContext & mock_context, DAGRequestType type = DAGRequestType::tree); QueryTasks buildMPPTasks(MockDAGRequestContext & mock_context); QueryTasks buildMPPTasks(MockDAGRequestContext & mock_context, const DAGProperties & properties); diff --git a/dbms/src/TestUtils/tests/gtest_mock_executors.cpp b/dbms/src/TestUtils/tests/gtest_mock_executors.cpp index a859ddb7c44..5a58c8fb2f4 100644 --- a/dbms/src/TestUtils/tests/gtest_mock_executors.cpp +++ b/dbms/src/TestUtils/tests/gtest_mock_executors.cpp @@ -351,7 +351,7 @@ try .aggregation(Max(col("s1")), col("s2")) .filter(eq(col("s2"), lit(Field("1", 1)))) .limit(10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( Limit | 10 Selection | equals(<1, String>, <-5692549928996306944, String>)} @@ -368,7 +368,7 @@ Limit | 10 .aggregation(Max(col("s1")), col("s2")) .filter(eq(col("s2"), lit(Field("1", 1)))) .topN("s2", false, 10) - .buildToListStruct(context); + .build(context, DAGRequestType::list); String expected = R"( TopN | order_by: {(<1, String>, desc: false)}, limit: 10 Selection | equals(<1, String>, <-5692549928996306944, String>)}