Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-681] Add floor & ceil expression support #682

Merged
merged 4 commits into from
Jan 7, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,62 @@ class ColumnarAbs(child: Expression, original: Expression)
}
}

class ColumnarFloor(child: Expression, original: Expression)
extends Floor(child: Expression)
with ColumnarExpression
with Logging {

buildCheck()

def buildCheck(): Unit = {
// Currently, decimal type is not supported.
val supportedTypes = List(DoubleType, LongType)
if (supportedTypes.indexOf(child.dataType) == -1 &&
!child.dataType.isInstanceOf[DecimalType]) {
throw new UnsupportedOperationException(
s"${child.dataType} is not supported in ColumnarFloor")
}
}

override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = {
val (child_node, _): (TreeNode, ArrowType) =
child.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)

val resultType = CodeGeneration.getResultType(dataType)
val funcNode =
TreeBuilder.makeFunction("floor", Lists.newArrayList(child_node), resultType)
(funcNode, resultType)
}
}

class ColumnarCeil(child: Expression, original: Expression)
extends Ceil(child: Expression)
with ColumnarExpression
with Logging {

buildCheck()

def buildCheck(): Unit = {
// Currently, decimal type is not supported.
val supportedTypes = List(DoubleType, LongType)
if (supportedTypes.indexOf(child.dataType) == -1 &&
!child.dataType.isInstanceOf[DecimalType]) {
throw new UnsupportedOperationException(
s"${child.dataType} is not supported in ColumnarCeil")
}
}

override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = {
val (child_node, _): (TreeNode, ArrowType) =
child.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)

val resultType = CodeGeneration.getResultType(dataType)
val funcNode =
TreeBuilder.makeFunction("ceil", Lists.newArrayList(child_node), resultType)
(funcNode, resultType)
}
}

class ColumnarUpper(child: Expression, original: Expression)
extends Upper(child: Expression)
with ColumnarExpression
Expand Down Expand Up @@ -822,6 +878,10 @@ object ColumnarUnaryOperator {
new ColumnarNot(child, n)
case a: Abs =>
new ColumnarAbs(child, a)
case f: Floor =>
new ColumnarFloor(child, f)
case c: Ceil =>
new ColumnarCeil(child, c)
case u: Upper =>
new ColumnarUpper(child, u)
case c: Cast =>
Expand Down