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
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion arrow-data-source/script/build_arrow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ echo "ARROW_SOURCE_DIR=${ARROW_SOURCE_DIR}"
echo "ARROW_INSTALL_DIR=${ARROW_INSTALL_DIR}"
mkdir -p $ARROW_SOURCE_DIR
mkdir -p $ARROW_INSTALL_DIR
git clone https://github.com/oap-project/arrow.git --branch arrow-4.0.0-oap $ARROW_SOURCE_DIR
git clone https://github.com/philo-he/arrow.git --branch floor $ARROW_SOURCE_DIR
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reverted it at latest commit. Thanks!

pushd $ARROW_SOURCE_DIR

cmake ./cpp \
Expand Down
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