-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
close #6801, ref pingcap/tidb#40663
- Loading branch information
1 parent
1e2fdec
commit 9b3e36d
Showing
10 changed files
with
467 additions
and
1 deletion.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
dbms/src/DataStreams/GeneratedColumnPlaceholderBlockInputStream.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <Columns/ColumnNullable.h> | ||
#include <Columns/ColumnString.h> | ||
#include <Columns/ColumnsNumber.h> | ||
#include <Core/ColumnsWithTypeAndName.h> | ||
#include <DataStreams/IProfilingBlockInputStream.h> | ||
#include <DataTypes/DataTypeNullable.h> | ||
#include <DataTypes/DataTypeString.h> | ||
#include <Flash/Coprocessor/TiDBTableScan.h> | ||
|
||
namespace DB | ||
{ | ||
class GeneratedColumnPlaceholderBlockInputStream : public IProfilingBlockInputStream | ||
{ | ||
public: | ||
GeneratedColumnPlaceholderBlockInputStream( | ||
const BlockInputStreamPtr & input, | ||
const std::vector<std::tuple<UInt64, String, DataTypePtr>> & generated_column_infos_, | ||
const String & req_id_) | ||
: generated_column_infos(generated_column_infos_) | ||
, log(Logger::get(req_id_)) | ||
{ | ||
children.push_back(input); | ||
} | ||
|
||
String getName() const override { return NAME; } | ||
Block getHeader() const override | ||
{ | ||
Block block = children.back()->getHeader(); | ||
insertColumns(block, /*insert_data=*/false); | ||
return block; | ||
} | ||
|
||
static String getColumnName(UInt64 col_index) | ||
{ | ||
return "generated_column_" + std::to_string(col_index); | ||
} | ||
|
||
protected: | ||
void readPrefix() override | ||
{ | ||
RUNTIME_CHECK(!generated_column_infos.empty(), Exception, "generated_column_infos cannot be empty"); | ||
// Validation check. | ||
for (size_t i = 1; i < generated_column_infos.size(); ++i) | ||
{ | ||
RUNTIME_CHECK(std::get<0>(generated_column_infos[i]) > std::get<0>(generated_column_infos[i - 1]), Exception, "generated column index should be ordered"); | ||
} | ||
} | ||
|
||
Block readImpl() override | ||
{ | ||
Block block = children.back()->read(); | ||
insertColumns(block, /*insert_data=*/true); | ||
return block; | ||
} | ||
|
||
private: | ||
void insertColumns(Block & block, bool insert_data) const | ||
{ | ||
if (!block) | ||
return; | ||
|
||
for (const auto & ele : generated_column_infos) | ||
{ | ||
const auto & col_index = std::get<0>(ele); | ||
const auto & col_name = std::get<1>(ele); | ||
const auto & data_type = std::get<2>(ele); | ||
ColumnPtr column = nullptr; | ||
if (insert_data) | ||
column = data_type->createColumnConstWithDefaultValue(block.rows()); | ||
else | ||
column = data_type->createColumn(); | ||
block.insert(col_index, ColumnWithTypeAndName{column, data_type, col_name}); | ||
} | ||
} | ||
|
||
static constexpr auto NAME = "GeneratedColumnPlaceholder"; | ||
const std::vector<std::tuple<UInt64, String, DataTypePtr>> generated_column_infos; | ||
const LoggerPtr log; | ||
}; | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// 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 <DataStreams/MockTableScanBlockInputStream.h> | ||
#include <Flash/Coprocessor/DAGContext.h> | ||
#include <Flash/Coprocessor/DAGPipeline.h> | ||
#include <Flash/Coprocessor/GenSchemaAndColumn.h> | ||
#include <Flash/Coprocessor/InterpreterUtils.h> | ||
#include <Flash/Coprocessor/MockSourceStream.h> | ||
#include <Flash/Pipeline/Exec/PipelineExecBuilder.h> | ||
#include <Flash/Planner/FinalizeHelper.h> | ||
#include <Flash/Planner/PhysicalPlanHelper.h> | ||
#include <Flash/Planner/Plans/PhysicalMockTableScan.h> | ||
#include <Interpreters/Context.h> | ||
#include <Operators/BlockInputStreamSourceOp.h> | ||
|
||
namespace DB | ||
{ | ||
namespace | ||
{ | ||
std::pair<NamesAndTypes, BlockInputStreams> mockSchemaAndStreams( | ||
Context & context, | ||
const String & executor_id, | ||
const LoggerPtr & log, | ||
const TiDBTableScan & table_scan) | ||
{ | ||
NamesAndTypes schema; | ||
BlockInputStreams mock_streams; | ||
auto & dag_context = *context.getDAGContext(); | ||
size_t max_streams = getMockSourceStreamConcurrency(dag_context.initialize_concurrency, context.mockStorage()->getScanConcurrencyHint(table_scan.getLogicalTableID())); | ||
assert(max_streams > 0); | ||
|
||
if (context.mockStorage()->useDeltaMerge()) | ||
{ | ||
assert(context.mockStorage()->tableExistsForDeltaMerge(table_scan.getLogicalTableID())); | ||
schema = context.mockStorage()->getNameAndTypesForDeltaMerge(table_scan.getLogicalTableID()); | ||
mock_streams.emplace_back(context.mockStorage()->getStreamFromDeltaMerge(context, table_scan.getLogicalTableID())); | ||
} | ||
else | ||
{ | ||
/// build from user input blocks. | ||
assert(context.mockStorage()->tableExists(table_scan.getLogicalTableID())); | ||
NamesAndTypes names_and_types; | ||
std::vector<std::shared_ptr<DB::MockTableScanBlockInputStream>> mock_table_scan_streams; | ||
if (context.isMPPTest()) | ||
{ | ||
std::tie(names_and_types, mock_table_scan_streams) = mockSourceStreamForMpp(context, max_streams, log, table_scan); | ||
} | ||
else | ||
{ | ||
std::tie(names_and_types, mock_table_scan_streams) = mockSourceStream<MockTableScanBlockInputStream>(context, max_streams, log, executor_id, table_scan.getLogicalTableID(), table_scan.getColumns()); | ||
} | ||
schema = std::move(names_and_types); | ||
mock_streams.insert(mock_streams.end(), mock_table_scan_streams.begin(), mock_table_scan_streams.end()); | ||
} | ||
|
||
assert(!schema.empty()); | ||
assert(!mock_streams.empty()); | ||
|
||
// Ignore handling GeneratedColumnPlaceholderBlockInputStream for now, because we don't support generated column in test framework. | ||
return {std::move(schema), std::move(mock_streams)}; | ||
} | ||
} // namespace | ||
|
||
PhysicalMockTableScan::PhysicalMockTableScan( | ||
const String & executor_id_, | ||
const NamesAndTypes & schema_, | ||
const String & req_id, | ||
const Block & sample_block_, | ||
const BlockInputStreams & mock_streams_, | ||
Int64 table_id_) | ||
: PhysicalLeaf(executor_id_, PlanType::MockTableScan, schema_, req_id) | ||
, sample_block(sample_block_) | ||
, mock_streams(mock_streams_) | ||
, table_id(table_id_) | ||
{} | ||
|
||
PhysicalPlanNodePtr PhysicalMockTableScan::build( | ||
Context & context, | ||
const String & executor_id, | ||
const LoggerPtr & log, | ||
const TiDBTableScan & table_scan) | ||
{ | ||
assert(context.isTest()); | ||
auto [schema, mock_streams] = mockSchemaAndStreams(context, executor_id, log, table_scan); | ||
|
||
auto physical_mock_table_scan = std::make_shared<PhysicalMockTableScan>( | ||
executor_id, | ||
schema, | ||
log->identifier(), | ||
Block(schema), | ||
mock_streams, | ||
table_scan.getLogicalTableID()); | ||
return physical_mock_table_scan; | ||
} | ||
|
||
void PhysicalMockTableScan::buildBlockInputStreamImpl(DAGPipeline & pipeline, Context & /*context*/, size_t /*max_streams*/) | ||
{ | ||
assert(pipeline.streams.empty()); | ||
pipeline.streams.insert(pipeline.streams.end(), mock_streams.begin(), mock_streams.end()); | ||
} | ||
|
||
void PhysicalMockTableScan::buildPipelineExec(PipelineExecGroupBuilder & group_builder, Context & /*context*/, size_t /*concurrency*/) | ||
{ | ||
group_builder.init(mock_streams.size()); | ||
size_t i = 0; | ||
group_builder.transform([&](auto & builder) { | ||
builder.setSourceOp(std::make_unique<BlockInputStreamSourceOp>(group_builder.exec_status, mock_streams[i++])); | ||
}); | ||
} | ||
|
||
void PhysicalMockTableScan::finalize(const Names & parent_require) | ||
{ | ||
FinalizeHelper::checkSchemaContainsParentRequire(schema, parent_require); | ||
} | ||
|
||
const Block & PhysicalMockTableScan::getSampleBlock() const | ||
{ | ||
return sample_block; | ||
} | ||
|
||
void PhysicalMockTableScan::updateStreams(Context & context) | ||
{ | ||
mock_streams.clear(); | ||
assert(context.mockStorage()->tableExistsForDeltaMerge(table_id)); | ||
mock_streams.emplace_back(context.mockStorage()->getStreamFromDeltaMerge(context, table_id, &filter_conditions)); | ||
} | ||
|
||
bool PhysicalMockTableScan::setFilterConditions(Context & context, const String & filter_executor_id, const tipb::Selection & selection) | ||
{ | ||
if (unlikely(hasFilterConditions())) | ||
{ | ||
return false; | ||
} | ||
filter_conditions = FilterConditions::filterConditionsFrom(filter_executor_id, selection); | ||
updateStreams(context); | ||
return true; | ||
} | ||
|
||
bool PhysicalMockTableScan::hasFilterConditions() const | ||
{ | ||
return filter_conditions.hasValue(); | ||
} | ||
|
||
const String & PhysicalMockTableScan::getFilterConditionsId() const | ||
{ | ||
assert(hasFilterConditions()); | ||
return filter_conditions.executor_id; | ||
} | ||
|
||
Int64 PhysicalMockTableScan::getLogicalTableID() const | ||
{ | ||
return table_id; | ||
} | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.