Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-7475][VL] fix: remove unnecessary trim function in CAST, cuz velox does it #7476

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -706,50 +706,6 @@ class VeloxSparkPlanExecApi extends SparkPlanExecApi {
VeloxGetStructFieldTransformer(substraitExprName, childTransformer, ordinal, original)
}

/**
* To align with spark in casting string type input to other types, add trim node for trimming
* space or whitespace. See spark's Cast.scala.
*/
override def genCastWithNewChild(c: Cast): Cast = {
// scalastyle:off nonascii
// Common whitespace to be trimmed, including: ' ', '\n', '\r', '\f', etc.
val trimWhitespaceStr = " \t\n\u000B\u000C\u000D\u001C\u001D\u001E\u001F"
// Space separator.
val trimSpaceSepStr = "\u1680\u2008\u2009\u200A\u205F\u3000" +
('\u2000' to '\u2006').toList.mkString
// Line separator.
val trimLineSepStr = "\u2028"
// Paragraph separator.
val trimParaSepStr = "\u2029"
// Needs to be trimmed for casting to float/double/decimal
val trimSpaceStr = ('\u0000' to '\u0020').toList.mkString
// scalastyle:on nonascii
c.dataType match {
case BinaryType | _: ArrayType | _: MapType | _: StructType | _: UserDefinedType[_] =>
c
case FloatType | DoubleType | _: DecimalType =>
c.child.dataType match {
case StringType =>
val trimNode = StringTrim(c.child, Some(Literal(trimSpaceStr)))
c.withNewChildren(Seq(trimNode)).asInstanceOf[Cast]
case _ =>
c
}
case _ =>
c.child.dataType match {
case StringType =>
val trimNode = StringTrim(
c.child,
Some(
Literal(trimWhitespaceStr +
trimSpaceSepStr + trimLineSepStr + trimParaSepStr)))
c.withNewChildren(Seq(trimNode)).asInstanceOf[Cast]
case _ =>
c
}
}
}

/** Define backend specfic expression mappings. */
override def extraExpressionMappings: Seq[Sig] = {
Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,6 @@ trait SparkPlanExecApi {
startDate: ExpressionTransformer,
original: DateDiff): ExpressionTransformer

def genCastWithNewChild(c: Cast): Cast = c

def genHashExpressionTransformer(
substraitExprName: String,
exprs: Seq[ExpressionTransformer],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,10 @@ object ExpressionConverter extends SQLConfHelper with Logging {
case s: ScalarSubquery =>
ScalarSubqueryTransformer(substraitExprName, s)
case c: Cast =>
// Add trim node, as necessary.
val newCast =
BackendsApiManager.getSparkPlanExecApiInstance.genCastWithNewChild(c)
CastTransformer(
substraitExprName,
replaceWithExpressionTransformer0(newCast.child, attributeSeq, expressionsMap),
newCast)
replaceWithExpressionTransformer0(c.child, attributeSeq, expressionsMap),
c)
case s: String2TrimExpression =>
val (srcStr, trimStr) = s match {
case StringTrim(srcStr, trimStr) => (srcStr, trimStr)
Expand Down
Loading