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

[NSE-867] Add substring_index function support #868

Merged
merged 5 commits into from
Apr 24, 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 @@ -422,6 +422,8 @@ object ColumnarExpressionConverter extends Logging {
case regexp: RegExpReplace =>
containsSubquery(regexp.subject) || containsSubquery(
regexp.regexp) || containsSubquery(regexp.rep) || containsSubquery(regexp.pos)
case substrIndex: ColumnarSubstringIndex =>
substrIndex.children.map(containsSubquery).exists(_ == true)
case expr =>
throw new UnsupportedOperationException(
s" --> ${expr.getClass} | ${expr} is not currently supported.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,27 @@ class ColumnarRegExpExtract(subject: Expression, regexp: Expression, idx: Expres
}
}

class ColumnarSubstringIndex(strExpr: Expression, delimExpr: Expression,
countExpr: Expression, original: Expression)
extends SubstringIndex(strExpr, delimExpr, countExpr) with ColumnarExpression {

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

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (str_node, _): (TreeNode, ArrowType) =
strExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (delim_node, _): (TreeNode, ArrowType) =
delimExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val (count_node, _): (TreeNode, ArrowType) =
countExpr.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val resultType = new ArrowType.Utf8()
(TreeBuilder.makeFunction("substr_index",
Lists.newArrayList(str_node, delim_node, count_node), resultType), resultType)
}
}

object ColumnarTernaryOperator {

def create(src: Expression, arg1: Expression, arg2: Expression,
Expand All @@ -217,6 +238,8 @@ object ColumnarTernaryOperator {
new ColumnarStringLocate(src, arg1, arg2, sl)
case re: RegExpExtract =>
new ColumnarRegExpExtract(src, arg1, arg2, re)
case substrIndex: SubstringIndex =>
new ColumnarSubstringIndex(src, arg1, arg2, substrIndex)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down