Repository navigation
Commit 5026ac4
fix: declare Hive partitioned scans as Range (#25279)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #23436.
## Rationale for this change
- Hive grouped scans declare Partitioning::Hash, but no hash ever ran.
- The optimizer treats any two Hash partitionings with equal counts as
co-partitioned, so it skips the repartition.
- Partitioned hash joins then drop rows. Fact {A, B, C} joined to
dimension {A, C, D} returns only A, because fact group 1 holds B while
dimension group 1 holds C.
- Joining a Hive scan to a VALUES list also loses rows, since the
planner hash repartitions the other side.
## What changes are included in this PR?
- Add FileGroup::group_by_partition_values_with_split_points, returning
groups plus the SplitPoints between them.
- Merge values into contiguous chunks rather than round robin. Only
contiguous chunks can be described by split points. Group counts are
unchanged.
- Give ListFilesResult a partition_split_points field.
- In ListingTable::scan build a logical Range partitioning from the
partition columns and the split points and convert it with
create_physical_partitioning, the same path a user declared output
partitioning takes. No new public helper.
- Declare nothing when split_file_groups_by_statistics re-cuts the
groups. Comparing counts misses this, since the re-cut can return the
same number.
- Drop the dynamic filter guard in HashJoinExec since it existed only
because Hive groups reported Hash.
## What is the testing strategy for this PR?
- TEST 14 and 15 in preserve_file_partitioning.slt cover the two
failures above.
- TEST 16 self joins the merged high cardinality table. TEST 17 asserts
the statistics re-cut declares nothing.
- Reverting only table.rs makes TEST 14 return one row instead of two
and breaks TEST 12.
- Six unit tests route every file through its split points and assert it
lands in its own group, covering NULLs, compound keys, a NULL inside a
split point, and unordered split points.
- Two datafusion-proto round trips cover Dictionary(UInt16, Utf8) and
Utf8View split points.
## Are there any user-facing changes?
- EXPLAIN prints Range([col ASC], [(v1), (v2)], N) instead of
Hash([col], N).
- Joins between Hive tables with different values gain a
RepartitionExec(Range) rather than returning wrong results.
- Partitioned dynamic filter pushdown works again under
preserve_file_partitions.
- File group membership changes when distinct values exceed
target_partitions. Byte balance can shift on date partitions with larger
recent days. Set preserve_file_partitions = 0 to restore the old
behaviour.
- API break: ListFilesResult gains a public field. Add
partition_split_points: vec![] or use ...
- Providers declaring Hash over value grouped files should declare Range
from the split points instead. They already return missing rows today
when the other join input is hash repartitioned.
---------
Co-authored-by: Andrew Lamb <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>1 parent c0ec512 commit 5026ac4
7 files changed
Lines changed: 626 additions & 106 deletions
File tree
- datafusion
- catalog-listing/src
- datasource/src
- file_scan_config
- physical-plan/src/joins/hash_join
- proto/tests/cases/plans
- sqllogictest/test_files
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| |||
668 | 670 | | |
669 | 671 | | |
670 | 672 | | |
| 673 | + | |
671 | 674 | | |
672 | 675 | | |
673 | 676 | | |
| |||
687 | 690 | | |
688 | 691 | | |
689 | 692 | | |
| 693 | + | |
690 | 694 | | |
691 | 695 | | |
692 | 696 | | |
| |||
704 | 708 | | |
705 | 709 | | |
706 | 710 | | |
| 711 | + | |
707 | 712 | | |
708 | 713 | | |
709 | 714 | | |
| |||
737 | 742 | | |
738 | 743 | | |
739 | 744 | | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
740 | 756 | | |
741 | 757 | | |
742 | 758 | | |
743 | 759 | | |
744 | 760 | | |
745 | 761 | | |
746 | 762 | | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
| 763 | + | |
760 | 764 | | |
761 | 765 | | |
762 | 766 | | |
| |||
1005 | 1009 | | |
1006 | 1010 | | |
1007 | 1011 | | |
| 1012 | + | |
1008 | 1013 | | |
1009 | 1014 | | |
1010 | 1015 | | |
| |||
1018 | 1023 | | |
1019 | 1024 | | |
1020 | 1025 | | |
1021 | | - | |
| 1026 | + | |
1022 | 1027 | | |
1023 | | - | |
| 1028 | + | |
| 1029 | + | |
1024 | 1030 | | |
1025 | | - | |
| 1031 | + | |
1026 | 1032 | | |
1027 | 1033 | | |
1028 | 1034 | | |
1029 | 1035 | | |
1030 | 1036 | | |
1031 | 1037 | | |
| 1038 | + | |
1032 | 1039 | | |
1033 | 1040 | | |
1034 | 1041 | | |
1035 | | - | |
| 1042 | + | |
1036 | 1043 | | |
1037 | 1044 | | |
1038 | 1045 | | |
1039 | 1046 | | |
1040 | 1047 | | |
1041 | 1048 | | |
1042 | 1049 | | |
| 1050 | + | |
1043 | 1051 | | |
1044 | 1052 | | |
1045 | 1053 | | |
| |||
1067 | 1075 | | |
1068 | 1076 | | |
1069 | 1077 | | |
| 1078 | + | |
1070 | 1079 | | |
1071 | 1080 | | |
1072 | 1081 | | |
| |||
1078 | 1087 | | |
1079 | 1088 | | |
1080 | 1089 | | |
1081 | | - | |
| 1090 | + | |
1082 | 1091 | | |
1083 | 1092 | | |
1084 | 1093 | | |
| |||
1113 | 1122 | | |
1114 | 1123 | | |
1115 | 1124 | | |
| 1125 | + | |
1116 | 1126 | | |
1117 | 1127 | | |
1118 | 1128 | | |
| |||
1129 | 1139 | | |
1130 | 1140 | | |
1131 | 1141 | | |
| 1142 | + | |
1132 | 1143 | | |
1133 | 1144 | | |
1134 | 1145 | | |
| |||
0 commit comments