Skip to content

Commit

Permalink
refine DAGExpressionAnalyzer: `ExpressionActionsPtr & --> const Expre…
Browse files Browse the repository at this point in the history
…ssionActionsPtr &` (#4128)

ref #4118
  • Loading branch information
SeaRise authored Feb 24, 2022
1 parent 96206c2 commit 6142e6e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
28 changes: 14 additions & 14 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool isUInt8Type(const DataTypePtr & type)
String DAGExpressionAnalyzer::applyFunction(
const String & func_name,
const Names & arg_names,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const TiDB::TiDBCollatorPtr & collator)
{
String result_name = DAGExpressionAnalyzerHelper::genFuncString(func_name, arg_names, {collator});
Expand All @@ -359,7 +359,7 @@ String DAGExpressionAnalyzer::applyFunction(
}

String DAGExpressionAnalyzer::buildFilterColumn(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const std::vector<const tipb::Expr *> & conditions)
{
String filter_column_name;
Expand Down Expand Up @@ -402,7 +402,7 @@ String DAGExpressionAnalyzer::appendWhere(
return filter_column_name;
}

String DAGExpressionAnalyzer::convertToUInt8(ExpressionActionsPtr & actions, const String & column_name)
String DAGExpressionAnalyzer::convertToUInt8(const ExpressionActionsPtr & actions, const String & column_name)
{
// Some of the TiFlash operators(e.g. FilterBlockInputStream) only support UInt8 as its input, so need to convert the
// column type to UInt8
Expand Down Expand Up @@ -453,7 +453,7 @@ String DAGExpressionAnalyzer::convertToUInt8(ExpressionActionsPtr & actions, con
}

NamesAndTypes DAGExpressionAnalyzer::buildOrderColumns(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const ::google::protobuf::RepeatedPtrField<tipb::ByItem> & order_by)
{
NamesAndTypes order_columns;
Expand Down Expand Up @@ -504,14 +504,14 @@ String DAGExpressionAnalyzer::appendTimeZoneCast(
const String & tz_col,
const String & ts_col,
const String & func_name,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
String cast_expr_name = applyFunction(func_name, {ts_col, tz_col}, actions, nullptr);
return cast_expr_name;
}

bool DAGExpressionAnalyzer::buildExtraCastsAfterTS(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const std::vector<ExtraCastAfterTSMode> & need_cast_column,
const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & table_scan_columns)
{
Expand Down Expand Up @@ -577,7 +577,7 @@ String DAGExpressionAnalyzer::appendDurationCast(
const String & fsp_expr,
const String & dur_expr,
const String & func_name,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
return applyFunction(func_name, {dur_expr, fsp_expr}, actions, nullptr);
}
Expand All @@ -593,7 +593,7 @@ void DAGExpressionAnalyzer::appendJoin(
}

std::pair<bool, Names> DAGExpressionAnalyzer::buildJoinKey(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const google::protobuf::RepeatedPtrField<tipb::Expr> & keys,
const DataTypes & key_types,
bool left,
Expand Down Expand Up @@ -877,7 +877,7 @@ NamesWithAliases DAGExpressionAnalyzer::appendFinalProjectForRootQueryBlock(

String DAGExpressionAnalyzer::alignReturnType(
const tipb::Expr & expr,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & expr_name,
bool force_uint8)
{
Expand Down Expand Up @@ -910,7 +910,7 @@ void DAGExpressionAnalyzer::initChain(ExpressionActionsChain & chain, const std:
}
}

String DAGExpressionAnalyzer::appendCast(const DataTypePtr & target_type, ExpressionActionsPtr & actions, const String & expr_name)
String DAGExpressionAnalyzer::appendCast(const DataTypePtr & target_type, const ExpressionActionsPtr & actions, const String & expr_name)
{
// need to add cast function
// first construct the second argument
Expand All @@ -922,7 +922,7 @@ String DAGExpressionAnalyzer::appendCast(const DataTypePtr & target_type, Expres

String DAGExpressionAnalyzer::appendCastIfNeeded(
const tipb::Expr & expr,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & expr_name)
{
if (!isFunctionExpr(expr))
Expand Down Expand Up @@ -965,7 +965,7 @@ void DAGExpressionAnalyzer::makeExplicitSet(
prepared_sets[&expr] = std::make_shared<DAGSet>(std::move(set), std::move(remaining_exprs));
}

String DAGExpressionAnalyzer::getActions(const tipb::Expr & expr, ExpressionActionsPtr & actions, bool output_as_uint8_type)
String DAGExpressionAnalyzer::getActions(const tipb::Expr & expr, const ExpressionActionsPtr & actions, bool output_as_uint8_type)
{
String ret;
if (isLiteralExpr(expr))
Expand Down Expand Up @@ -1022,7 +1022,7 @@ String DAGExpressionAnalyzer::buildTupleFunctionForGroupConcat(
SortDescription & sort_desc,
NamesAndTypes & names_and_types,
TiDB::TiDBCollators & collators,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = "tuple";
Names argument_names;
Expand Down Expand Up @@ -1062,7 +1062,7 @@ String DAGExpressionAnalyzer::buildTupleFunctionForGroupConcat(

String DAGExpressionAnalyzer::buildFunction(
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = getFunctionName(expr);
Names argument_names;
Expand Down
28 changes: 14 additions & 14 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable

String getActions(
const tipb::Expr & expr,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
bool output_as_uint8_type = false);

// appendExtraCastsAfterTS will append extra casts after tablescan if needed.
Expand Down Expand Up @@ -115,7 +115,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable

private:
NamesAndTypes buildOrderColumns(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const ::google::protobuf::RepeatedPtrField<tipb::ByItem> & order_by);

void appendCastAfterAgg(
Expand All @@ -127,7 +127,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable
SortDescription & sort_desc,
NamesAndTypes & names_and_types,
TiDB::TiDBCollators & collators,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

void buildGroupConcat(
const tipb::Expr & expr,
Expand All @@ -153,12 +153,12 @@ class DAGExpressionAnalyzer : private boost::noncopyable

String appendCast(
const DataTypePtr & target_type,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & expr_name);

String appendCastIfNeeded(
const tipb::Expr & expr,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & expr_name);

/**
Expand All @@ -172,17 +172,17 @@ class DAGExpressionAnalyzer : private boost::noncopyable
*/
String alignReturnType(
const tipb::Expr & expr,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & expr_name,
bool force_uint8);

bool buildExtraCastsAfterTS(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const std::vector<ExtraCastAfterTSMode> & need_cast_column,
const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & table_scan_columns);

std::pair<bool, Names> buildJoinKey(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const google::protobuf::RepeatedPtrField<tipb::Expr> & keys,
const DataTypes & key_types,
bool left,
Expand All @@ -191,31 +191,31 @@ class DAGExpressionAnalyzer : private boost::noncopyable
String applyFunction(
const String & func_name,
const Names & arg_names,
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const TiDB::TiDBCollatorPtr & collator);

String appendTimeZoneCast(
const String & tz_col,
const String & ts_col,
const String & func_name,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

String appendDurationCast(
const String & fsp_expr,
const String & dur_expr,
const String & func_name,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

String convertToUInt8(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const String & column_name);

String buildFunction(
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

String buildFilterColumn(
ExpressionActionsPtr & actions,
const ExpressionActionsPtr & actions,
const std::vector<const tipb::Expr *> & conditions);

// all columns from table scan
Expand Down
20 changes: 10 additions & 10 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ String DAGExpressionAnalyzerHelper::genFuncString(
String DAGExpressionAnalyzerHelper::buildMultiIfFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
// multiIf is special because
// 1. the type of odd argument(except the last one) must be UInt8
Expand All @@ -102,7 +102,7 @@ String DAGExpressionAnalyzerHelper::buildMultiIfFunction(
String DAGExpressionAnalyzerHelper::buildIfNullFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
// rewrite IFNULL function with multiIf
// ifNull(arg1, arg2) -> multiIf(isNull(arg1), arg2, arg1)
Expand All @@ -129,7 +129,7 @@ String DAGExpressionAnalyzerHelper::buildIfNullFunction(
String DAGExpressionAnalyzerHelper::buildInFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = getFunctionName(expr);
Names argument_names;
Expand Down Expand Up @@ -200,7 +200,7 @@ String DAGExpressionAnalyzerHelper::buildInFunction(
String DAGExpressionAnalyzerHelper::buildLogicalFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = getFunctionName(expr);
Names argument_names;
Expand All @@ -216,7 +216,7 @@ String DAGExpressionAnalyzerHelper::buildLogicalFunction(
String DAGExpressionAnalyzerHelper::buildLeftUTF8Function(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = "substringUTF8";
Names argument_names;
Expand All @@ -242,7 +242,7 @@ String DAGExpressionAnalyzerHelper::buildCastFunctionInternal(
const Names & argument_names,
bool in_union,
const tipb::FieldType & field_type,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
static const String tidb_cast_name = "tidb_cast";

Expand All @@ -264,7 +264,7 @@ String DAGExpressionAnalyzerHelper::buildCastFunctionInternal(
String DAGExpressionAnalyzerHelper::buildCastFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
if (expr.children_size() != 1)
throw TiFlashException("Cast function only support one argument", Errors::Coprocessor::BadRequest);
Expand All @@ -285,7 +285,7 @@ template <typename Impl>
String DAGExpressionAnalyzerHelper::buildDateAddOrSubFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
if (expr.children_size() != 3)
{
Expand Down Expand Up @@ -329,7 +329,7 @@ String DAGExpressionAnalyzerHelper::buildDateAddOrSubFunction(
String DAGExpressionAnalyzerHelper::buildBitwiseFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
const String & func_name = getFunctionName(expr);
Names argument_names;
Expand Down Expand Up @@ -362,7 +362,7 @@ String DAGExpressionAnalyzerHelper::buildBitwiseFunction(
String DAGExpressionAnalyzerHelper::buildRoundFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions)
const ExpressionActionsPtr & actions)
{
// ROUND(x) -> ROUND(x, 0)
if (expr.children_size() != 1)
Expand Down
22 changes: 11 additions & 11 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,62 @@ class DAGExpressionAnalyzerHelper
static String buildInFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildBitwiseFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildMultiIfFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildIfNullFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildLogicalFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildLeftUTF8Function(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildCastFunctionInternal(
DAGExpressionAnalyzer * analyzer,
const Names & argument_names,
bool in_union,
const tipb::FieldType & field_type,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildCastFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

template <typename Impl>
static String buildDateAddOrSubFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
const ExpressionActionsPtr & actions);

static String buildRoundFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
ExpressionActionsPtr & actions);
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 &, ExpressionActionsPtr &)>;
using FunctionBuilder = std::function<String(DAGExpressionAnalyzer *, const tipb::Expr &, const ExpressionActionsPtr &)>;
using FunctionBuilderMap = std::unordered_map<String, FunctionBuilder>;

static FunctionBuilderMap function_builder_map;
Expand Down

0 comments on commit 6142e6e

Please sign in to comment.