coderfender commented on code in PR #3083:
URL: https://github.com/apache/datafusion-comet/pull/3083#discussion_r2756997102
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -1342,28 +1357,32 @@ class CometCastSuite extends CometTestBase with
AdaptiveSparkPlanHelper {
input: DataFrame,
toType: DataType,
hasIncompatibleType: Boolean = false,
- testAnsi: Boolean = true): Unit = {
+ testAnsi: Boolean = true,
+ testTry: Boolean = true): Unit = {
withTempPath { dir =>
val data = roundtripParquet(input, dir).coalesce(1)
- data.createOrReplaceTempView("t")
withSQLConf((SQLConf.ANSI_ENABLED.key, "false")) {
// cast() should return null for invalid inputs when ansi mode is
disabled
- val df = spark.sql(s"select a, cast(a as ${toType.sql}) from t order
by a")
+ val df = data.select(col("a"), col("a").cast(toType)).orderBy(col("a"))
if (hasIncompatibleType) {
checkSparkAnswer(df)
} else {
checkSparkAnswerAndOperator(df)
}
- // try_cast() should always return null for invalid inputs
- val df2 =
- spark.sql(s"select a, try_cast(a as ${toType.sql}) from t order by
a")
- if (hasIncompatibleType) {
- checkSparkAnswer(df2)
- } else {
- checkSparkAnswerAndOperator(df2)
+ if (testTry) {
+ data.createOrReplaceTempView("t")
+ // try_cast() should always return null for invalid inputs
+// not using spark DSL since it `try_cast` is only available from
Spark 4x
Review Comment:
True.That is the `SQL` version of it. DSL version of it got
[added](https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/Column.html#try_cast(to:org.apache.spark.sql.types.DataType):org.apache.spark.sql.Column)
in v4.0.0 . I initially tried to convert all SQL statements to DSL but had to
hold back on updating `try_cast` DSL from SQL given that it is only available
starting v.4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]