You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "4ktLuffy (via GitHub)" <gi...@apache.org> on 2026/08/11 17:53:09 UTC

[PR] test: add expression fallback-invariance suite [datafusion-comet]

4ktLuffy opened a new pull request, #5329:
URL: https://github.com/apache/datafusion-comet/pull/5329

   ## Which issue does this PR close?
   
   Closes #5328.
   
   ## Rationale for this change
   
   For every expression Comet rates compatible, forcing it back to Spark with `spark.comet.expression.<Name>.enabled=false` must not change a query's outcome — neither its rows nor whether and what it throws. The invariant is free: the config already ships, and `QueryPlanSerde` already honours it for all 293 registered expressions.
   
   It is not currently swept. Four tests exercise the lever, each on one hand-picked expression; all four check the answer, but none checks a range of expressions mechanically and none checks that the two legs raise the *same* error.
   
   Replaying #5218's pre-fix logic shows the shape has teeth: the defect is invisible to `CometFuzzMathSuite` (30/30), `CometCodegenFuzzSuite` (28/28), `CometCodegenHOFSuite` (5/5) and `CometExecRuleSuite` (29/29), while this suite names it:
   
   ```
   FAIL-OUTCOME [errors] AddMonths default=VALUE(2024-02-01) forced=THREW(CAST_INVALID_INPUT)
   ```
   
   To be clear about what that is and isn't: `AddMonths` is in the corpus *because* #5218 named it, so this is a validation replay rather than an independent find, and `CometCodegenSuite` already guards that exact query end-to-end. The generic-detector misses are the load-bearing part, and the comparator is not specific to `add_months` — it flags this shape for any corpus expression.
   
   ## What changes are included in this PR?
   
   One new suite, `CometFallbackInvarianceSuite`, extending `CometFuzzTestBase`. No product code.
   
   - **Fixed query corpus** — 25 expressions over the existing seeded fuzz fixture, no new fixtures. A value-parity section with ANSI off, and an error-parity section with ANSI set explicitly on so it behaves identically on every Spark profile.
   - **Bind gate, mandatory.** Before any comparison, the executed plan must prove the flip moved execution: default leg shows Comet operators and zero Spark `ProjectExec`; forced leg shows a Spark `ProjectExec`. A plan showing neither is `SKIPPED-VACUOUS` and reported — never a pass. Plan presence is captured whether or not `collect()` succeeded, so a leg that throws is gated too.
   - **Three-valued outcome comparison** (`Rows` vs `Threw(errorClass)`): value-vs-throw is a failure, differing error classes are a failure, row-count mismatch is a failure. Error parity is where #5218 lives, so these comparator rules are load-bearing rather than incidental.
   - **Verdicts** — compatible-rated divergence `FAIL` · value-vs-throw `FAIL` · differing error class `FAIL` · length mismatch `FAIL` · incompatible-rated divergence `EXCUSED`, logged but never certified · NaN / `-0.0` / NULL as distinct tokens · row order canonicalised by sorting.
   
   ## How are these changes tested?
   
   The suite is the test. On a clean tree:
   
   ```
   FALLBACK-INVARIANCE-RESULT pass=24 fail=0 excused=0 vacuous=1
   FALLBACK-INVARIANCE SKIPPED-VACUOUS [values] StringTranslate not-native-by-default
   ```
   
   24 pass, 0 fail, 1 skipped-vacuous per variant × 3 variants, ~10 s. The one skip is honest and expected: `StringTranslate` is incompatible-rated, so it already runs on Spark by default and there is no native leg to compare against. Verified under `spark-3.4`, `spark-3.5` and `spark-4.1`.
   
   Validated by injected divergence twice: a deliberately broken `spark_decimal_div` as a positive control (also caught by `CometFuzzMathSuite`, as it should be), and the #5218 pre-fix replay. The probe run reports `pass=23 fail=1` — one delta from clean, and it is the witness quoted above.
   
   **On the bind gate.** It earned its place three times over while this suite was being written. An early version reported 22 passes where the truth was 19 passes and 3 vacuous. A second pinned ANSI off and mapped throw-vs-value to a harness error, making it structurally blind to the very bug class it exists for. A third used `ORDER BY` for determinism, which introduces a shuffle and roots the executed plan at `AdaptiveSparkPlanExec` — whose `children` is empty, so plan inspection silently read zero for every query in that section and the gate stopped working entirely. Comet's own `spark.comet.expression.*` tests sidestep all of this by using simple queries with no shuffle; this suite now does the same, avoiding `ORDER BY` and canonicalising row order in the comparator instead.
   
   **Scope, stated plainly.** 25 of 293 expressions. The suite owns one historical bug (#5218) and is not claimed to cover operator-level mixed execution, fallback-*decision* logic, or scan-metadata mismatches — #4813, #4051, #4789 and #2720 are different mechanisms and this invariant would not have caught any of them.
   
   Provenance note: produced during an AI-assisted audit of Comet's verification machinery, human-verified at each gate; mutation experiments were run with positive controls and the tree restored clean afterward.
   


-- 
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] test: add expression fallback-invariance suite [datafusion-comet]

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


-- 
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] test: add expression fallback-invariance suite [datafusion-comet]

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

   Both addressed — registered in both workflow matrices (check-suites.py now exits 0),
   and the exemption is derived from the live config rather than listed:
   
       private def divergenceExcusable(expr: String): Boolean =
         CometConf.isExprAllowIncompat(expr)
   
   Reproduced your experiment: with the static set, an injected mismatch on RLike
   records EXCUSED (suite green) while the same mismatch on EqualTo gives FAIL-VALUE.
   With the derived predicate, RLike gives FAIL-VALUE. All six exempted names returned
   allowIncompatible=false under this suite's config, so RLike wasn't the only stale one.
   
   Deriving does leave the EXCUSED branch unreachable here, since nothing in this suite
   sets allowIncompatible — happy to delete it instead if you'd rather not carry dead code.
   
   Rebased on latest main.


