Repository navigation
Commit 1c43063
authored
fix: stop treating arithmetic negation as bitwise NOT (apache#24668)
## Which issue does this PR address?
- Addresses the arithmetic-negation/bitwise portion of apache#24665.
- The remaining checked-negation and ordering work stays open in apache#24665
and apache#24683.
## Rationale for this change
`Expr::Negative` represents arithmetic unary minus, but the simplifier
applied identities for bitwise complement. That changes valid results
for expressions combining unary minus with bitwise AND, OR, and XOR.
This PR is intentionally narrow. It preserves the existing generic
`-(-x) -> x` simplification and does not change physical negation,
bounds, pruning, ordering equivalence, or SQL unparsing.
## What changes are included in this PR?
- Remove the six bitwise-complement identities that treated `-x` as
`~x`.
- Stop applying bitwise De Morgan rewrites to arithmetic unary minus.
- Retain the existing exact double-negation simplification.
## Are these changes tested?
Yes.
- Optimizer unit tests cover both operand orders for AND, OR, and XOR,
both invalid De Morgan shapes, and unchanged double-negation
cancellation.
- A SQL logic test verifies the corrected integer results.
- `cargo clippy --all-targets --all-features -- -D warnings` passes.
- `./dev/rust_lint.sh` passes.
- The extended workspace suite passes, including all 505 SQL logic-test
files.
## Are there any user-facing changes?
Yes. Unary minus in bitwise expressions now keeps arithmetic-negation
semantics and returns the correct values. There are no API changes.
Signed-off-by: Amogh Ramesh <[email protected]>1 parent f9b7f34 commit 1c43063
3 files changed
Lines changed: 39 additions & 171 deletions
File tree
- datafusion
- optimizer/src/simplify_expressions
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1267 | 1267 | | |
1268 | 1268 | | |
1269 | 1269 | | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | 1270 | | |
1295 | 1271 | | |
1296 | 1272 | | |
| |||
1341 | 1317 | | |
1342 | 1318 | | |
1343 | 1319 | | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | 1320 | | |
1369 | 1321 | | |
1370 | 1322 | | |
| |||
1415 | 1367 | | |
1416 | 1368 | | |
1417 | 1369 | | |
1418 | | - | |
1419 | | - | |
1420 | | - | |
1421 | | - | |
1422 | | - | |
1423 | | - | |
1424 | | - | |
1425 | | - | |
1426 | | - | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
1436 | | - | |
1437 | | - | |
1438 | | - | |
1439 | | - | |
1440 | | - | |
1441 | | - | |
1442 | 1370 | | |
1443 | 1371 | | |
1444 | 1372 | | |
| |||
1503 | 1431 | | |
1504 | 1432 | | |
1505 | 1433 | | |
1506 | | - | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
1507 | 1440 | | |
1508 | 1441 | | |
1509 | 1442 | | |
| |||
3449 | 3382 | | |
3450 | 3383 | | |
3451 | 3384 | | |
3452 | | - | |
3453 | | - | |
3454 | | - | |
3455 | | - | |
3456 | | - | |
3457 | | - | |
3458 | | - | |
3459 | | - | |
3460 | | - | |
3461 | | - | |
3462 | | - | |
3463 | | - | |
3464 | | - | |
3465 | | - | |
3466 | | - | |
3467 | | - | |
3468 | | - | |
3469 | | - | |
3470 | | - | |
3471 | | - | |
3472 | | - | |
3473 | | - | |
3474 | | - | |
3475 | | - | |
3476 | | - | |
3477 | | - | |
3478 | | - | |
3479 | | - | |
3480 | | - | |
3481 | | - | |
3482 | | - | |
3483 | | - | |
3484 | | - | |
3485 | | - | |
3486 | | - | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
| 3391 | + | |
| 3392 | + | |
| 3393 | + | |
| 3394 | + | |
| 3395 | + | |
| 3396 | + | |
3487 | 3397 | | |
3488 | | - | |
3489 | | - | |
3490 | | - | |
| 3398 | + | |
| 3399 | + | |
| 3400 | + | |
3491 | 3401 | | |
3492 | | - | |
| 3402 | + | |
| 3403 | + | |
3493 | 3404 | | |
3494 | 3405 | | |
3495 | 3406 | | |
| |||
3674 | 3585 | | |
3675 | 3586 | | |
3676 | 3587 | | |
3677 | | - | |
3678 | | - | |
3679 | | - | |
3680 | | - | |
3681 | | - | |
3682 | | - | |
3683 | | - | |
3684 | | - | |
3685 | | - | |
3686 | | - | |
3687 | | - | |
3688 | | - | |
3689 | | - | |
3690 | | - | |
3691 | 3588 | | |
3692 | 3589 | | |
3693 | 3590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | 197 | | |
203 | 198 | | |
204 | 199 | | |
| |||
370 | 365 | | |
371 | 366 | | |
372 | 367 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | 368 | | |
413 | 369 | | |
414 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1479 | 1479 | | |
1480 | 1480 | | |
1481 | 1481 | | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
1482 | 1497 | | |
1483 | 1498 | | |
1484 | 1499 | | |
| |||
0 commit comments