Commit 4cffa4b
fix: Array_intersect with a single argument doesn't correctly handle nulls in dictionary encoded inner arrays (#11807)
Summary:
Pull Request resolved: #11807
The single argument flavor of array_intersect computes the intersection of the inner arrays in an array of arrays.
It currently does not correctly handle nulls in the dictionary if the inner arrays are dictionary encoded.
There are 2 bugs:
1) toElementRows requires that nulls be deselected in the SelectivityVector, array_intersect does not do this
when calling it on the inner arrays. This means it will attempt to use the index from the DecodedVector's
indices() to get the offset and size of the null arrays, which can lead to accessing arbitrary memory as the index
may point off the end of the buffers getting the size and offset, which can further lead to writing to arbitrary
memory as we can write off the end of the SelectivityVector.
2) When actually doing the intersection we get the innerOffset and innerSize before checking if the inner array
is null. We don't end up using these values if the inner array is null, so this just results in an error when ASAN is
enabled.
To fix 1) I created separate APIs for toElementRows for use with DecodedVectors and otherwise. It forces the
user to pass in the nulls from the DecodedVector in addition to the indices to help avoid mistakes like this.
Note that this worked in PrestoHasher because it was correctly deselecting nulls in the SelectivityVector, and in
WidthBucketArray because it has default null behavior so the nulls would have been automatically deselected
by the expression eval code.
Reviewed By: spershin
Differential Revision: D66994602
fbshipit-source-id: 1c14bfaab886e692aae09b555cd6d2971e3deb721 parent 1bd480e commit 4cffa4b
File tree
5 files changed
+59
-31
lines changed- velox/functions
- lib
- prestosql
- aggregates
- tests
5 files changed
+59
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
34 | | - | |
| 32 | + | |
35 | 33 | | |
36 | | - | |
| 34 | + | |
| 35 | + | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | | - | |
| 48 | + | |
51 | 49 | | |
52 | | - | |
| 50 | + | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
| |||
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
| 248 | + | |
253 | 249 | | |
254 | 250 | | |
255 | | - | |
| 251 | + | |
256 | 252 | | |
257 | 253 | | |
258 | 254 | | |
| |||
263 | 259 | | |
264 | 260 | | |
265 | 261 | | |
266 | | - | |
267 | 262 | | |
268 | 263 | | |
269 | 264 | | |
| |||
285 | 280 | | |
286 | 281 | | |
287 | 282 | | |
| 283 | + | |
288 | 284 | | |
289 | 285 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | 286 | | |
296 | | - | |
| 287 | + | |
297 | 288 | | |
298 | 289 | | |
299 | 290 | | |
| |||
309 | 300 | | |
310 | 301 | | |
311 | 302 | | |
312 | | - | |
313 | 303 | | |
314 | 304 | | |
315 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
0 commit comments