Skip to content

Commit

Permalink
[GLUTEN-1902] Separate the implementations for TranslateTransformer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE authored Nov 16, 2023
1 parent aab6dbe commit 6c9c81b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,15 @@ class CHSparkPlanExecApi extends SparkPlanExecApi {
CHEqualNullSafeTransformer(substraitExprName, left, right, original)
}

override def genStringTranslateTransformer(
substraitExprName: String,
srcExpr: ExpressionTransformer,
matchingExpr: ExpressionTransformer,
replaceExpr: ExpressionTransformer,
original: StringTranslate): ExpressionTransformer = {
CHStringTranslateTransformer(substraitExprName, srcExpr, matchingExpr, replaceExpr, original)
}

override def genStringLocateTransformer(
substraitExprName: String,
first: ExpressionTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,39 @@ case class CHTruncTimestampTransformer(
}
}

case class CHStringTranslateTransformer(
substraitExprName: String,
srcExpr: ExpressionTransformer,
matchingExpr: ExpressionTransformer,
replaceExpr: ExpressionTransformer,
original: StringTranslate)
extends ExpressionTransformer {

override def doTransform(args: java.lang.Object): ExpressionNode = {
// In CH, translateUTF8 requires matchingExpr and replaceExpr argument have the same length
val matchingNode = matchingExpr.doTransform(args)
val replaceNode = replaceExpr.doTransform(args)
if (
!matchingNode.isInstanceOf[StringLiteralNode] ||
!replaceNode.isInstanceOf[StringLiteralNode]
) {
throw new UnsupportedOperationException(s"$original not supported yet.")
}

val matchingLiteral = matchingNode.asInstanceOf[StringLiteralNode].getValue
val replaceLiteral = replaceNode.asInstanceOf[StringLiteralNode].getValue
if (matchingLiteral.length() != replaceLiteral.length()) {
throw new UnsupportedOperationException(s"$original not supported yet.")
}

GenericExpressionTransformer(
substraitExprName,
Seq(srcExpr, matchingExpr, replaceExpr),
original)
.doTransform(args)
}
}

case class CHStringLocateTransformer(
substraitExprName: String,
substrExpr: ExpressionTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ trait SparkPlanExecApi {
GenericExpressionTransformer(substraitExprName, Seq(child), original)
}

def genStringTranslateTransformer(
substraitExprName: String,
srcExpr: ExpressionTransformer,
matchingExpr: ExpressionTransformer,
replaceExpr: ExpressionTransformer,
original: StringTranslate): ExpressionTransformer = {
GenericExpressionTransformer(
substraitExprName,
Seq(srcExpr, matchingExpr, replaceExpr),
original)
}

def genStringLocateTransformer(
substraitExprName: String,
first: ExpressionTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ object ExpressionConverter extends SQLConfHelper with Logging {
getStructField.ordinal,
getStructField)
case t: StringTranslate =>
StringTranslateTransformer(
BackendsApiManager.getSparkPlanExecApiInstance.genStringTranslateTransformer(
substraitExprName,
replaceWithExpressionTransformer(t.srcExpr, attributeSeq),
replaceWithExpressionTransformer(t.matchingExpr, attributeSeq),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,6 @@ case class String2TrimExpressionTransformer(
}
}

case class StringTranslateTransformer(
substraitExprName: String,
srcExpr: ExpressionTransformer,
matchingExpr: ExpressionTransformer,
replaceExpr: ExpressionTransformer,
original: StringTranslate)
extends ExpressionTransformer {

override def doTransform(args: java.lang.Object): ExpressionNode = {
// In CH, translateUTF8 requires matchingExpr and replaceExpr argument have the same length
val matchingNode = matchingExpr.doTransform(args)
val replaceNode = replaceExpr.doTransform(args)
if (
!matchingNode.isInstanceOf[StringLiteralNode] ||
!replaceNode.isInstanceOf[StringLiteralNode]
) {
throw new UnsupportedOperationException(s"$original not supported yet.")
}

val matchingLiteral = matchingNode.asInstanceOf[StringLiteralNode].getValue
val replaceLiteral = replaceNode.asInstanceOf[StringLiteralNode].getValue
if (matchingLiteral.length() != replaceLiteral.length()) {
throw new UnsupportedOperationException(s"$original not supported yet.")
}

GenericExpressionTransformer(
substraitExprName,
Seq(srcExpr, matchingExpr, replaceExpr),
original)
.doTransform(args)
}
}

case class RegExpReplaceTransformer(
substraitExprName: String,
subject: ExpressionTransformer,
Expand Down

0 comments on commit 6c9c81b

Please sign in to comment.