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

[NSE-955] Support bin function #1049

Merged
merged 6 commits into from
Jul 28, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ class ColumnarPow(left: Expression, right: Expression, original: Pow) extends Po
}
}

class ColumnarFindInSet(left: Expression, right: Expression, original: Expression)
extends FindInSet(left: Expression, right: Expression) with ColumnarExpression with Logging {

override def supportColumnarCodegen(args: Object): Boolean = {
false
}

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (leftNode, _): (TreeNode, ArrowType) =
left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (rightNode, _): (TreeNode, ArrowType) =
right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)

val resultType = new ArrowType.Int(32, true)
val funcNode = TreeBuilder.makeFunction("find_in_set",
Lists.newArrayList(leftNode, rightNode), resultType)
(funcNode, resultType)
}
}

object ColumnarBinaryExpression {

def create(left: Expression, right: Expression, original: Expression): Expression =
Expand All @@ -154,13 +174,14 @@ object ColumnarBinaryExpression {
new ColumnarFromUnixTime(left, right)
case d: DateSub =>
new ColumnarDateSub(left, right)
//TODO(): the current impl has poor perf
case g: GetJsonObject =>
case g: GetJsonObject =>
new ColumnarGetJsonObject(left, right, g)
case instr: StringInstr =>
new ColumnarStringInstr(left, right, instr)
case pow: Pow =>
new ColumnarPow(left, right, pow)
case f: FindInSet =>
new ColumnarFindInSet(left, right, f)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,26 +524,6 @@ class ColumnarShiftRight(left: Expression, right: Expression, original: Expressi
}
}

class ColumnarFindInSet(left: Expression, right: Expression, original: Expression)
extends FindInSet(left: Expression, right: Expression) with ColumnarExpression with Logging {

override def supportColumnarCodegen(args: Object): Boolean = {
false
}

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (leftNode, _): (TreeNode, ArrowType) =
left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (rightNode, _): (TreeNode, ArrowType) =
right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)

val resultType = new ArrowType.Int(32, true)
val funcNode = TreeBuilder.makeFunction("find_in_set",
Lists.newArrayList(leftNode, rightNode), resultType)
(funcNode, resultType)
}
}

object ColumnarBinaryOperator {

def create(left: Expression, right: Expression, original: Expression): Expression = {
Expand Down Expand Up @@ -579,8 +559,6 @@ object ColumnarBinaryOperator {
new ColumnarShiftLeft(left, right, s)
case s: ShiftRight =>
new ColumnarShiftRight(left, right, s)
case f: FindInSet =>
new ColumnarFindInSet(left, right, f)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ class ColumnarNormalizeNaNAndZero(child: Expression, original: NormalizeNaNAndZe
class ColumnarRand(child: Expression)
extends Rand(child: Expression) with ColumnarExpression with Logging {

val resultType = new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE);
var offset: Integer = _;
val resultType = new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)
var offset: Integer = _

buildCheck()

Expand All @@ -915,7 +915,7 @@ class ColumnarRand(child: Expression)

// Aligned with Spark, seed + partitionIndex will be the actual seed.
override def initializeInternal(partitionIndex: Int): Unit = {
offset = partitionIndex;
offset = partitionIndex
}

override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = {
Expand Down Expand Up @@ -981,6 +981,28 @@ class ColumnarHex(child: Expression) extends Hex(child: Expression)
}
}

class ColumnarBin(child: Expression) extends Bin(child: Expression)
with ColumnarExpression with Logging {

override def supportColumnarCodegen(args: java.lang.Object): Boolean = {
false
}

override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = {
val (child_node, _): (TreeNode, ArrowType) =
child.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val resultType = new ArrowType.Utf8()
val limitNode = TreeBuilder.makeLiteral(new java.lang.Long(64))
val castNode = TreeBuilder.makeFunction("castVARCHAR",
Lists.newArrayList(child_node, limitNode), resultType)
val fromBaseNode = TreeBuilder.makeLiteral(new java.lang.Integer(10))
val toBaseNode = TreeBuilder.makeLiteral(new java.lang.Integer(2))
val funcNode = TreeBuilder.makeFunction("conv",
Lists.newArrayList(castNode, fromBaseNode, toBaseNode), resultType)
(funcNode, resultType)
}
}

object ColumnarUnaryOperator {

def create(child: Expression, original: Expression): Expression = original match {
Expand Down Expand Up @@ -1054,6 +1076,8 @@ object ColumnarUnaryOperator {
new ColumnarLength(child)
case hex: Hex =>
new ColumnarHex(child)
case _: Bin =>
new ColumnarBin(child)
case other =>
child.dataType match {
case _: DateType => other match {
Expand Down