advancedxy commented on code in PR #351:
URL: https://github.com/apache/datafusion-comet/pull/351#discussion_r1584964296
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -43,87 +44,660 @@ class CometCastSuite extends CometTestBase with
AdaptiveSparkPlanHelper {
private val datePattern = "0123456789/" + whitespaceChars
private val timestampPattern = "0123456789/:T" + whitespaceChars
- ignore("cast long to short") {
- castTest(generateLongs, DataTypes.ShortType)
+ test("all valid cast combinations covered") {
+ val names = testNames
+
+ def assertTestsExist(fromTypes: Seq[DataType], toTypes: Seq[DataType]):
Unit = {
+ for (fromType <- fromTypes) {
+ for (toType <- toTypes) {
+ if (fromType != toType) {
+ val expectedTestName = s"cast $fromType to $toType"
+ if (Cast.canCast(fromType, toType)) {
+ if (!names.contains(expectedTestName)) {
+ fail(s"Missing test: $expectedTestName")
+ }
+ } else if (names.contains(expectedTestName)) {
+ fail(s"Found test for cast that Spark does not support:
$expectedTestName")
+ }
+ }
+ }
+ }
+ }
+
+ // make sure we have tests for all combinations of our supported types
+ val supportedTypes =
+ Seq(
+ DataTypes.BooleanType,
+ DataTypes.ByteType,
+ DataTypes.ShortType,
+ DataTypes.IntegerType,
+ DataTypes.LongType,
+ DataTypes.FloatType,
+ DataTypes.DoubleType,
+ DataTypes.createDecimalType(10, 2),
+ DataTypes.StringType,
+ DataTypes.DateType,
+ DataTypes.TimestampType,
+ DataTypes.TimestampNTZType)
+ assertTestsExist(supportedTypes, supportedTypes)
+ }
+
+ // CAST from BooleanType
+
+ test("cast BooleanType to BooleanType") {
+ castTest(generateBools(), DataTypes.BooleanType)
+ }
+
+ ignore("cast BooleanType to ByteType") {
+ // https://github.com/apache/datafusion-comet/issues/311
+ castTest(generateBools(), DataTypes.ByteType)
+ }
+
+ ignore("cast BooleanType to ShortType") {
+ // https://github.com/apache/datafusion-comet/issues/311
+ castTest(generateBools(), DataTypes.ShortType)
+ }
+
+ test("cast BooleanType to IntegerType") {
+ castTest(generateBools(), DataTypes.IntegerType)
+ }
+
+ test("cast BooleanType to LongType") {
+ // https://github.com/apache/datafusion-comet/issues/311
+ castTest(generateBools(), DataTypes.LongType)
+ }
+
+ test("cast BooleanType to FloatType") {
+ castTest(generateBools(), DataTypes.FloatType)
+ }
+
+ test("cast BooleanType to DoubleType") {
+ castTest(generateBools(), DataTypes.DoubleType)
+ }
+
+ ignore("cast BooleanType to DecimalType(10,2)") {
+ // Comet should have failed with [NUMERIC_VALUE_OUT_OF_RANGE] -1117686336
cannot be represented as Decimal(10, 2)
+ castTest(generateBools(), DataTypes.createDecimalType(10, 2))
+ }
+
+ test("cast BooleanType to StringType") {
+ castTest(generateBools(), DataTypes.StringType)
+ }
+
+ ignore("cast BooleanType to TimestampType") {
+ // Arrow error: Cast error: Casting from Boolean to Timestamp(Microsecond,
Some("UTC")) not supported
+ castTest(generateBools(), DataTypes.TimestampType)
+ }
+
+ // CAST from ByteType
+
+ test("cast ByteType to BooleanType") {
+ castTest(generateBytes(), DataTypes.BooleanType)
+ }
+
+ ignore("cast ByteType to ByteType") {
Review Comment:
is the same type cast needed? It seems that assertTestsExist ignores this
kind of cast.
--
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]