Commit c7e9284
authored
refactor: use raw view access in do_append_val_inner and consolidate duplicated logic (#22907)
## Which issue does this PR close?
Follow-up to #21794, addressing review feedback from @alamb and
@Dandandan.
## Rationale for this change
In the review of #21794, several optimizations were suggested:
- **@alamb**
([comment](#21794 (comment))):
"as a possible future optimization, we could use `get_unchecked` here if
it makes any difference" — referring to the slow-path `arr.views()[row]`
access.
- **@alamb**
([comment](#21794 (comment))):
"from here on down I think this is basically the same as
append_val_inner -- if there are any differences perhaps we can fold it
into append_val_inner and avoid the copy"
- **@Dandandan**
([comment](#21794 (comment))):
"In principle we can make this faster as well - `extend` + reuse input
view (instead of make_view) + avoid `array.value(row)`"
## What changes are included in this PR?
**1. Refactored `do_append_val_inner` to use raw view access**
Replaced `array.value(row)` + `make_view()` with raw view access via
`get_unchecked(row)`:
- **Inline (len <= 12):** push the u128 view as-is — no decode/re-encode
round-trip
- **Non-inline (len > 12):** parse via `ByteView::from(view)`, copy
buffer data, reuse source prefix directly (avoids re-reading first 4
bytes)
**2. Simplified the vectorized slow path**
Replaced the duplicated 28-line loop body in `vectorized_append_inner`
with `try_reserve` + a loop calling `do_append_val_inner`, eliminating
code duplication.
**3. Removed unused `make_view` import**
### Safety notes
- **`get_unchecked` usage**: Consistent with `do_equal_to_inner` (same
file) and `PrimitiveGroupValueBuilder` in `primitive.rs`, both of which
use the same pattern. All callers derive row indices from enumeration
over the input array length, guaranteeing validity.
- **Buffer access safety**: When `data_buffers()` is empty, all views
must have len <= 12 (Arrow invariant), so the non-inline branch is never
entered.
## Are these changes tested?
Covered by 6 existing unit tests in the `bytes_view` module plus 3
integration tests in the `multi_group_by` module. All 111 tests in the
aggregates suite pass.
## Are there any user-facing changes?
No. This is an internal refactor with no API changes.1 parent 408dad3 commit c7e9284
1 file changed
Lines changed: 29 additions & 48 deletions
Lines changed: 29 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | | - | |
180 | | - | |
181 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
182 | 181 | | |
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 188 | + | |
216 | 189 | | |
217 | 190 | | |
218 | 191 | | |
| |||
230 | 203 | | |
231 | 204 | | |
232 | 205 | | |
233 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
234 | 209 | | |
235 | | - | |
236 | | - | |
237 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
238 | 213 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
252 | 233 | | |
253 | 234 | | |
254 | 235 | | |
| |||
0 commit comments