comphead commented on code in PR #7723:
URL: https://github.com/apache/datafusion-comet/pull/7723#discussion_r4743960364


##########
docs/source/user-guide/latest/compatibility/index.md:
##########
@@ -171,6 +171,51 @@ already-ordered `TakeOrderedAndProject` inputs are tracked 
in
 An error on a row absent from the final result is not always a mismatch: Spark 
can also need to
 evaluate that row, for example to sort the input or process an `OFFSET` prefix.
 
+## ANSI division errors skipped by filters and projections
+
+With `spark.sql.ansi.enabled=true`, Comet can return rows where Spark raises
+`DIVIDE_BY_ZERO`. The examples below use Spark's default code generation 
settings
+and a Parquet table `t` with these two rows in the same row group.
+
+| x   | y    | p     | q     |
+| --- | ---- | ----- | ----- |
+| 1   | 1    | true  | true  |
+| 0   | NULL | false | false |
+
+```sql
+SELECT x FROM t WHERE y IS NOT NULL AND abs(10 DIV x) > 0
+```
+
+`CometFilter` skips the row with `y = NULL` and returns `1`. Spark's 
whole-stage filter
+checks a column for NULL when a predicate first needs it. The comparison needs 
only
+`x`, so Spark divides by zero before checking `y`. With 
`spark.sql.codegen.wholeStage=false`,
+Spark checks `y` first. Lowering `spark.sql.codegen.hugeMethodLimit` only 
forces this
+switch if a compiled method exceeds the limit.
+
+With `spark.comet.parquet.rowFilterPushdown.enabled=true`, the Comet Parquet 
scan can
+apply `y IS NOT NULL` during decoding. The zero divisor then never reaches the 
filter,
+even if Spark runs that filter. See [Parquet filter pushdown](../parquet.md).
+
+```sql
+SELECT x <> 0 AND abs(10 DIV x) + abs(10 DIV x) > 1 AS b FROM t
+```
+
+`CometProject` returns `false` for `x = 0`. With subexpression elimination 
enabled,
+Spark's generated projection computes the repeated `abs(10 DIV x)` before 
testing
+`x <> 0` and raises. This can happen even with whole-stage code generation 
disabled.
+
+```sql
+SELECT x FROM t WHERE (p OR (q AND 10 DIV x > 0)) AND 10 DIV x < 100
+```
+
+With subexpression elimination enabled for filters, Spark 4.2's whole-stage 
filter
+computes the shared `10 DIV x` before testing `p` or `q`. Both are false on the
+second row, so `CometFilter` rejects it without dividing, while Spark raises.
+
+To use Spark's evaluation order for both the scan and the operators, set
+`spark.comet.enabled=false` before running the query. See
+[#7480](https://github.com/apache/datafusion-comet/issues/7480).

Review Comment:
   Disabling Comet for the whole query is broader than this difference needs. 
The page already points at a per-operator switch for the grouped ANSI decimal 
`AVG` entry (`spark.comet.exec.aggregate.enabled`), and `operators.md` 
documents `spark.comet.exec.OPERATOR.enabled=false`. Here 
`spark.comet.exec.filter.enabled=false` and 
`spark.comet.exec.project.enabled=false` should leave the filter and projection 
to Spark while the scan stays in Comet, and the scan-side case in the second 
paragraph only exists when 
`spark.comet.parquet.rowFilterPushdown.enabled=true`, which is off by default. 
I did not run these settings. Could the paragraph name them and keep 
`spark.comet.enabled=false` as the whole-query option?



##########
docs/source/user-guide/latest/compatibility/index.md:
##########
@@ -171,6 +171,51 @@ already-ordered `TakeOrderedAndProject` inputs are tracked 
in
 An error on a row absent from the final result is not always a mismatch: Spark 
can also need to
 evaluate that row, for example to sort the input or process an `OFFSET` prefix.
 
+## ANSI division errors skipped by filters and projections
+
+With `spark.sql.ansi.enabled=true`, Comet can return rows where Spark raises
+`DIVIDE_BY_ZERO`. The examples below use Spark's default code generation 
settings
+and a Parquet table `t` with these two rows in the same row group.
+
+| x   | y    | p     | q     |
+| --- | ---- | ----- | ----- |
+| 1   | 1    | true  | true  |
+| 0   | NULL | false | false |
+
+```sql
+SELECT x FROM t WHERE y IS NOT NULL AND abs(10 DIV x) > 0
+```
+
+`CometFilter` skips the row with `y = NULL` and returns `1`. Spark's 
whole-stage filter
+checks a column for NULL when a predicate first needs it. The comparison needs 
only
+`x`, so Spark divides by zero before checking `y`. With 
`spark.sql.codegen.wholeStage=false`,
+Spark checks `y` first. Lowering `spark.sql.codegen.hugeMethodLimit` only 
forces this
+switch if a compiled method exceeds the limit.
+
+With `spark.comet.parquet.rowFilterPushdown.enabled=true`, the Comet Parquet 
scan can
+apply `y IS NOT NULL` during decoding. The zero divisor then never reaches the 
filter,
+even if Spark runs that filter. See [Parquet filter pushdown](../parquet.md).

Review Comment:
   The link text names a section but the target is the top of `parquet.md`. The 
section is `Filter Pushdown / Late Materialization`, so 
`../parquet.md#filter-pushdown--late-materialization` takes the reader to it, 
as `../parquet.md#known-issues` does elsewhere on this page. I did not build 
the docs to confirm the slug.



##########
docs/source/user-guide/latest/compatibility/index.md:
##########
@@ -171,6 +171,51 @@ already-ordered `TakeOrderedAndProject` inputs are tracked 
in
 An error on a row absent from the final result is not always a mismatch: Spark 
can also need to
 evaluate that row, for example to sort the input or process an `OFFSET` prefix.
 
+## ANSI division errors skipped by filters and projections
+
+With `spark.sql.ansi.enabled=true`, Comet can return rows where Spark raises
+`DIVIDE_BY_ZERO`. The examples below use Spark's default code generation 
settings
+and a Parquet table `t` with these two rows in the same row group.
+
+| x   | y    | p     | q     |
+| --- | ---- | ----- | ----- |
+| 1   | 1    | true  | true  |
+| 0   | NULL | false | false |
+
+```sql
+SELECT x FROM t WHERE y IS NOT NULL AND abs(10 DIV x) > 0
+```
+
+`CometFilter` skips the row with `y = NULL` and returns `1`. Spark's 
whole-stage filter
+checks a column for NULL when a predicate first needs it. The comparison needs 
only
+`x`, so Spark divides by zero before checking `y`. With 
`spark.sql.codegen.wholeStage=false`,
+Spark checks `y` first. Lowering `spark.sql.codegen.hugeMethodLimit` only 
forces this
+switch if a compiled method exceeds the limit.

Review Comment:
   `this switch` has no antecedent. The sentence before it says that 
`spark.sql.codegen.wholeStage=false` makes Spark check `y` first, so the reader 
has to infer that the limit can also turn whole-stage code generation off. 
Something like `Lowering spark.sql.codegen.hugeMethodLimit has the same effect 
only when a compiled method exceeds the limit` says it directly.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to