@@ -656,8 +656,12 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
656656 // Parquet does not support negative-scale decimals so we use checkSparkAnswer directly
657657 // (no parquet round-trip) to avoid schema coercion.
658658
659- // With config enabled: Comet should match Spark's plain string output
660- withSQLConf(" spark.sql.legacy.allowNegativeScaleOfDecimal" -> " true" ) {
659+ // With config enabled, enable localTableScan so Comet can take over the full plan
660+ // and execute the cast natively. Parquet does not support negative-scale decimals so
661+ // the data is kept in-memory; localTableScan.enabled bridges that gap.
662+ withSQLConf(
663+ " spark.sql.legacy.allowNegativeScaleOfDecimal" -> " true" ,
664+ " spark.comet.exec.localTableScan.enabled" -> " true" ) {
661665 val dfNeg2 = Seq (
662666 Some (BigDecimal (" 0" )),
663667 Some (BigDecimal (" 100" )),
@@ -669,7 +673,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
669673 .withColumn(" a" , col(" b" ).cast(DecimalType (7 , - 2 )))
670674 .drop(" b" )
671675 .select(col(" a" ).cast(DataTypes .StringType ).as(" result" ))
672- checkSparkAnswer (dfNeg2)
676+ checkSparkAnswerAndOperator (dfNeg2)
673677
674678 val dfNeg4 = Seq (
675679 Some (BigDecimal (" 0" )),
@@ -681,7 +685,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
681685 .withColumn(" a" , col(" b" ).cast(DecimalType (7 , - 4 )))
682686 .drop(" b" )
683687 .select(col(" a" ).cast(DataTypes .StringType ).as(" result" ))
684- checkSparkAnswer (dfNeg4)
688+ checkSparkAnswerAndOperator (dfNeg4)
685689 }
686690
687691 // With config disabled (default): the SQL parser rejects negative scale, so
@@ -1565,6 +1569,10 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
15651569 BigDecimal (" -2147483647.123123123" ),
15661570 BigDecimal (" -123456.789" ),
15671571 BigDecimal (" 0.00000000000" ),
1572+ // Small-magnitude non-zero: adj_exp = -9 + 0 = -9 < -6, so LEGACY produces
1573+ // scientific notation "1E-9" / "1.000000000E-9" rather than plain "0.000000001".
1574+ BigDecimal (" 0.000000001" ),
1575+ BigDecimal (" -0.000000001" ),
15681576 BigDecimal (" 123456.789" ),
15691577 // Int Max
15701578 BigDecimal (" 2147483647.123123123" ),
0 commit comments