Skip to content

Commit

Permalink
add make_decimal (apache#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchengchenghh authored Mar 21, 2023
1 parent eff8a0e commit 6f5c2a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ object ExpressionMappings {
final val SCALAR_SUBQUERY = "scalar_subquery"
final val EXPLODE = "explode"
final val CHECK_OVERFLOW = "ss_check_overflow"
final val MAKE_DECIMAL = "make_decimal"
final val PROMOTE_PRECISION = "promote_precision"
final val ROW_CONSTRUCTOR = "row_constructor"

Expand Down Expand Up @@ -376,6 +377,7 @@ object ExpressionMappings {
Sig[InSet](IN_SET),
Sig[ScalarSubquery](SCALAR_SUBQUERY),
Sig[CheckOverflow](CHECK_OVERFLOW),
Sig[MakeDecimal](MAKE_DECIMAL),
Sig[PromotePrecision](PROMOTE_PRECISION),
// Decimal
Sig[UnscaledValue](UNSCALED_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,32 @@ class CheckOverflowTransformer(
}
}

class MakeDecimalTransformer(substraitExprName: String,
child: ExpressionTransformer,
original: MakeDecimal)
extends ExpressionTransformer {

override def doTransform(args: java.lang.Object): ExpressionNode = {
val childNode = child.doTransform(args)
val functionMap = args.asInstanceOf[java.util.HashMap[String, java.lang.Long]]
val functionId = ExpressionBuilder.newScalarFunction(
functionMap,
ConverterUtils.makeFuncName(
substraitExprName,
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))
val typeNode = ConverterUtils.getTypeNode(original.dataType, original.nullable)
ExpressionBuilder.makeScalarFunction(functionId, expressionNodes, typeNode)
}
}

case class Md5Transformer(substraitExprName: String, child: ExpressionTransformer, original: Md5)
extends ExpressionTransformer
with Logging {
Expand Down Expand Up @@ -196,6 +222,8 @@ object UnaryExpressionTransformer {
original match {
case c: CheckOverflow =>
new CheckOverflowTransformer(substraitExprName, child, c)
case m: MakeDecimal =>
new MakeDecimalTransformer(substraitExprName, child, m)
case p: PromotePrecision =>
new PromotePrecisionTransformer(child, p)
case extract if extract.isInstanceOf[GetDateField] || extract.isInstanceOf[GetTimeField] =>
Expand Down

0 comments on commit 6f5c2a4

Please sign in to comment.