Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine appendAggregation in analyzer #4042

Merged
merged 30 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7a092c3
move constructTZExpr and isUInt8Type to helper
SeaRise Feb 16, 2022
7f2d72c
refine
SeaRise Feb 16, 2022
8ab268b
fix clang-warning
SeaRise Feb 16, 2022
f16d25e
revert
SeaRise Feb 16, 2022
1f46431
revert
SeaRise Feb 16, 2022
4ece31e
update
SeaRise Feb 17, 2022
1732e1b
fix
SeaRise Feb 17, 2022
82184c1
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 18, 2022
d8a57b5
address comments
SeaRise Feb 18, 2022
9153890
fix
SeaRise Feb 18, 2022
36cccbd
fix clang
SeaRise Feb 18, 2022
467ee87
update
SeaRise Feb 18, 2022
784ad52
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 18, 2022
4a8adbd
fix
SeaRise Feb 18, 2022
9a15475
remove useless comment
SeaRise Feb 18, 2022
9f6ba8f
address comment
SeaRise Feb 19, 2022
731615e
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 19, 2022
ce1fbeb
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 24, 2022
d4a9143
address comments
SeaRise Feb 24, 2022
abc1cdd
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 28, 2022
e46a3ef
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Feb 28, 2022
918ebf1
address comments
SeaRise Feb 28, 2022
5e6ebe0
update
SeaRise Feb 28, 2022
df36b0f
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Mar 3, 2022
e9f76ca
adddress comments
SeaRise Mar 3, 2022
94e28c8
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Mar 4, 2022
e500019
address comments
SeaRise Mar 4, 2022
d583a8a
Merge branch 'master' into refine_analyzer_for_planner
SeaRise Mar 7, 2022
7bd8152
update
SeaRise Mar 7, 2022
a2b7f83
Merge branch 'master' into refine_analyzer_for_planner
ti-chi-bot Mar 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 221 additions & 186 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable
const tipb::TopN & topN);

/// <aggregation_keys, collators, aggregate_descriptions, before_agg>
/// May change the source columns.
std::tuple<Names, TiDB::TiDBCollators, AggregateDescriptions, ExpressionActionsPtr> appendAggregation(
ExpressionActionsChain & chain,
const tipb::Aggregation & agg,
Expand All @@ -62,6 +63,8 @@ class DAGExpressionAnalyzer : private boost::noncopyable
ExpressionActionsChain & chain,
const std::vector<NameAndTypePair> & columns) const;

ExpressionActionsChain::Step & initAndGetLastStep(ExpressionActionsChain & chain) const;

void appendJoin(
ExpressionActionsChain & chain,
SubqueryForSet & join_query,
Expand Down Expand Up @@ -119,7 +122,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable
const ::google::protobuf::RepeatedPtrField<tipb::ByItem> & order_by);

void appendCastAfterAgg(
ExpressionActionsChain & chain,
const ExpressionActionsPtr & actions,
const tipb::Aggregation & agg);

String buildTupleFunctionForGroupConcat(
Expand All @@ -131,20 +134,43 @@ class DAGExpressionAnalyzer : private boost::noncopyable

void buildGroupConcat(
const tipb::Expr & expr,
ExpressionActionsChain::Step & step,
const ExpressionActionsPtr & actions,
const String & agg_func_name,
AggregateDescriptions & aggregate_descriptions,
NamesAndTypes & aggregated_columns,
bool result_is_nullable);

void buildCommonAggFunc(
const tipb::Expr & expr,
ExpressionActionsChain::Step & step,
const ExpressionActionsPtr & actions,
const String & agg_func_name,
AggregateDescriptions & aggregate_descriptions,
NamesAndTypes & aggregated_columns,
bool empty_input_as_null);

void buildAggFuncs(
const tipb::Aggregation & aggregation,
const ExpressionActionsPtr & actions,
AggregateDescriptions & aggregate_descriptions,
NamesAndTypes & aggregated_columns);

void buildAggGroupBy(
const google::protobuf::RepeatedPtrField<tipb::Expr> & group_by,
const ExpressionActionsPtr & actions,
AggregateDescriptions & aggregate_descriptions,
NamesAndTypes & aggregated_columns,
Names & aggregation_keys,
std::unordered_set<String> & agg_key_set,
bool group_by_collation_sensitive,
TiDB::TiDBCollators & collators);

void fillAggArgumentDetail(
const ExpressionActionsPtr & actions,
const tipb::Expr & arg,
Names & arg_names,
DataTypes & arg_types,
TiDB::TiDBCollators & arg_collators);

void makeExplicitSet(
const tipb::Expr & expr,
const Block & sample_block,
Expand Down
21 changes: 2 additions & 19 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <Columns/ColumnSet.h>
#include <Common/FmtUtils.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeSet.h>
#include <DataTypes/getLeastSupertype.h>
#include <Flash/Coprocessor/DAGExpressionAnalyzer.h>
#include <Flash/Coprocessor/DAGExpressionAnalyzerHelper.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionsTiDBConversion.h>
#include <Storages/Transaction/TypeMapping.h>
Expand Down Expand Up @@ -56,25 +58,6 @@ const std::unordered_map<String, String> DateSub::unit_to_func_name_map
{"SECOND", "subtractSeconds"}};
} // namespace

