Commit af79d14
authored
Make translate emit Utf8View for Utf8View input (#20624)
## Which issue does this PR close?
- Part of #20585
<!--
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.
-->
## Rationale for this change
String UDFs should preserve string representation where feasible.
`translate` previously accepted Utf8View input but emitted Utf8, causing
an unnecessary type downgrade. This aligns `translate` with the expected
behavior of returning the same string type as its primary input.
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
1. Updated `translate` return type inference to emit Utf8View when input
is Utf8View, while preserving existing behavior for Utf8 and LargeUtf8.
2. Refactored `translate` and `translate_with_map` to use explicit
string builders (via a local `TranslateOutput` helper trait) instead of
`.collect::<GenericStringArray<T>>()`, so the correct output array type
is produced for each input type.
3. Added unit tests for Utf8View input (basic, null, non-ASCII) and
sqllogictests verifying `arrow_typeof` output for all three string
types.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
Yes. Unit tests and sqllogictests are included.
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
No.
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->1 parent 39226c3 commit af79d14
2 files changed
Lines changed: 126 additions & 46 deletions
File tree
- datafusion
- functions/src/unicode
- sqllogictest/test_files/string
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
| 124 | + | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
| 130 | + | |
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
132 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
136 | 141 | | |
| 142 | + | |
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
141 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
145 | 153 | | |
| 154 | + | |
146 | 155 | | |
147 | 156 | | |
148 | 157 | | |
| |||
172 | 181 | | |
173 | 182 | | |
174 | 183 | | |
| 184 | + | |
175 | 185 | | |
176 | 186 | | |
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
180 | | - | |
| 190 | + | |
| 191 | + | |
181 | 192 | | |
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
185 | 196 | | |
186 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
187 | 200 | | |
188 | 201 | | |
189 | 202 | | |
190 | 203 | | |
191 | 204 | | |
192 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
193 | 208 | | |
194 | 209 | | |
195 | 210 | | |
| |||
199 | 214 | | |
200 | 215 | | |
201 | 216 | | |
202 | | - | |
| 217 | + | |
203 | 218 | | |
204 | 219 | | |
205 | 220 | | |
| 221 | + | |
206 | 222 | | |
207 | 223 | | |
208 | 224 | | |
209 | 225 | | |
| 226 | + | |
210 | 227 | | |
211 | 228 | | |
212 | 229 | | |
| |||
219 | 236 | | |
220 | 237 | | |
221 | 238 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
226 | 242 | | |
227 | 243 | | |
228 | 244 | | |
| |||
254 | 270 | | |
255 | 271 | | |
256 | 272 | | |
257 | | - | |
| 273 | + | |
258 | 274 | | |
259 | | - | |
260 | | - | |
261 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
262 | 278 | | |
263 | | - | |
| 279 | + | |
264 | 280 | | |
265 | 281 | | |
266 | 282 | | |
| |||
300 | 316 | | |
301 | 317 | | |
302 | 318 | | |
303 | | - | |
| 319 | + | |
304 | 320 | | |
305 | 321 | | |
306 | 322 | | |
307 | 323 | | |
| 324 | + | |
308 | 325 | | |
309 | 326 | | |
310 | 327 | | |
| 328 | + | |
311 | 329 | | |
312 | 330 | | |
313 | 331 | | |
314 | 332 | | |
315 | | - | |
316 | | - | |
317 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
318 | 336 | | |
319 | 337 | | |
320 | 338 | | |
| |||
327 | 345 | | |
328 | 346 | | |
329 | 347 | | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
343 | 361 | | |
| 362 | + | |
344 | 363 | | |
345 | | - | |
346 | 364 | | |
347 | | - | |
348 | 365 | | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
353 | 372 | | |
354 | | - | |
| 373 | + | |
355 | 374 | | |
356 | 375 | | |
357 | 376 | | |
358 | 377 | | |
359 | | - | |
360 | | - | |
| 378 | + | |
| 379 | + | |
361 | 380 | | |
362 | 381 | | |
363 | 382 | | |
| |||
453 | 472 | | |
454 | 473 | | |
455 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
456 | 514 | | |
457 | 515 | | |
458 | 516 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1783 | 1783 | | |
1784 | 1784 | | |
1785 | 1785 | | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
0 commit comments