Commit 9a6ac72
committed
[SPARK-19601][SQL] Fix CollapseRepartition rule to preserve shuffle-enabled Repartition
### What changes were proposed in this pull request?
Observed by felixcheung in #16739, when users use the shuffle-enabled `repartition` API, they expect the partition they got should be the exact number they provided, even if they call shuffle-disabled `coalesce` later.
Currently, `CollapseRepartition` rule does not consider whether shuffle is enabled or not. Thus, we got the following unexpected result.
```Scala
val df = spark.range(0, 10000, 1, 5)
val df2 = df.repartition(10)
assert(df2.coalesce(13).rdd.getNumPartitions == 5)
assert(df2.coalesce(7).rdd.getNumPartitions == 5)
assert(df2.coalesce(3).rdd.getNumPartitions == 3)
```
This PR is to fix the issue. We preserve shuffle-enabled Repartition.
### How was this patch tested?
Added a test case
Author: Xiao Li <[email protected]>
Closes #16933 from gatorsmile/CollapseRepartition.1 parent 5f7d835 commit 9a6ac72
File tree
7 files changed
+178
-49
lines changed- R/pkg/inst/tests/testthat
- sql
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst
- dsl
- optimizer
- plans/logical
- test/scala/org/apache/spark/sql/catalyst/optimizer
- core/src
- main/scala/org/apache/spark/sql
- test/scala/org/apache/spark/sql/execution
7 files changed
+178
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2592 | 2592 | | |
2593 | 2593 | | |
2594 | 2594 | | |
2595 | | - | |
2596 | | - | |
| 2595 | + | |
| 2596 | + | |
2597 | 2597 | | |
2598 | 2598 | | |
2599 | 2599 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
| |||
Lines changed: 14 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
| 567 | + | |
573 | 568 | | |
574 | 569 | | |
575 | 570 | | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
588 | 584 | | |
589 | 585 | | |
590 | 586 | | |
| |||
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
845 | 854 | | |
846 | 855 | | |
847 | 856 | | |
848 | 857 | | |
849 | 858 | | |
850 | 859 | | |
851 | 860 | | |
852 | | - | |
| 861 | + | |
853 | 862 | | |
854 | | - | |
855 | 863 | | |
856 | 864 | | |
857 | 865 | | |
| |||
863 | 871 | | |
864 | 872 | | |
865 | 873 | | |
866 | | - | |
| 874 | + | |
867 | 875 | | |
868 | 876 | | |
869 | 877 | | |
870 | 878 | | |
871 | | - | |
| 879 | + | |
872 | 880 | | |
873 | 881 | | |
874 | 882 | | |
| |||
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/CollapseRepartitionSuite.scala
Lines changed: 137 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
35 | 53 | | |
36 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
37 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
38 | 99 | | |
39 | 100 | | |
40 | | - | |
| 101 | + | |
| 102 | + | |
41 | 103 | | |
42 | 104 | | |
43 | | - | |
| 105 | + | |
| 106 | + | |
44 | 107 | | |
45 | 108 | | |
46 | | - | |
47 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
48 | 112 | | |
49 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
50 | 117 | | |
51 | | - | |
| 118 | + | |
| 119 | + | |
52 | 120 | | |
53 | 121 | | |
54 | | - | |
| 122 | + | |
| 123 | + | |
55 | 124 | | |
56 | 125 | | |
57 | | - | |
58 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
59 | 133 | | |
60 | | - | |
61 | 134 | | |
62 | | - | |
63 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
64 | 138 | | |
65 | | - | |
| 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 | + | |
66 | 181 | | |
67 | 182 | | |
68 | 183 | | |
69 | | - | |
| 184 | + | |
| 185 | + | |
70 | 186 | | |
71 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
72 | 191 | | |
73 | | - | |
| 192 | + | |
| 193 | + | |
74 | 194 | | |
75 | 195 | | |
76 | | - | |
| 196 | + | |
| 197 | + | |
77 | 198 | | |
78 | 199 | | |
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2441 | 2441 | | |
2442 | 2442 | | |
2443 | 2443 | | |
2444 | | - | |
2445 | | - | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
2449 | 2449 | | |
2450 | 2450 | | |
2451 | 2451 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
246 | 246 | | |
247 | | - | |
248 | | - | |
249 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| |||
0 commit comments