@@ -2486,6 +2486,59 @@ class CometCodegenSuite
24862486 }
24872487 }
24882488
2489+ test(" transitive consumers of DSv2 decimals preserve materialization timing (#6425)" ) {
2490+ withDecimalFunctions(3 , null , 100000000 , - 100000000 ) {
2491+ for (ansi <- Seq (" true" , " false" )) {
2492+ withSQLConf(SQLConf .ANSI_ENABLED .key -> ansi) {
2493+ val projected = sql(
2494+ " SELECT i, abs(decfn.ns.as_money(i)) IS NULL, " +
2495+ " abs(decfn.ns.static_as_money(i)) IS NULL, " +
2496+ " decfn.ns.money_array(i)[0] IS NULL, " +
2497+ " decfn.ns.money_struct(i).m IS NULL, " +
2498+ " CAST(abs(decfn.ns.as_money(i)) AS STRING) FROM t" )
2499+ assertCodegenRan {
2500+ checkSparkAnswerAndImpl(projected, dispatched = Seq (" isnull" , " cast" ))
2501+ }
2502+ checkAnswer(
2503+ projected,
2504+ Seq (
2505+ Row (3 , false , false , false , false , " 3" ),
2506+ Row (null , true , true , true , true , null ),
2507+ Row (100000000 , false , false , false , false , " 100000000" ),
2508+ Row (- 100000000 , false , false , false , false , " 100000000" )))
2509+ val filtered = sql(" SELECT i FROM t WHERE abs(decfn.ns.as_money(i)) IS NULL" )
2510+ checkSparkAnswerAndImpl(filtered, dispatched = Seq (" isnull" ))
2511+ checkAnswer(filtered, Seq (Row (null )))
2512+ val aggregated = sql(
2513+ " SELECT count(abs(decfn.ns.as_money(i))), " +
2514+ " count(abs(decfn.ns.static_as_money(i))), " +
2515+ " count(decfn.ns.money_array(i)[0]), " +
2516+ " count(decfn.ns.money_struct(i).m), max(abs(decfn.ns.as_money(i))), " +
2517+ " sum(abs(decfn.ns.as_money(i))) FROM t" )
2518+ checkSparkAnswerAndFallbackReason(
2519+ aggregated,
2520+ " aggregates the decimal result of a DSv2 function" )
2521+ checkAnswer(aggregated, Row (3L , 3L , 3L , 3L , null , dec(" 200000003.00" )))
2522+ withSQLConf(CometConf .COMET_SCALA_UDF_CODEGEN_ENABLED .key -> " false" ) {
2523+ checkSparkAnswerAndFallbackReason(
2524+ " SELECT abs(decfn.ns.as_money(i)) IS NULL FROM t" ,
2525+ " spark.comet.exec.scalaUDF.codegen.enabled=false" )
2526+ }
2527+ // A physical write is a real boundary; a view would be collapsed by Catalyst.
2528+ withTable(" decimal_materialized" ) {
2529+ sql(
2530+ " CREATE TABLE decimal_materialized USING parquet AS " +
2531+ " SELECT i, abs(decfn.ns.as_money(i)) AS d FROM t" )
2532+ checkSparkAnswerAndOperator(" SELECT i, d IS NULL FROM decimal_materialized" )
2533+ checkAnswer(
2534+ sql(" SELECT i FROM decimal_materialized WHERE d IS NULL" ),
2535+ Seq (Row (null ), Row (100000000 ), Row (- 100000000 )))
2536+ }
2537+ }
2538+ }
2539+ }
2540+ }
2541+
24892542 test(
24902543 " an aggregate over a DSv2 decimal result falls back, as Spark aggregates the value (#6425)" ) {
24912544 // Spark aggregates the `Decimal` the function returned, and the row writer nulls the result
0 commit comments