Skip to content

Commit

Permalink
Test: fix mpp test bug (#6511)
Browse files Browse the repository at this point in the history
ref #4609, close #6442
  • Loading branch information
ywqzzy authored Dec 22, 2022
1 parent b99541f commit 2ea6253
Show file tree
Hide file tree
Showing 45 changed files with 319 additions and 112 deletions.
2 changes: 2 additions & 0 deletions dbms/src/Debug/MockComputeServerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
#include <Common/FmtUtils.h>
#include <Debug/MockComputeServerManager.h>
#include <Flash/Mpp/MPPTaskManager.h>
#include <Storages/Transaction/TMTContext.h>
#include <TestUtils/TiFlashTestEnv.h>

#include <chrono>
Expand Down
4 changes: 1 addition & 3 deletions dbms/src/Debug/MockComputeServerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
#pragma once

#include <Debug/MockStorage.h>
#include <Flash/Mpp/MPPTaskManager.h>
#include <Flash/Mpp/MPPTaskId.h>
#include <Server/FlashGrpcServerHolder.h>
#include <Storages/Transaction/TMTContext.h>
#include <TestUtils/TiFlashTestEnv.h>

namespace DB::tests
{
Expand Down
5 changes: 4 additions & 1 deletion dbms/src/Debug/MockExecutor/AggregationBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/AggregateFunctionUniq.h>
#include <Debug/MockExecutor/AggregationBinder.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExchangeReceiverBinder.h>
#include <Debug/MockExecutor/ExchangeSenderBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/FuncSigMap.h>
#include <Parsers/ASTIdentifier.h>
#include <fmt/core.h>

namespace DB::mock
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Debug/MockExecutor/AggregationBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

#pragma once

#include <Debug/MockExecutor/ExchangeReceiverBinder.h>
#include <Debug/MockExecutor/ExchangeSenderBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Parsers/ASTFunction.h>

namespace DB::mock
{
class ExchangeSenderBinder;
class ExchangeReceiverBinder;

class AggregationBinder : public ExecutorBinder
{
public:
Expand Down
18 changes: 18 additions & 0 deletions dbms/src/Debug/MockExecutor/AstToPB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <DataTypes/FieldToDataType.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/FuncSigMap.h>
#include <Flash/Coprocessor/DAGCodec.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Functions/FunctionFactory.h>
#include <Interpreters/Context.h>
#include <Interpreters/convertFieldToType.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Storages/Transaction/TypeMapping.h>
#include <Storages/Transaction/Types.h>
#include <common/logger_useful.h>
#include <common/types.h>
#include <tipb/executor.pb.h>
#include <tipb/select.pb.h>

namespace DB
{
Expand Down
25 changes: 7 additions & 18 deletions dbms/src/Debug/MockExecutor/AstToPB.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,8 @@

#pragma once

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <DataTypes/FieldToDataType.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/FuncSigMap.h>
#include <Flash/Coprocessor/DAGCodec.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Functions/FunctionFactory.h>
#include <Interpreters/Context.h>
#include <Interpreters/convertFieldToType.h>
#include <Parsers/ASTFunction.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTLiteral.h>
#include <Storages/Transaction/TypeMapping.h>
#include <Storages/Transaction/Types.h>
#include <common/logger_useful.h>
#include <common/types.h>
#include <tipb/executor.pb.h>
#include <tipb/select.pb.h>
#include <Flash/Coprocessor/ChunkCodec.h>
#include <Storages/Transaction/TiDB.h>

namespace DB
{
Expand All @@ -41,6 +25,11 @@ extern const int BAD_ARGUMENTS;
extern const int LOGICAL_ERROR;
extern const int NO_SUCH_COLUMN_IN_TABLE;
} // namespace ErrorCodes

class ASTFunction;
class ASTIdentifier;
class Context;

struct MPPCtx
{
Timestamp start_ts;
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Debug/MockExecutor/ExchangeReceiverBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockComputeServerManager.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/ExchangeReceiverBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Storages/Transaction/TiDB.h>
#include <kvproto/mpp.pb.h>

namespace DB::mock
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/MockExecutor/ExchangeReceiverBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>

namespace DB::mock
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Debug/MockExecutor/ExchangeSenderBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockComputeServerManager.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/ExchangeSenderBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Flash/Coprocessor/DAGCodec.h>
#include <Interpreters/Context.h>

namespace DB::mock
{
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/MockExecutor/ExchangeSenderBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>

namespace DB::mock
Expand Down
10 changes: 6 additions & 4 deletions dbms/src/Debug/MockExecutor/ExecutorBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@

#pragma once

#include <Common/typeid_cast.h>
#include <Debug/DAGProperties.h>
#include <Debug/MockComputeServerManager.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Flash/Coprocessor/ChunkCodec.h>
#include <Parsers/IAST.h>
#include <kvproto/mpp.pb.h>
#include <tipb/executor.pb.h>


namespace DB::mock
{
class ExchangeSenderBinder;
class ExchangeReceiverBinder;


// Convert CH AST to tipb::Executor
// Used in integration test framework and Unit test framework.
class ExecutorBinder
Expand All @@ -45,7 +47,7 @@ class ExecutorBinder
index_++;
}

std::vector<std::shared_ptr<ExecutorBinder>> getChildren()
std::vector<std::shared_ptr<ExecutorBinder>> getChildren() const
{
return children;
}
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Debug/MockExecutor/JoinBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/ExchangeReceiverBinder.h>
#include <Debug/MockExecutor/ExchangeSenderBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/JoinBinder.h>
#include <Flash/Coprocessor/DAGCodec.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTTablesInSelectQuery.h>

namespace DB::mock
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Debug/MockExecutor/JoinBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

#pragma once

#include <Debug/MockExecutor/ExchangeReceiverBinder.h>
#include <Debug/MockExecutor/ExchangeSenderBinder.h>
#include <Debug/MockExecutor/ExecutorBinder.h>

namespace DB::mock
{
class ExchangeSenderBinder;
class ExchangeReceiverBinder;
class JoinBinder : public ExecutorBinder
{
public:
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/MockExecutor/LimitBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/LimitBinder.h>
#include <Parsers/ASTLiteral.h>

namespace DB::mock
{
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Debug/MockExecutor/ProjectBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/ProjectBinder.h>
#include <Flash/Coprocessor/DAGCodec.h>
#include <Parsers/ASTAsterisk.h>
#include <Parsers/ASTFunction.h>

namespace DB::mock
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/MockExecutor/SelectionBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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 <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/SelectionBinder.h>

namespace DB::mock
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Debug/MockExecutor/SelectionBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#pragma once

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>

namespace DB::mock
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/MockExecutor/SortBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/SortBinder.h>
#include <Parsers/ASTOrderByElement.h>
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Debug/MockExecutor/TableScanBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockExecutor/AstToPBUtils.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/TableScanBinder.h>
#include <Storages/MutableSupport.h>
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Debug/MockExecutor/TopNBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/TopNBinder.h>
#include <Parsers/ASTLiteral.h>
#include <Parsers/ASTOrderByElement.h>

namespace DB::mock
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Debug/MockExecutor/WindowBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Debug/MockExecutor/AstToPB.h>
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/FuncSigMap.h>
#include <Debug/MockExecutor/WindowBinder.h>
#include <Parsers/ASTFunction.h>

namespace DB::mock
{
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Debug/MockExecutor/WindowBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct MockWindowFrame
std::optional<MockWindowFrameBound> end;
// TODO: support calcFuncs
};

using ASTPartitionByElement = ASTOrderByElement;

class WindowBinder : public ExecutorBinder
Expand Down
33 changes: 25 additions & 8 deletions dbms/src/Debug/MockStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <Debug/MockStorage.h>
#include <Flash/Coprocessor/TiDBTableScan.h>

namespace DB::tests
{
Expand All @@ -22,8 +23,11 @@ void MockStorage::addTableSchema(const String & name, const MockColumnInfoVec &
addTableInfo(name, columnInfos);
}

void MockStorage::addTableData(const String & name, const ColumnsWithTypeAndName & columns)
void MockStorage::addTableData(const String & name, ColumnsWithTypeAndName & columns)
{
for (size_t i = 0; i < columns.size(); ++i)
columns[i].column_id = i;

table_columns[getTableId(name)] = columns;
}

Expand Down Expand Up @@ -123,11 +127,12 @@ CutColumnInfo getCutColumnInfo(size_t rows, Int64 partition_id, Int64 partition_
return {start, cur_rows};
}

ColumnsWithTypeAndName MockStorage::getColumnsForMPPTableScan(Int64 table_id, Int64 partition_id, Int64 partition_num)
ColumnsWithTypeAndName MockStorage::getColumnsForMPPTableScan(const TiDBTableScan & table_scan, Int64 partition_id, Int64 partition_num)
{
auto table_id = table_scan.getLogicalTableID();
if (tableExists(table_id))
{
auto columns_with_type_and_name = table_columns[table_id];
auto columns_with_type_and_name = table_columns[table_scan.getLogicalTableID()];
size_t rows = 0;
for (const auto & col : columns_with_type_and_name)
{
Expand All @@ -141,11 +146,23 @@ ColumnsWithTypeAndName MockStorage::getColumnsForMPPTableScan(Int64 table_id, In
ColumnsWithTypeAndName res;
for (const auto & column_with_type_and_name : columns_with_type_and_name)
{
res.push_back(
ColumnWithTypeAndName(
column_with_type_and_name.column->cut(cut_info.first, cut_info.second),
column_with_type_and_name.type,
column_with_type_and_name.name));
bool contains = false;
for (const auto & column : table_scan.getColumns())
{
if (column.id == column_with_type_and_name.column_id)
{
contains = true;
break;
}
}
if (contains)
{
res.push_back(
ColumnWithTypeAndName(
column_with_type_and_name.column->cut(cut_info.first, cut_info.second),
column_with_type_and_name.type,
column_with_type_and_name.name));
}
}
return res;
}
Expand Down
Loading

0 comments on commit 2ea6253

Please sign in to comment.