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

Commit

Permalink
[NSE-955] Support expression conv (#965)
Browse files Browse the repository at this point in the history
* Initial commit

* Add missing attributeSeq

* Change arrow branch [will revert at last]

* Revert "Change arrow branch [will revert at last]"

This reverts commit 2ab2a61.
  • Loading branch information
PHILO-HE authored Jun 13, 2022
1 parent a44b889 commit c9bfc3d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,26 @@ object ColumnarExpressionConverter extends Logging {
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
replaceWithColumnarExpression(
sr.searchExpr,
attributeSeq,
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
replaceWithColumnarExpression(
sr.replaceExpr,
attributeSeq,
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
expr)
case conv: Conv =>
ColumnarTernaryOperator.create(
replaceWithColumnarExpression(
conv.numExpr,
attributeSeq,
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
replaceWithColumnarExpression(
conv.fromBaseExpr,
attributeSeq,
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
replaceWithColumnarExpression(
conv.toBaseExpr,
attributeSeq,
convertBoundRefToAttrRef = convertBoundRefToAttrRef),
expr)
case u: UnaryExpression =>
Expand Down Expand Up @@ -512,6 +529,8 @@ object ColumnarExpressionConverter extends Logging {
containsSubquery(sr.srcExpr) ||
containsSubquery(sr.searchExpr) ||
containsSubquery(sr.replaceExpr)
case conv: Conv =>
conv.children.map(containsSubquery).exists(_ == true)
case expr: ScalaUDF if (expr.udfName match {
case Some(name) =>
ColumnarUDF.isSupportedUDF(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,44 @@ class ColumnarStringReplace(
}
}

class ColumnarConv(numExpr: Expression, fromBaseExpr: Expression, toBaseExpr: Expression)
extends Conv(numExpr, fromBaseExpr, toBaseExpr) with ColumnarExpression {

buildCheck

def buildCheck(): Unit = {
val supportedTypes = List(StringType)
if (supportedTypes.indexOf(numExpr.dataType) == -1) {
throw new RuntimeException(s"${numExpr.dataType}" +
s" is not supported in ColumnarConv!")
}
}

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

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (num_node, _): (TreeNode, ArrowType) =
numExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (from_node, _): (TreeNode, ArrowType) =
fromBaseExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (to_node, _): (TreeNode, ArrowType) =
toBaseExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val resultType = new ArrowType.Utf8()
(TreeBuilder.makeFunction("conv",
Lists.newArrayList(num_node, from_node, to_node), resultType), resultType)
}

}

object ColumnarTernaryOperator {

def create(src: Expression, arg1: Expression, arg2: Expression,
original: Expression): Expression = original match {
case ss: Substring =>
new ColumnarSubString(src, arg1, arg2, ss)
// Currently not supported.
case ssp: StringSplit =>
case ssp: StringSplit =>
new ColumnarStringSplitPart(src, arg1, arg2, ssp)
case st: StringTranslate =>
new ColumnarStringTranslate(src, arg1, arg2, st)
Expand All @@ -284,6 +314,8 @@ object ColumnarTernaryOperator {
new ColumnarSubstringIndex(src, arg1, arg2, substrIndex)
case _: StringReplace =>
new ColumnarStringReplace(src, arg1, arg2)
case _: Conv =>
new ColumnarConv(src, arg1, arg2)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down

0 comments on commit c9bfc3d

Please sign in to comment.