Commit d86b8b1
committed
fix(core): resolve reference segments totally, and scope join keys per side
Two defects in the field-reference retyping, both found reviewing it.
Segment resolution was guarded one segment deep. The guard checked only that the
outermost segment selected a field the new record type has, so a reference into a
nested type that had been reshaped reached the derivation anyway and threw — a bare
IndexOutOfBoundsException out of a struct-field finder, or an IllegalArgumentException
or UnsupportedOperationException for a list or map segment. That contradicted the
guard's own promise to leave an unresolvable reference alone, and it made a narrowing
rewrite fail where it previously produced a stale type.
Resolution is now total: FieldReference.resolveType reports the type a chain of
segments selects, or nothing, at any depth and for every kind of segment. It lives
beside the finders whose rules it mirrors, so the two cannot drift apart unnoticed
without the parity test that pins them going red. It mirrors those rules exactly,
including the two asymmetries that matter: a list element offset is not bounds
checked, because the length of a list is not part of its type, and a map key type is
compared exactly, nullability included. The visitor's one-deep guard and its defensive
segment copy both go, and the same guarantee now covers a reference rooted at another
expression, which had no guard at all.
Join keys were retyped against the wrong scope. The offsets of a hash or merge join
key are relative to the side of the join the key selects from, not to the two inputs
combined — proto conversion types each side with its own converter, and only the
condition, post-join filter and residual expression use the combined type. Retyping
both sides against the combined type silently resolved a right-side offset to a left
column. Each side is now rewritten against its own input, which changes the signature
of visitComparisonJoinKey; the method could not previously return a usable reference at
all, so nothing can have depended on the old one.
Two things this deliberately does not do: the off-by-one bound check in
StructFieldFinder stays, because the exception it produces is part of what
ProtoExpressionConverter reports for a malformed plan; and MergeJoin.deriveRecordType
reads its right input for both sides, which is a separate bug in a relation this change
only passes through.1 parent f2d5c65 commit d86b8b1
5 files changed
Lines changed: 746 additions & 59 deletions
File tree
- core/src
- main/java/io/substrait
- expression
- relation
- test/java/io/substrait
- expression
- relation
Lines changed: 71 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | | - | |
| 483 | + | |
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
| |||
509 | 509 | | |
510 | 510 | | |
511 | 511 | | |
512 | | - | |
| 512 | + | |
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
519 | 588 | | |
520 | 589 | | |
521 | 590 | | |
| |||
Lines changed: 25 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
435 | 434 | | |
436 | 435 | | |
437 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
438 | 442 | | |
439 | 443 | | |
440 | 444 | | |
441 | 445 | | |
442 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
443 | 452 | | |
444 | 453 | | |
445 | 454 | | |
| |||
453 | 462 | | |
454 | 463 | | |
455 | 464 | | |
| 465 | + | |
| 466 | + | |
456 | 467 | | |
457 | 468 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
| 469 | + | |
| 470 | + | |
462 | 471 | | |
463 | 472 | | |
464 | 473 | | |
| |||
476 | 485 | | |
477 | 486 | | |
478 | 487 | | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 488 | + | |
483 | 489 | | |
484 | 490 | | |
485 | | - | |
486 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
487 | 499 | | |
488 | 500 | | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
| 501 | + | |
| 502 | + | |
513 | 503 | | |
514 | 504 | | |
515 | 505 | | |
| |||
Lines changed: 29 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
612 | 614 | | |
613 | 615 | | |
614 | 616 | | |
615 | | - | |
616 | | - | |
617 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
618 | 621 | | |
619 | 622 | | |
620 | 623 | | |
| |||
640 | 643 | | |
641 | 644 | | |
642 | 645 | | |
| 646 | + | |
| 647 | + | |
643 | 648 | | |
644 | 649 | | |
645 | 650 | | |
646 | | - | |
647 | | - | |
648 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
649 | 655 | | |
650 | 656 | | |
651 | 657 | | |
| |||
761 | 767 | | |
762 | 768 | | |
763 | 769 | | |
| 770 | + | |
| 771 | + | |
764 | 772 | | |
765 | 773 | | |
766 | 774 | | |
| |||
872 | 880 | | |
873 | 881 | | |
874 | 882 | | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
875 | 887 | | |
| 888 | + | |
| 889 | + | |
876 | 890 | | |
877 | 891 | | |
878 | 892 | | |
879 | 893 | | |
880 | 894 | | |
881 | | - | |
882 | | - | |
883 | | - | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
884 | 904 | | |
885 | 905 | | |
886 | 906 | | |
| |||
0 commit comments