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-8499][VL] Fix the logic of cast expression #8500

Open
wants to merge 3 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 @@ -1482,13 +1482,13 @@ abstract class ScalarFunctionsValidateSuite extends FunctionsValidateSuite {
withTempView("try_cast_table") {
withTempPath {
path =>
Seq[(String)](("123456"), ("000A1234"))
Seq[(String)](("123456"), ("000A1234"), ("1.1"), ("1a.1"))
.toDF("str")
.write
.parquet(path.getCanonicalPath)
spark.read.parquet(path.getCanonicalPath).createOrReplaceTempView("try_cast_table")
runQueryAndCompare("select try_cast(str as bigint) from try_cast_table") {
checkGlutenOperatorMatch[ProjectExecTransformer]
checkSparkOperatorMatch[ProjectExec]
}
runQueryAndCompare("select try_cast(str as double) from try_cast_table") {
checkGlutenOperatorMatch[ProjectExecTransformer]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ object ExpressionConverter extends SQLConfHelper with Logging {
case s: ScalarSubquery =>
ScalarSubqueryTransformer(substraitExprName, s)
case c: Cast =>
if (SparkShimLoader.getSparkShims.withAnsiEvalMode(c)) {
throw new GlutenNotSupportException(s"Cast expression does not support ANSI mode, $c")
}
// Add trim node, as necessary.
val newCast =
BackendsApiManager.getSparkPlanExecApiInstance.genCastWithNewChild(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ case class CastTransformer(substraitExprName: String, child: ExpressionTransform
ExpressionBuilder.makeCast(
typeNode,
child.doTransform(args),
SparkShimLoader.getSparkShims.withAnsiEvalMode(original))
SparkShimLoader.getSparkShims.withAnsiEvalMode(original) &&
!SparkShimLoader.getSparkShims.withTryEvalMode(original))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ class Spark34Shims extends SparkShims {
case s: Subtract => s.evalMode == EvalMode.TRY
case d: Divide => d.evalMode == EvalMode.TRY
case m: Multiply => m.evalMode == EvalMode.TRY
case c: Cast => c.isTryCast
case _ => false
}
}
Expand All @@ -463,6 +464,7 @@ class Spark34Shims extends SparkShims {
case s: Subtract => s.evalMode == EvalMode.ANSI
case d: Divide => d.evalMode == EvalMode.ANSI
case m: Multiply => m.evalMode == EvalMode.ANSI
case c: Cast => c.ansiEnabled
case _ => false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ class Spark35Shims extends SparkShims {
case s: Subtract => s.evalMode == EvalMode.TRY
case d: Divide => d.evalMode == EvalMode.TRY
case m: Multiply => m.evalMode == EvalMode.TRY
case c: Cast => c.isTryCast
case _ => false
}
}
Expand All @@ -488,6 +489,7 @@ class Spark35Shims extends SparkShims {
case s: Subtract => s.evalMode == EvalMode.ANSI
case d: Divide => d.evalMode == EvalMode.ANSI
case m: Multiply => m.evalMode == EvalMode.ANSI
case c: Cast => c.ansiEnabled
case _ => false
}
}
Expand Down
Loading