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

[NSE-955] Support expression conv #965

Merged
merged 4 commits into from
Jun 13, 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 @@ -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