Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaRise committed Aug 30, 2022
1 parent ab3008f commit e487c26
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Flash/tests/gtest_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: <final projection>
Expand All @@ -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: <for test>
SharedQuery x 20: <restore concurrency>
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Flash/tests/gtest_planner_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: <final projection>
Limit, limit = 10
Expand All @@ -1015,7 +1015,7 @@ Expression: <final projection>
.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: <for test>
Expression x 20: <final projection>
Expand Down
29 changes: 15 additions & 14 deletions dbms/src/TestUtils/mockExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,30 @@ void DAGRequestBuilder::initDAGRequest(tipb::DAGRequest & dag_request)
}

// traval the AST tree to build tipb::Executor recursively.
std::shared_ptr<tipb::DAGRequest> DAGRequestBuilder::build(MockDAGRequestContext & mock_context)
std::shared_ptr<tipb::DAGRequest> 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<tipb::DAGRequest> dag_request_ptr = std::make_shared<tipb::DAGRequest>();
tipb::DAGRequest & dag_request = *dag_request_ptr;
initDAGRequest(dag_request);
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<tipb::DAGRequest> 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;
}

Expand Down
9 changes: 7 additions & 2 deletions dbms/src/TestUtils/mockExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -70,8 +76,7 @@ class DAGRequestBuilder
return root;
}

std::shared_ptr<tipb::DAGRequest> build(MockDAGRequestContext & mock_context);
std::shared_ptr<tipb::DAGRequest> buildToListStruct(MockDAGRequestContext & mock_context);
std::shared_ptr<tipb::DAGRequest> build(MockDAGRequestContext & mock_context, DAGRequestType type = DAGRequestType::tree);
QueryTasks buildMPPTasks(MockDAGRequestContext & mock_context);
QueryTasks buildMPPTasks(MockDAGRequestContext & mock_context, const DAGProperties & properties);

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/TestUtils/tests/gtest_mock_executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>)}
Expand All @@ -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>)}
Expand Down

0 comments on commit e487c26

Please sign in to comment.