From 42d8c509c868fe3aca13a3e93fb86bc698560623 Mon Sep 17 00:00:00 2001 From: Gengliang Wang Date: Fri, 18 Feb 2022 23:37:50 +0800 Subject: [PATCH] [SPARK-38251][SQL] Change Cast.toString as "cast" instead of "ansi_cast" under ANSI mode ### What changes were proposed in this pull request? Change Cast.toString as "cast" instead of "ansi_cast" under ANSI mode. This is to restore the behavior before https://github.com/apache/spark/pull/27608 ### Why are the changes needed? 1. There is no such a function "ansi_cast" in Spark SQL 2. Add/Divide/.. has different behavior under ANSI mode as well, but they don't have this special string representation. 3. As we are setting up new Github job for ANSI mode, this can avoid test failures from TPCDS plan stability test suites ### Does this PR introduce _any_ user-facing change? Yes but quite minor, the string output of `Cast` under ANSI mode becomes "cast" instead of "ansi_cast" again. ### How was this patch tested? Existing UT Closes #35570 from gengliangwang/revert-SPARK-30863. Authored-by: Gengliang Wang Signed-off-by: Gengliang Wang --- .../org/apache/spark/sql/catalyst/expressions/Cast.scala | 5 +---- .../sql-tests/results/ansi/string-functions.sql.out | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala index 06a148f063201..ef054e77707ac 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala @@ -293,10 +293,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit */ def typeCheckFailureMessage: String - override def toString: String = { - val ansi = if (ansiEnabled) "ansi_" else "" - s"${ansi}cast($child as ${dataType.simpleString})" - } + override def toString: String = s"cast($child as ${dataType.simpleString})" override def checkInputDataTypes(): TypeCheckResult = { if (canCast(child.dataType, dataType)) { diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out index 4c0aa8c948334..ec7f41dcf4bff 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out @@ -928,7 +928,7 @@ select to_binary(null, cast(null as int)) struct<> -- !query output org.apache.spark.sql.AnalysisException -cannot resolve 'to_binary(NULL, CAST(NULL AS INT))' due to data type mismatch: Unsupported encoding format: Some(ansi_cast(null as int)). The format has to be a case-insensitive string literal of 'hex', 'utf-8', or 'base64'; line 1 pos 7 +cannot resolve 'to_binary(NULL, CAST(NULL AS INT))' due to data type mismatch: Unsupported encoding format: Some(cast(null as int)). The format has to be a case-insensitive string literal of 'hex', 'utf-8', or 'base64'; line 1 pos 7 -- !query