jayzhan211 commented on issue #26430:
URL: https://github.com/apache/datafusion/issues/26430#issuecomment-6382089587
Another way to hit this, with the same cause: `abs`, `sqrt`, `ln`, `log2` or
`cosh` over a `CASE`, which is what `COALESCE` becomes after simplification. It
needs no projection or repartition, and fails with one partition:
```sql
create table t (a bigint, b bigint);
select row_number() over (order by abs(coalesce(b, 0))) from t;
```
```text
SanityCheckPlan
caused by
Error during planning: ... does not satisfy order requirements: [abs(CASE
WHEN b@0 IS NOT NULL THEN b@0 ELSE 0 END) ASC NULLS LAST]. Child-0 order:
[[abs(CASE WHEN b@0 IS NOT NULL THEN b@0 ELSE 0 END) ASC NULLS LAST]]
```
`CaseExpr` doesn't implement `get_properties`, so like `a * b` it reports
the unknown range of type `Null`, and `abs` fails to build its zero. Giving `*`
and `/` real ranges would not fix this one.
Fixing it where the error is dropped covers both. In `update_properties`
(`equivalence/properties/mod.rs`), a failing `get_properties` returns early
through `?`, so the ordering lookup right below it never runs, although that
lookup already knows `abs(...)` is sorted. I tried this change on `main`:
```rust
node.data = node
.expr
.get_properties(&children_props)
.unwrap_or_else(|_| ExprProperties::new_unknown());
```
With it, the query above, every failing query in this issue's table, and the
same queries with `ln`, `log2` and `cosh` plan and return their rows in the
right order. (`sqrt(a * b)` then stops at execution with `cannot take square
root of a negative number` on the row where `a * b` is negative.) All
sqllogictest files pass.
This also breaks query q121 of the dbolympics benchmark (#26661).
--
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]