Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ String DAGExpressionAnalyzerHelper::buildIfNullFunction(
return analyzer->applyFunction(func_name, argument_names, actions, getCollatorFromExpr(expr));
}

String DAGExpressionAnalyzerHelper::buildNullEqFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
const ExpressionActionsPtr & actions)
{
if (expr.children_size() != 2)
{
throw TiFlashException("Invalid arguments of nullEq function", Errors::Coprocessor::BadRequest);
}

String col1 = analyzer->getActions(expr.children(0), actions, false);
String col2 = analyzer->getActions(expr.children(1), actions, false);

const Block & sample_block = actions->getSampleBlock();
bool col1_nullable = sample_block.getByName(col1).type->isNullable();
bool col2_nullable = sample_block.getByName(col2).type->isNullable();

if (!col1_nullable && !col2_nullable)
{
return analyzer->applyFunction("equals", {col1, col2}, actions, getCollatorFromExpr(expr));
}

String equals = analyzer->applyFunction("equals", {col1, col2}, actions, getCollatorFromExpr(expr));
String name = analyzer->getActions(constructInt64LiteralTiExpr(0), actions);

String is_null_col1 = analyzer->applyFunction("isNull", {col1}, actions, getCollatorFromExpr(expr));
String is_null_col2 = analyzer->applyFunction("isNull", {col2}, actions, getCollatorFromExpr(expr));
String and_is_null = analyzer->applyFunction("and", {is_null_col1, is_null_col2}, actions, nullptr);
String not_null_equals = analyzer->applyFunction("coalesce", {equals, name}, actions, nullptr);

return analyzer->applyFunction("or", {and_is_null, not_null_equals}, actions, nullptr);
}

String DAGExpressionAnalyzerHelper::buildInFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
Expand Down Expand Up @@ -547,6 +580,7 @@ DAGExpressionAnalyzerHelper::FunctionBuilderMap DAGExpressionAnalyzerHelper::fun
{"tidbIn", DAGExpressionAnalyzerHelper::buildInFunction},
{"tidbNotIn", DAGExpressionAnalyzerHelper::buildInFunction},
{"ifNull", DAGExpressionAnalyzerHelper::buildIfNullFunction},
{"nullEq", DAGExpressionAnalyzerHelper::buildNullEqFunction},
{"multiIf", DAGExpressionAnalyzerHelper::buildMultiIfFunction},
{"tidb_cast", DAGExpressionAnalyzerHelper::buildCastFunction},
{"cast_int_as_json", DAGExpressionAnalyzerHelper::buildSingleParamJsonRelatedFunctions},
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class DAGExpressionAnalyzerHelper
const tipb::Expr & expr,
const ExpressionActionsPtr & actions);

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

static String buildLogicalFunction(
DAGExpressionAnalyzer * analyzer,
const tipb::Expr & expr,
Expand Down
13 changes: 6 additions & 7 deletions dbms/src/Flash/Coprocessor/DAGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,12 @@ const std::unordered_map<tipb::ScalarFuncSig, String> scalar_func_map({
//{tipb::ScalarFuncSig::NEJson, "notEquals"},
{tipb::ScalarFuncSig::NEVectorFloat32, "notEquals"},

//{tipb::ScalarFuncSig::NullEQInt, "cast"},
//{tipb::ScalarFuncSig::NullEQReal, "cast"},
//{tipb::ScalarFuncSig::NullEQString, "cast"},
//{tipb::ScalarFuncSig::NullEQDecimal, "cast"},
//{tipb::ScalarFuncSig::NullEQTime, "cast"},
//{tipb::ScalarFuncSig::NullEQDuration, "cast"},
//{tipb::ScalarFuncSig::NullEQJson, "cast"},
{tipb::ScalarFuncSig::NullEQInt, "nullEq"},
{tipb::ScalarFuncSig::NullEQReal, "nullEq"},
{tipb::ScalarFuncSig::NullEQString, "nullEq"},
{tipb::ScalarFuncSig::NullEQDecimal, "nullEq"},
{tipb::ScalarFuncSig::NullEQTime, "nullEq"},
{tipb::ScalarFuncSig::NullEQDuration, "nullEq"},

{tipb::ScalarFuncSig::PlusReal, "plus"},
{tipb::ScalarFuncSig::PlusDecimal, "plus"},
Expand Down
Loading