Repository navigation
Commit 69a7fef
authored
fix: do not fail when an expression's ordering cannot be derived (apache#26884)
## Which issue does this PR close?
- Related to apache#26481. No issue filed.
## Rationale for this change
`sqrt`, `ln`, `log2`, `log10`, `acos`, `asin`, `acosh` and `atanh`
cannot derive an ordering from their input when the input may be outside
their domain (for `sqrt`, a negative `a`), so their `get_properties`
returns an error. Two places in `EquivalenceProperties` treated that
error as fatal, although it only means that nothing can be derived:
- `update_properties` propagated it, which also discarded the ordering
the expression already had from the plan. A plan sorted on `sqrt(c)`
then does not satisfy a requirement on `sqrt(c)`, so on `main` this
query fails in `SanityCheckPlan`:
```sql
SELECT c, row_number() OVER (ORDER BY sqrt(c))
FROM (SELECT c FROM t ORDER BY sqrt(c) LIMIT 5);
```
- `discover_new_orderings` propagated it out of `FilterExec`'s
properties. On a table with `DOUBLE` columns `a` and `b`, ordered by
`(a, b)`, this query fails on `main` with `Execution error: Input range
of SQRT contains out-of-domain values`:
```sql
SELECT * FROM t WHERE a = sqrt(b);
```
## What changes are included in this PR?
- `update_properties` treats properties that cannot be derived from the
children as unknown, with an unbounded range of the expression's type,
instead of failing. The node's own known ordering is kept, and parents
such as `-sqrt(c)` can still derive their ordering from it.
- `discover_new_orderings` skips a candidate whose properties cannot be
derived, so no new ordering is found from it.
## Are these changes tested?
Yes. `equivalence_properties.slt` covers both queries above and
`-sqrt(c)`; each case fails without its change.
`test_known_ordering_when_expr_properties_fail` checks that a known
ordering on `sqrt(a)` satisfies only a requirement with the same sort
options, and that `sqrt(a)` is not ordered when nothing is ordered or
only `a` is.
## Are there any user-facing changes?
Yes: the two queries above now plan and run.1 parent 8df818a commit 69a7fef
3 files changed
Lines changed: 133 additions & 4 deletions
File tree
- datafusion
- physical-expr/src/equivalence/properties
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
595 | 643 | | |
596 | 644 | | |
597 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
511 | | - | |
512 | | - | |
513 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
514 | 518 | | |
515 | 519 | | |
516 | 520 | | |
| |||
1548 | 1552 | | |
1549 | 1553 | | |
1550 | 1554 | | |
1551 | | - | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
1552 | 1563 | | |
1553 | 1564 | | |
1554 | 1565 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
137 | 207 | | |
138 | 208 | | |
139 | 209 | | |
| |||
0 commit comments