@@ -163,6 +163,33 @@ class CometCodegenDispatchSmokeSuite extends CometTestBase with AdaptiveSparkPla
163163 s " expected no dispatcher activity under disabled config, got $after" )
164164 }
165165
166+ test(" schema exceeding spark.sql.codegen.maxFields falls back to Spark" ) {
167+ // `CometBatchKernelCodegen.canHandle` mirrors WSCG's `spark.sql.codegen.maxFields` gate by
168+ // counting nested input fields plus the output field and refusing once the total exceeds the
169+ // configured cap. Comet has no mid-execution fallback, so the gate must fire at plan time
170+ // (in the serde) rather than letting an oversized kernel reach Janino. With 5 input
171+ // BoundReferences and a 1-field output we have 6 fields total; setting `maxFields=3` ensures
172+ // the gate fires here regardless of test ordering or future schema additions.
173+ spark.udf.register(
174+ " sumFiveInts" ,
175+ (a : Int , b : Int , c : Int , d : Int , e : Int ) => a + b + c + d + e)
176+ withTable(" t" ) {
177+ sql(" CREATE TABLE t (a INT, b INT, c INT, d INT, e INT) USING parquet" )
178+ sql(" INSERT INTO t VALUES (1, 2, 3, 4, 5), (10, 20, 30, 40, 50)" )
179+ CometScalaUDFCodegen .resetStats()
180+ withSQLConf(" spark.sql.codegen.maxFields" -> " 3" ) {
181+ // Result correctness still has to match Spark; only the dispatcher path is refused.
182+ // ScalaUDF has no Comet-native path, so this runs on the JVM Spark path under fallback,
183+ // hence `checkSparkAnswer` rather than `checkSparkAnswerAndOperator`.
184+ checkSparkAnswer(sql(" SELECT sumFiveInts(a, b, c, d, e) FROM t" ))
185+ }
186+ val after = CometScalaUDFCodegen .stats()
187+ assert(
188+ after.compileCount == 0 && after.cacheHitCount == 0 ,
189+ s " expected dispatcher fallback under maxFields=3, got $after" )
190+ }
191+ }
192+
166193 test(" per-batch nullability produces distinct compiles for null-present vs null-absent" ) {
167194 // Same ScalaUDF + same Arrow vector class + different observed nullability should hit
168195 // different cache keys, because `ArrowColumnSpec.nullable` flips when the batch has no
0 commit comments