Commit 3c0f7e4
authored
[ES-1804970] Fix CloudFetch returning stale column names from cached results (#351)
## Summary
Fixes a bug where `arrow.Record.Schema()` returns stale column aliases
when CloudFetch serves cached Arrow IPC files from a structurally
identical prior query with different `AS` aliases.
- **Root cause:** `NewCloudBatchIterator` was not receiving the
authoritative schema bytes from `GetResultSetMetadata`, unlike the local
batch path which already had this. CloudFetch Arrow IPC files have
column names baked in from the original query, and the driver was
reading them as-is.
- **Fix:** Pass `arrowSchemaBytes` (the authoritative schema from
`GetResultSetMetadata`) into `NewCloudBatchIterator`. After records are
deserialized from the IPC stream, replace the stale schema with the
authoritative one using `array.NewRecord()` (zero-copy — shares
underlying column data, only swaps metadata).
## Changes
- **`arrowRecordIterator.go`** — Pass `ri.arrowSchemaBytes` to
`NewCloudBatchIterator` in `newBatchIterator()`
- **`arrowRows.go`** — Pass `schemaBytes` to `NewCloudBatchIterator` in
`NewArrowRowScanner()`
- **`batchloader.go`** — Core fix:
- `NewCloudBatchIterator` accepts `arrowSchemaBytes`, parses into
`*arrow.Schema`, stores on `batchIterator`
- `batchIterator.Next()` applies override schema to CloudFetch records
only (local path is untouched, `overrideSchema` is `nil`)
- Added `schemaFromIPCBytes()` helper
- Field count validation guard to prevent panics on schema mismatch
- Schema parse failure logged at `Warn` level
- **`batchloader_test.go`** — Added `TestCloudFetchSchemaOverride` with
two subtests:
- Verifies stale column names `["id","name"]` are overridden to
`["x","y"]`
- Verifies `nil` schema bytes pass through original names unchanged
## Who is affected
Go driver users with CloudFetch enabled (`WithCloudFetch(true)`) who
read `arrow.Record.Schema()` directly. Python, ODBC, and JDBC drivers
are not affected.
## Test plan
- [x] All existing unit tests pass (37 tests in
`internal/rows/arrowbased/`)
- [x] New unit test `TestCloudFetchSchemaOverride` covers the override
and no-override paths
- [x] Verified end-to-end against a real Databricks warehouse using
`samples.tpch.lineitem` (~30M rows) with two queries differing only in
column aliases — confirmed `arrow.Record.Schema()` now returns correct
aliases
This pull request was AI-assisted by Isaac.
---------
Signed-off-by: Sreekanth Vadigi <sreekanth.vadigi@databricks.com>1 parent 305e3bc commit 3c0f7e4
4 files changed
Lines changed: 172 additions & 6 deletions
File tree
- internal/rows/arrowbased
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
71 | 76 | | |
72 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
73 | 92 | | |
74 | 93 | | |
75 | 94 | | |
| |||
416 | 435 | | |
417 | 436 | | |
418 | 437 | | |
| 438 | + | |
419 | 439 | | |
420 | 440 | | |
421 | 441 | | |
| |||
437 | 457 | | |
438 | 458 | | |
439 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
440 | 478 | | |
441 | 479 | | |
442 | 480 | | |
| |||
459 | 497 | | |
460 | 498 | | |
461 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| 216 | + | |
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
| |||
286 | 289 | | |
287 | 290 | | |
288 | 291 | | |
| 292 | + | |
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| |||
325 | 329 | | |
326 | 330 | | |
327 | 331 | | |
| 332 | + | |
328 | 333 | | |
329 | 334 | | |
330 | 335 | | |
| |||
340 | 345 | | |
341 | 346 | | |
342 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
343 | 461 | | |
344 | 462 | | |
345 | 463 | | |
| |||
388 | 506 | | |
389 | 507 | | |
390 | 508 | | |
391 | | - | |
| 509 | + | |
392 | 510 | | |
393 | 511 | | |
394 | 512 | | |
| |||
439 | 557 | | |
440 | 558 | | |
441 | 559 | | |
442 | | - | |
| 560 | + | |
443 | 561 | | |
444 | 562 | | |
445 | 563 | | |
| |||
0 commit comments