String DAGExpressionAnalyzerHelper::genFuncString(
const String & func_name,
const Names & argument_names,
const TiDB::TiDBCollators & collators)
{
assert(!collators.empty());
FmtBuffer buf;
buf.fmtAppend("{}({})_collator", func_name, fmt::join(argument_names.begin(), argument_names.end(), ", "));
for (const auto & collator : collators)
{
if (collator == nullptr)
buf.append("_0");
else
buf.fmtAppend("_{}", collator->getCollatorId());
}
buf.append(" ");
return buf.toString();
}

String DAGExpressionAnalyzerHelper::buildMultiIfFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
Expand Down
5 changes: 0 additions & 5 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class DAGExpressionAnalyzerHelper
const tipb::Expr & expr,
const ExpressionActionsPtr & actions);

static String genFuncString(
const String & func_name,
const Names & argument_names,
const TiDB::TiDBCollators & collators);

using FunctionBuilder = std::function<String(DAGExpressionAnalyzer *, const tipb::Expr &, const ExpressionActionsPtr &)>;
using FunctionBuilderMap = std::unordered_map<String, FunctionBuilder>;

Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Flash/Coprocessor/DAGQueryBlockInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,7 @@ void DAGQueryBlockInterpreter::handleProjection(DAGPipeline & pipeline, const ti
input_columns.emplace_back(p.name, p.type);
DAGExpressionAnalyzer dag_analyzer(std::move(input_columns), context);
ExpressionActionsChain chain;
dag_analyzer.initChain(chain, dag_analyzer.getCurrentInputColumns());
ExpressionActionsChain::Step & last_step = chain.steps.back();
auto & last_step = dag_analyzer.initAndGetLastStep(chain);
std::vector<NameAndTypePair> output_columns;
NamesWithAliases project_cols;
UniqueNameGenerator unique_name_generator;
Expand Down
19 changes: 19 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,25 @@ SortDescription getSortDescription(const std::vector<NameAndTypePair> & order_co
return order_descr;
}

String genFuncString(
const String & func_name,
const Names & argument_names,
const TiDB::TiDBCollators & collators)
{
assert(!collators.empty());
FmtBuffer buf;
buf.fmtAppend("{}({})_collator", func_name, fmt::join(argument_names.begin(), argument_names.end(), ", "));
for (const auto & collator : collators)
{
if (collator)
buf.fmtAppend("_{}", collator->getCollatorId());
else
buf.append("_0");
}
buf.append(" ");
return buf.toString();
}

TiDB::TiDBCollatorPtr getCollatorFromFieldType(const tipb::FieldType & field_type)
{
if (field_type.collate() < 0)
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ DataTypePtr inferDataType4Literal(const tipb::Expr & expr);
SortDescription getSortDescription(
const std::vector<NameAndTypePair> & order_columns,
const google::protobuf::RepeatedPtrField<tipb::ByItem> & by_items);
String genFuncString(
const String & func_name,
const Names & argument_names,
const TiDB::TiDBCollators & collators);

extern const Int8 VAR_SIZE;

Expand Down