Skip to content

Commit

Permalink
Integrate with Velox make_decimal function
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Nov 21, 2023
1 parent 0d4e43c commit 390dba0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,10 @@ SerializedPlanParser::getFunctionName(const std::string & function_signature, co
}
else if (function_name == "make_decimal")
{
if (args.size() < 3)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "make_decimal function requires at least 3 args.");
if (args.size() < 2)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "make_decimal function requires at least 2 args.");
ch_function_name = SCALAR_FUNCTIONS.at(function_name);
auto null_on_overflow = args.at(2).value().literal().boolean();
auto null_on_overflow = args.at(1).value().literal().boolean();
if (null_on_overflow)
ch_function_name = ch_function_name + "OrNull";
}
Expand Down
1 change: 0 additions & 1 deletion cpp/velox/substrait/SubstraitParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ std::unordered_map<std::string, std::string> SubstraitParser::substraitVeloxFunc
{"bit_and_merge", "bitwise_and_agg_merge"},
{"collect_set", "array_distinct"},
{"murmur3hash", "hash_with_seed"},
{"make_decimal", "make_decimal_by_unscaled_value"},
{"modulus", "mod"} /*Presto functions.*/
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,8 @@ case class MakeDecimalTransformer(
Seq(original.dataType, BooleanType),
FunctionConfig.OPT))

// use fake decimal literal, because velox function signature need to get return type
// scale and precision by input type variable
val toTypeNodes =
ExpressionBuilder.makeDecimalLiteral(new Decimal().set(0, original.precision, original.scale))
val expressionNodes =
Lists.newArrayList(childNode, toTypeNodes, new BooleanLiteralNode(original.nullOnOverflow))
Lists.newArrayList(childNode, new BooleanLiteralNode(original.nullOnOverflow))
val typeNode = ConverterUtils.getTypeNode(original.dataType, original.nullable)
ExpressionBuilder.makeScalarFunction(functionId, expressionNodes, typeNode)
}
Expand Down

0 comments on commit 390dba0

Please sign in to comment.