Commit f6290ae
[SPARK-22285][SQL] Change implementation of ApproxCountDistinctForIntervals to TypedImperativeAggregate
## What changes were proposed in this pull request?
The current implementation of `ApproxCountDistinctForIntervals` is `ImperativeAggregate`. The number of `aggBufferAttributes` is the number of total words in the hllppHelper array. Each hllppHelper has 52 words by default relativeSD.
Since this aggregate function is used in equi-height histogram generation, and the number of buckets in histogram is usually hundreds, the number of `aggBufferAttributes` can easily reach tens of thousands or even more.
This leads to a huge method in codegen and causes error:
```
org.codehaus.janino.JaninoRuntimeException: Code of method "apply(Lorg/apache/spark/sql/catalyst/InternalRow;)Lorg/apache/spark/sql/catalyst/expressions/UnsafeRow;" of class "org.apache.spark.sql.catalyst.expressions.GeneratedClass$SpecificUnsafeProjection" grows beyond 64 KB.
```
Besides, huge generated methods also result in performance regression.
In this PR, we change its implementation to `TypedImperativeAggregate`. After the fix, `ApproxCountDistinctForIntervals` can deal with more than thousands endpoints without throwing codegen error, and improve performance from `20 sec` to `2 sec` in a test case of 500 endpoints.
## How was this patch tested?
Test by an added test case and existing tests.
Author: Zhenhua Wang <wangzhenhua@huawei.com>
Closes #19506 from wzhfy/change_forIntervals_typedAgg.1 parent 5a5b6b7 commit f6290ae
File tree
3 files changed
+130
-62
lines changed- sql
- catalyst/src
- main/scala/org/apache/spark/sql/catalyst/expressions/aggregate
- test/scala/org/apache/spark/sql/catalyst/expressions/aggregate
- core/src/test/scala/org/apache/spark/sql
3 files changed
+130
-62
lines changedLines changed: 52 additions & 45 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 50 | + | |
59 | 51 | | |
60 | 52 | | |
61 | 53 | | |
| |||
114 | 106 | | |
115 | 107 | | |
116 | 108 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 109 | + | |
| 110 | + | |
121 | 111 | | |
122 | 112 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 113 | + | |
140 | 114 | | |
141 | 115 | | |
142 | 116 | | |
| |||
153 | 127 | | |
154 | 128 | | |
155 | 129 | | |
156 | | - | |
| 130 | + | |
157 | 131 | | |
158 | 132 | | |
159 | 133 | | |
160 | | - | |
161 | | - | |
| 134 | + | |
| 135 | + | |
162 | 136 | | |
| 137 | + | |
163 | 138 | | |
164 | 139 | | |
165 | 140 | | |
| |||
196 | 171 | | |
197 | 172 | | |
198 | 173 | | |
199 | | - | |
| 174 | + | |
200 | 175 | | |
201 | 176 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
206 | 181 | | |
| 182 | + | |
207 | 183 | | |
208 | 184 | | |
209 | | - | |
| 185 | + | |
210 | 186 | | |
211 | 187 | | |
212 | 188 | | |
| |||
218 | 194 | | |
219 | 195 | | |
220 | 196 | | |
221 | | - | |
| 197 | + | |
222 | 198 | | |
223 | 199 | | |
224 | | - | |
| 200 | + | |
225 | 201 | | |
226 | 202 | | |
227 | 203 | | |
228 | 204 | | |
229 | | - | |
| 205 | + | |
| 206 | + | |
230 | 207 | | |
| 208 | + | |
231 | 209 | | |
232 | | - | |
| 210 | + | |
| 211 | + | |
233 | 212 | | |
| 213 | + | |
234 | 214 | | |
235 | 215 | | |
236 | 216 | | |
| |||
239 | 219 | | |
240 | 220 | | |
241 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
242 | 249 | | |
Lines changed: 17 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 82 | + | |
90 | 83 | | |
91 | 84 | | |
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
95 | | - | |
96 | | - | |
| 88 | + | |
| 89 | + | |
97 | 90 | | |
98 | 91 | | |
99 | 92 | | |
| |||
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
126 | | - | |
| 119 | + | |
127 | 120 | | |
128 | 121 | | |
129 | 122 | | |
| |||
152 | 145 | | |
153 | 146 | | |
154 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments