You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "rich7420 (via GitHub)" <gi...@apache.org> on 2026/10/24 07:52:45 UTC

[PR] fix: cap projection input beneath local and global limits [datafusion-comet]

rich7420 opened a new pull request, #7195:
URL: https://github.com/apache/datafusion-comet/pull/7195

   ## Which issue does this PR close?
   
   Part of #7147.
   
   ## Rationale for this change
   
   A native projection immediately below LocalLimit or GlobalLimit can evaluate an ANSI cast on rows beyond the limit and fail where Spark succeeds, for example when LIMIT is inside a subquery.
   
   ## What changes are included in this PR?
   
   Extend the existing CollectLimit projection input cap to adjacent LocalLimit and GlobalLimit. With native local limits enabled, a limit below the projection bounds its input before expression evaluation. Keep the outer limit and include the OFFSET prefix in the cap.
   
   Preserve configuration gating, column-only projection pruning, AQE links and repeated planning. Exclude CollectTail and offset-only limits, and never move the cap across filters or sorts.
   
   Update compatibility documentation. Throwing filters, GlobalLimit codegen OFFSET-prefix differences and the investigation of already-ordered TakeOrderedAndProject inputs remain outside this PR.
   
   ## How are these changes tested?
   
   - Spark 4.0.4: 16 focused tests passed; seven regressions failed before the fix.
   - Spark 4.1.3: 131 tests passed, including the full planner suite and focused LIMIT suites. After strengthening the final assertions, all four affected tests passed again.
   - Coverage includes direct LocalLimit/GlobalLimit, offsets, zero limits, batch boundaries, multiple partitions, AQE and consumed invalid values.
   - Native debug build, Spotless, Scalastyle, Prettier and `git diff --check` passed.
   - Spark 3.4/3.5/4.2 were not run locally.
   
   Draft pending Spark SQL CI. Please apply `run-spark-4.1-tests`, covering `InsertSortForLimitAndOffsetSuite` (sql_core-1) and `StreamSuite` (sql_core-3), before review.
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: cap projection input beneath local and global limits [datafusion-comet]

Posted by "rich7420 (via GitHub) via github" <gi...@datafusion.apache.org>.
rich7420 commented on PR #7195:
URL: https://github.com/apache/datafusion-comet/pull/7195#issuecomment-7317595335

   thanks for the review @sunchao and @comphead 


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: cap projection input beneath local and global limits [datafusion-comet]

Posted by "sunchao (via GitHub) via github" <gi...@datafusion.apache.org>.
sunchao merged PR #7195:
URL: https://github.com/apache/datafusion-comet/pull/7195


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: cap projection input beneath local and global limits [datafusion-comet]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #7195:
URL: https://github.com/apache/datafusion-comet/pull/7195#discussion_r4391176097


##########
spark/src/test/scala/org/apache/comet/CometNativeCastSuite.scala:
##########
@@ -128,6 +128,81 @@ class CometNativeCastSuite
     }
   }
 
+  test("non-collect LIMIT skips a failing cast beyond its projection input cap") {

Review Comment:
   The behavior checks in this test are a `query` that must match Spark, an error for `limit + 1`, an AQE on and off matrix and a few `spark.comet.batchSize` values, which `CometSqlFileTestSuite` supports. `array_append_eager_eval.sql` is a precedent with the same shape (`-- Config: spark.sql.ansi.enabled=true`, `/*+ COALESCE(1) */` for a single file and an `expect_error_class`), and `array_null_short_circuit.sql` already uses `expect_error(CAST_INVALID_INPUT)`. The plan-shape assertion on `CometLocalLimitExec.limit == limit + offset` is covered by the `CometExecRuleSuite` loops over collect, local and global limits, so this test could shrink to the parts a fixture cannot express. The `#6035` sibling test lives in this suite in Scala, so keeping the pattern is defensible. The dispatch assertion needs a `-- Config:` line for the codegen setting. I have not run such a fixture.



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: cap projection input beneath local and global limits [datafusion-comet]

Posted by "rich7420 (via GitHub) via github" <gi...@datafusion.apache.org>.
rich7420 commented on code in PR #7195:
URL: https://github.com/apache/datafusion-comet/pull/7195#discussion_r4662304388


##########
spark/src/test/scala/org/apache/comet/CometNativeCastSuite.scala:
##########
@@ -128,6 +128,81 @@ class CometNativeCastSuite
     }
   }
 
+  test("non-collect LIMIT skips a failing cast beyond its projection input cap") {

Review Comment:
   Thanks! I moved the behavior checks into SQL fixtures, `limit_projection.sql` plus `limit_projection_offset.sql` for the OFFSET cases, which need Spark 4.0 or later: ANSI on, `COALESCE(1)`, `expect_error_class(CAST_INVALID_INPUT)` for `limit + 1`, AQE on/off and batch sizes 2 and 8192. The fixtures use a `-- Config:` line for the codegen dispatch. The two non-collect Scala tests now only check what a fixture can't: that the cap is `limit + offset` with AQE on and off, and that it applies in each partition.
   



-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org