-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plan, executor: implement Expand operator for grouping sets (#6545)
close #6852, ref pingcap/tidb#16581, ref pingcap/tidb#34704
- Loading branch information
Showing
38 changed files
with
2,006 additions
and
47 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -53,5 +53,4 @@ Block ExpressionBlockInputStream::readImpl() | |
expression->execute(res); | ||
return res; | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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. | ||
|
||
#include <Debug/MockExecutor/AstToPBUtils.h> | ||
#include <Debug/MockExecutor/ExpandBinder.h> | ||
|
||
namespace DB::mock | ||
{ | ||
|
||
bool ExpandBinder::toTiPBExecutor(tipb::Executor * tipb_executor, int32_t collator_id, const MPPInfo & mpp_info, const Context & context) | ||
{ | ||
tipb_executor->set_tp(tipb::ExecType::TypeExpand); | ||
tipb_executor->set_executor_id(name); | ||
tipb::Expand * expand = tipb_executor->mutable_expand(); | ||
for (const auto & grouping_set : grouping_sets_columns) | ||
{ | ||
auto * gss = expand->add_grouping_sets(); | ||
for (const auto & grouping_exprs : grouping_set) | ||
{ | ||
auto * ges = gss->add_grouping_exprs(); | ||
for (const auto & grouping_col : grouping_exprs) | ||
{ | ||
tipb::Expr * add_column = ges->add_grouping_expr(); | ||
astToPB(children[0]->output_schema, grouping_col, add_column, collator_id, context); // ast column ref change to tipb:Expr column ref | ||
} | ||
} | ||
} | ||
auto * children_executor = expand->mutable_child(); | ||
return children[0]->toTiPBExecutor(children_executor, collator_id, mpp_info, context); | ||
} | ||
|
||
ExecutorBinderPtr compileExpand(ExecutorBinderPtr input, size_t & executor_index, MockVVecGroupingNameVec grouping_set_columns, std::set<String> in_set) | ||
{ | ||
DAGSchema output_schema; | ||
for (const auto & field : input->output_schema) | ||
{ | ||
// if the column is in the grouping sets, make it nullable. | ||
if (in_set.find(field.first) != in_set.end() && field.second.hasNotNullFlag()) | ||
output_schema.push_back(toNullableDAGColumnInfo(field)); | ||
else | ||
output_schema.push_back(field); | ||
} | ||
{ | ||
tipb::FieldType field_type{}; | ||
field_type.set_tp(TiDB::TypeLongLong); | ||
field_type.set_charset("binary"); | ||
field_type.set_collate(TiDB::ITiDBCollator::BINARY); | ||
field_type.set_flag(TiDB::ColumnFlagUnsigned | TiDB::ColumnFlagNotNull); // should have NOT NULL FLAG | ||
field_type.set_flen(-1); | ||
field_type.set_decimal(-1); | ||
output_schema.push_back(std::make_pair("groupingID", TiDB::fieldTypeToColumnInfo(field_type))); | ||
} | ||
ExecutorBinderPtr expand = std::make_shared<ExpandBinder>(executor_index, output_schema, std::move(grouping_set_columns)); | ||
expand->children.push_back(input); | ||
return expand; | ||
} | ||
} // namespace DB::mock |
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,43 @@ | ||
// 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 <Debug/MockExecutor/ExecutorBinder.h> | ||
|
||
namespace DB::mock | ||
{ | ||
using MockGroupingNameVec = std::vector<ASTPtr>; | ||
using MockVecGroupingNameVec = std::vector<MockGroupingNameVec>; | ||
using MockVVecGroupingNameVec = std::vector<MockVecGroupingNameVec>; | ||
|
||
class ExpandBinder : public ExecutorBinder | ||
{ | ||
public: | ||
ExpandBinder(size_t & index_, const DAGSchema & output_schema_, MockVVecGroupingNameVec gss) | ||
: ExecutorBinder(index_, "expand_" + std::to_string(index_), output_schema_) | ||
, grouping_sets_columns(gss) | ||
{} | ||
|
||
bool toTiPBExecutor(tipb::Executor * tipb_executor, int32_t collator_id, const MPPInfo & mpp_info, const Context & context) override; | ||
|
||
void columnPrune(std::unordered_set<String> &) override { throw Exception("Should not reach here"); } | ||
|
||
private: | ||
// for now, every grouping set is base columns list, modify structure to be one more nested if grouping set merge is enabled. | ||
MockVVecGroupingNameVec grouping_sets_columns; | ||
}; | ||
|
||
ExecutorBinderPtr compileExpand(ExecutorBinderPtr input, size_t & executor_index, MockVVecGroupingNameVec grouping_set_columns, std::set<String> set); | ||
} // namespace DB::mock |
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
Oops, something went wrong.