You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Yang Jie (Jira)" <ji...@apache.org> on 2025/07/24 18:10:00 UTC

[jira] [Commented] (SPARK-52945) Test failure related to CastSuiteBase#checkInvalidCastFromNumericType

    [ https://issues.apache.org/jira/browse/SPARK-52945?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18009666#comment-18009666 ] 

Yang Jie commented on SPARK-52945:
----------------------------------

cc [~maxgekk] FYI

> Test failure related to CastSuiteBase#checkInvalidCastFromNumericType
> ---------------------------------------------------------------------
>
>                 Key: SPARK-52945
>                 URL: https://issues.apache.org/jira/browse/SPARK-52945
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 3.4.4, 4.1.0, 3.5.6, 4.0.0
>            Reporter: Yang Jie
>            Priority: Major
>
> There is no valid assertions are present in the CastSuiteBase#checkInvalidCastFromNumericType method:
>  
>  
> {code:java}
> protected def checkInvalidCastFromNumericType(to: DataType): Unit = {
>     cast(1.toByte, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.toByte).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     cast(1.toShort, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.toShort).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     cast(1, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     cast(1L, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1L).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     cast(1.0.toFloat, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.0.toFloat).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     cast(1.0, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.0).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>   } {code}
>  
> _After applying the fix, the code is as follows:_
>  
> {code:java}
> protected def checkInvalidCastFromNumericType(to: DataType): Unit = {
>     assert(cast(1.toByte, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.toByte).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>     assert(cast(1.toShort, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.toShort).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>     assert(cast(1, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>     assert(cast(1L, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1L).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>     assert(cast(1.0.toFloat, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.0.toFloat).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>     assert(cast(1.0, to).checkInputDataTypes() ==
>       DataTypeMismatch(
>         errorSubClass = "CAST_WITH_FUNC_SUGGESTION",
>         messageParameters = Map(
>           "srcType" -> toSQLType(Literal(1.0).dataType),
>           "targetType" -> toSQLType(to),
>           "functionNames" -> "`DATE_FROM_UNIX_DATE`"
>         )
>       )
>     )
>   } {code}
>  
> _At this point, testing the {{{}CastWithAnsiOffSuite{}}}, {{{}CastWithAnsiOnSuite{}}}, and {{TryCastSuite}} will result in failures similar to the following:_
>  
> build/sbt clean "catalyst/testOnly org.apache.spark.sql.catalyst.expressions.CastWithAnsiOffSuite"
>  
> {code:java}
> [info] - SPARK-16729 type checking for casting to date type *** FAILED *** (12 milliseconds)
> [info]   DataTypeMismatch("CAST_WITHOUT_SUGGESTION", Map("srcType" -> ""TINYINT"", "targetType" -> ""DATE"")) did not equal DataTypeMismatch("CAST_WITH_FUNC_SUGGESTION", Map("srcType" -> ""TINYINT"", "targetType" -> ""DATE"", "functionNames" -> "`DATE_FROM_UNIX_DATE`")) (CastSuiteBase.scala:549)
> [info]   Analysis:
> [info]   TypeCheckResult$DataTypeMismatch(errorSubClass: "CAST_WITH[OUT]_SUGGESTION" -> "CAST_WITH[_FUNC]_SUGGESTION", messageParameters: Map("functionNames": -> "`DATE_FROM_UNIX_DATE`"))
> [info]   org.scalatest.exceptions.TestFailedException:
> [info]   at org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
> [info]   at org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
> [info]   at org.scalatest.Assertions$.newAssertionFailedException(Assertions.scala:1231)
> [info]   at org.scalatest.Assertions$AssertionsHelper.macroAssert(Assertions.scala:1295)
> [info]   at org.apache.spark.sql.catalyst.expressions.CastSuiteBase.checkInvalidCastFromNumericType(CastSuiteBase.scala:549)
> [info]   at org.apache.spark.sql.catalyst.expressions.CastSuiteBase.$anonfun$new$97(CastSuiteBase.scala:623)
> ...
> [info] - disallow type conversions between Numeric types and Timestamp without time zone type *** FAILED *** (0 milliseconds)
> [info]   DataTypeMismatch("CAST_WITHOUT_SUGGESTION", Map("srcType" -> ""TINYINT"", "targetType" -> ""TIMESTAMP_NTZ"")) did not equal DataTypeMismatch("CAST_WITH_FUNC_SUGGESTION", Map("srcType" -> ""TINYINT"", "targetType" -> ""TIMESTAMP_NTZ"", "functionNames" -> "`DATE_FROM_UNIX_DATE`")) (CastSuiteBase.scala:549)
> [info]   Analysis:
> [info]   TypeCheckResult$DataTypeMismatch(errorSubClass: "CAST_WITH[OUT]_SUGGESTION" -> "CAST_WITH[_FUNC]_SUGGESTION", messageParameters: Map("functionNames": -> "`DATE_FROM_UNIX_DATE`"))
> [info]   org.scalatest.exceptions.TestFailedException:
> [info]   at org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
> [info]   at org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
> [info]   at org.scalatest.Assertions$.newAssertionFailedException(Assertions.scala:1231)
> [info]   at org.scalatest.Assertions$AssertionsHelper.macroAssert(Assertions.scala:1295)
> [info]   at org.apache.spark.sql.catalyst.expressions.CastSuiteBase.checkInvalidCastFromNumericType(CastSuiteBase.scala:549)
> [info]   at org.apache.spark.sql.catalyst.expressions.CastSuiteBase.$anonfun$new$211(CastSuiteBase.scala:1007) {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org