-- 
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] test: add expression fallback-invariance suite [datafusion-comet]

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


##########
spark/src/test/scala/org/apache/comet/CometFallbackInvarianceSuite.scala:
##########
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.execution.{ProjectExec, SparkPlan}
+import org.apache.spark.sql.internal.SQLConf
+
+/**
+ * Checks that forcing an expression from Comet's native path back to Spark does not change the
+ * outcome of a query.
+ *
+ * Comet exposes `spark.comet.expression.<Name>.enabled` for every registered expression, and
+ * `QueryPlanSerde` honours it as forced fallback. For any expression Comet rates compatible, that
+ * gives a free invariant: the outcome of a query -- its rows, or the error it raises -- must be
+ * identical whether the expression is evaluated natively or by Spark.
+ *
+ * Two properties of this suite are load-bearing:
+ *
+ *   1. "Outcome" is three-valued. A leg either produces rows or throws. A value on one leg and an
+ *      exception on the other is a failure with a named witness, not an error in the harness --
+ *      exception parity is where several historical divergences have lived.
+ *
+ * 2. Every comparison is gated on evidence that the config flip actually moved execution. A query
+ * whose executed plan proves nothing is reported SKIPPED-VACUOUS and never counted as a pass.
+ * Without that gate an invariance sweep silently overstates its own coverage.
+ *
+ * Queries deliberately avoid `ORDER BY`: a shuffle roots the executed plan at
+ * `AdaptiveSparkPlanExec`, whose `children` is empty, so plan inspection would read zero for
+ * everything and the gate above would be inoperative. Row order is canonicalised in the
+ * comparator instead.
+ */
+class CometFallbackInvarianceSuite extends CometFuzzTestBase {

Review Comment:
   [P2] Register the suite in both CI workflows
   
   Could you add `org.apache.comet.CometFallbackInvarianceSuite` to the suite matrices in both `.github/workflows/pr_build_linux.yml` and `.github/workflows/pr_build_macos.yml`? They use explicit suite lists. `python3 dev/ci/check-suites.py` passes on the base but exits 255 on this head, and the [Preflight job](https://github.com/apache/datafusion-comet/actions/runs/31517356712/job/96231037450) fails on this class before the downstream tests can run.



##########
spark/src/test/scala/org/apache/comet/CometFallbackInvarianceSuite.scala:
##########
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.comet
+
+import scala.collection.mutable
+import scala.util.{Failure, Success, Try}
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.execution.{ProjectExec, SparkPlan}
+import org.apache.spark.sql.internal.SQLConf
+
+/**
+ * Checks that forcing an expression from Comet's native path back to Spark does not change the
+ * outcome of a query.
+ *
+ * Comet exposes `spark.comet.expression.<Name>.enabled` for every registered expression, and
+ * `QueryPlanSerde` honours it as forced fallback. For any expression Comet rates compatible, that
+ * gives a free invariant: the outcome of a query -- its rows, or the error it raises -- must be
+ * identical whether the expression is evaluated natively or by Spark.
+ *
+ * Two properties of this suite are load-bearing:
+ *
+ *   1. "Outcome" is three-valued. A leg either produces rows or throws. A value on one leg and an
+ *      exception on the other is a failure with a named witness, not an error in the harness --
+ *      exception parity is where several historical divergences have lived.
+ *
+ * 2. Every comparison is gated on evidence that the config flip actually moved execution. A query
+ * whose executed plan proves nothing is reported SKIPPED-VACUOUS and never counted as a pass.
+ * Without that gate an invariance sweep silently overstates its own coverage.
+ *
+ * Queries deliberately avoid `ORDER BY`: a shuffle roots the executed plan at
+ * `AdaptiveSparkPlanExec`, whose `children` is empty, so plan inspection would read zero for
+ * everything and the gate above would be inoperative. Row order is canonicalised in the
+ * comparator instead.
+ */
+class CometFallbackInvarianceSuite extends CometFuzzTestBase {
+
+  /**
+   * Expressions Comet documents as not guaranteed to match Spark exactly. A divergence here is
+   * reported as EXCUSED: logged for the record, never counted as a pass.
+   */
+  private val incompatibleRated: Set[String] =
+    Set(
+      "DateFormatClass",
+      "FromUTCTimestamp",
+      "GetJsonObject",
+      "RLike",

Review Comment:
   [P2] Do not excuse compatible RLike mismatches
   
   Could you remove this exemption or derive it from the active implementation and configuration? At this head, [`CometRLike.getSupportLevel`](https://github.com/apache/datafusion-comet/blob/e3c6fea350e44558194090945f3a0b0bd604e2af/spark/src/main/scala/org/apache/comet/serde/strings.scala#L378-L399) rates the default JVM-codegen path compatible. The incompatible Rust regex implementation requires `spark.comet.expression.RLike.allowIncompatible=true`, which this suite does not enable. With valid execution-plan evidence, opposite Boolean results are nevertheless recorded as `EXCUSED`, leaving the test green. I reproduced that with the unchanged comparator on Scala 2.12.18 and 2.13.17. The same mismatch for `EqualTo` correctly produces `FAIL-VALUE`.



-- 
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] test: add expression fallback-invariance suite [datafusion-comet]

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

   Merged, thanks for the contribution @4ktLuffy !


-- 
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