@@ -2513,6 +2513,59 @@ class CometCodegenSuite
25132513 }
25142514 }
25152515
2516+ test(" transitive consumers of DSv2 decimals preserve materialization timing (#6425)" ) {
2517+ withDecimalFunctions(3 , null , 100000000 , - 100000000 ) {
2518+ for (ansi <- Seq (" true" , " false" )) {
2519+ withSQLConf(SQLConf .ANSI_ENABLED .key -> ansi) {
2520+ val projected = sql(
2521+ " SELECT i, abs(decfn.ns.as_money(i)) IS NULL, " +
2522+ " abs(decfn.ns.static_as_money(i)) IS NULL, " +
2523+ " decfn.ns.money_array(i)[0] IS NULL, " +
2524+ " decfn.ns.money_struct(i).m IS NULL, " +
2525+ " CAST(abs(decfn.ns.as_money(i)) AS STRING) FROM t" )
2526+ assertCodegenRan {
2527+ checkSparkAnswerAndImpl(projected, dispatched = Seq (" isnull" , " cast" ))
2528+ }
2529+ checkAnswer(
2530+ projected,
2531+ Seq (
2532+ Row (3 , false , false , false , false , " 3" ),
2533+ Row (null , true , true , true , true , null ),
2534+ Row (100000000 , false , false , false , false , " 100000000" ),
2535+ Row (- 100000000 , false , false , false , false , " 100000000" )))
2536+ val filtered = sql(" SELECT i FROM t WHERE abs(decfn.ns.as_money(i)) IS NULL" )
2537+ checkSparkAnswerAndImpl(filtered, dispatched = Seq (" isnull" ))
2538+ checkAnswer(filtered, Seq (Row (null )))
2539+ val aggregated = sql(
2540+ " SELECT count(abs(decfn.ns.as_money(i))), " +
2541+ " count(abs(decfn.ns.static_as_money(i))), " +
2542+ " count(decfn.ns.money_array(i)[0]), " +
2543+ " count(decfn.ns.money_struct(i).m), max(abs(decfn.ns.as_money(i))), " +
2544+ " sum(abs(decfn.ns.as_money(i))) FROM t" )
2545+ checkSparkAnswerAndFallbackReason(
2546+ aggregated,
2547+ " aggregates the decimal result of a DSv2 function" )
2548+ checkAnswer(aggregated, Row (3L , 3L , 3L , 3L , null , dec(" 200000003.00" )))
2549+ withSQLConf(CometConf .COMET_SCALA_UDF_CODEGEN_ENABLED .key -> " false" ) {
2550+ checkSparkAnswerAndFallbackReason(
2551+ " SELECT abs(decfn.ns.as_money(i)) IS NULL FROM t" ,
2552+ " spark.comet.exec.scalaUDF.codegen.enabled=false" )
2553+ }
2554+ // A physical write is a real boundary; a view would be collapsed by Catalyst.
2555+ withTable(" decimal_materialized" ) {
2556+ sql(
2557+ " CREATE TABLE decimal_materialized USING parquet AS " +
2558+ " SELECT i, abs(decfn.ns.as_money(i)) AS d FROM t" )
2559+ checkSparkAnswerAndOperator(" SELECT i, d IS NULL FROM decimal_materialized" )
2560+ checkAnswer(
2561+ sql(" SELECT i FROM decimal_materialized WHERE d IS NULL" ),
2562+ Seq (Row (null ), Row (100000000 ), Row (- 100000000 )))
2563+ }
2564+ }
2565+ }
2566+ }
2567+ }
2568+
25162569 test(
25172570 " an aggregate over a DSv2 decimal result falls back, as Spark aggregates the value (#6425)" ) {
25182571 // Spark aggregates the `Decimal` the function returned, and the row writer nulls the result
0 commit comments