Repository navigation
Conversation
comphead
left a comment
There was a problem hiding this comment.
Capping the projection input is the batch-engine counterpart of Spark's lazy codegen, which stops at the limit, and it is the follow-up #7147 scoped. The offset handling (rows already includes the OFFSET prefix) matches SparkStrategies and limit.scala. Spark's PushProjectionThroughLimit does not make this unnecessary, since it is what creates the Limit -> Project shape. Two comments.
| } | ||
| } | ||
|
|
||
| test("non-collect LIMIT skips a failing cast beyond its projection input cap") { |
There was a problem hiding this 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.
There was a problem hiding this 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.
Preserve the guarded make_date conversion and the local/global projection input caps.
Keep final AQE and partition plan checks in Scala.
# Conflicts: # spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala
Spark 3.5 plans LIMIT with OFFSET with no LocalLimit below the shuffle, so Spark itself evaluates the projection on every row and raises CAST_INVALID_INPUT where these cases expect a result. Move the OFFSET queries to limit_projection_offset.sql with MinSparkVersion 4.0 and skip the AQE OFFSET test before Spark 4.0. The other cases still run on 3.5.
Both partitions return the same value, so the query result alone would not notice a partition that lost its row.
… OFFSET codegen An OFFSET-only GlobalLimit has no limit to cap at. On Spark 3.5 the generated code for a GlobalLimit with an OFFSET can evaluate the projection past the limit, so Spark can raise an error Comet does not.
The compatibility page said "native local limits", which the documentation style guide's rule for "native" does not allow in the user guide. Name spark.comet.exec.localLimit.enabled instead, and say "a Comet limit" in the rule's doc comment.
…ctions On Spark 3.5.9, with GlobalLimit and the projection in one codegen stage, Spark did not evaluate the projection past the limit: a LIMIT 2 OFFSET 1 over range(0, 5, 1, 1) with an invalid value at id 3 or 4 returned rows 1 and 2. Remove the sentence that said it could. A projection below another projection still evaluates its whole input batch, so list it with the other open cases.
With one partition there is no shuffle between the limit and the projection. On Spark 3.5 a LIMIT with OFFSET then plans as GlobalLimit over the projection, which no SQL fixture reached.
Which issue does this PR close?
Part of #7147.
Rationale for this change
A Comet projection below
LocalLimitorGlobalLimitcan evaluate a failing ANSI cast on rows beyond the limit, including when theLIMITis inside a subquery.What changes are included in this PR?
Extend the existing CollectLimit projection input cap to adjacent LocalLimit and GlobalLimit using the same conversion helper. Include the OFFSET prefix and retain the outer limit, configuration gating, column-only pruning, AQE links and repeated planning.
Preserve the guarded make_date conversion under CollectLimit. Move behavioral checks into SQL fixtures and retain Scala plan assertions. Update compatibility documentation. Spark 4.0 added a LocalLimit below the shuffle, so the OFFSET cases need Spark 4.0 or later and are in
limit_projection_offset.sql.Throwing filters, GlobalLimit codegen OFFSET-prefix differences and already-ordered TakeOrderedAndProject inputs remain outside this PR.
How are these changes tested?
CometExecRuleSuite, the LIMIT tests inCometNativeCastSuiteand both SQL fixtures pass on Spark 4.1.3 and 4.0.4 (148 tests per version). On Spark 3.5.9 with strict warnings, 143 pass and 2 are canceled by version gates.LocalLimitandGlobalLimitcases removed, all eight fixture runs fail withCAST_INVALID_INPUTon Spark 4.1.3. They pass with the fix restored.execandexpressionssuite groups frompr_build_linux.ymlpass on Spark 4.1.3.sql_corepasses on Spark 4.1.3 withdev/local-ci.sh. All four shards ran a total of 16,762 tests, matching the counts from the merge-queue run on f67d51d.catalystandsql_hiveshards, the Iceberg suites and the rest of the PR tier.CI (fork)has no run for this branch, so the runs above are local.