Commit 440f8e8
fix(csharp): preserve schema for empty result sets in SEA mode (PECO-2949) (#325)
## Problem
When executing a query against an empty table via the Statement
Execution API (SEA / REST mode), the `ResultManifest` always contains
column schema even when `totalRowCount` is 0. However, `CreateReader`
fell through to `EmptyArrowArrayStream` which always returned `new
Schema.Builder().Build()` (zero fields), silently discarding the
manifest schema.
This means callers of `IArrowArrayStream.Schema` received a schema with
no columns for any empty-table query in SEA mode, making it impossible
to inspect column metadata without actually having data rows.
## Root Cause
`EmptyArrowArrayStream` was schema-unaware — it hardcoded an empty
schema regardless of context. The `CreateReader` branching logic only
extracted schema from the manifest in the CloudFetch and inline-data
paths, not in the empty-result fallback path.
## Fix
Follow the JDBC driver pattern where `DatabricksResultSetMetaData` is
always constructed from `ResultManifest` independently of data presence:
- Refactor `GetSchemaFromManifest` into a null-returning
`TryGetSchemaFromManifest` helper
- In the no-data branch of `CreateReader`, extract schema from manifest
and pass it to `EmptyArrowArrayStream`
- Make `EmptyArrowArrayStream` accept an optional `Schema` parameter
(defaults to empty schema for the null-manifest / DDL case)
## Tests
Added `StatementExecutionEmptyResultSchemaTests` with 3 unit tests:
- `ExecuteQuery_EmptyTable_SchemaContainsCorrectColumns` — column names
preserved for empty table
- `ExecuteQuery_EmptyTable_ArrowTypesAreMappedCorrectly` —
INT/BIGINT/STRING/BOOLEAN/DOUBLE/DATE/TIMESTAMP all map correctly
- `ExecuteQuery_NullManifest_ReturnsEmptySchema` — null manifest (DDL)
still returns empty schema without error
## Known CI Failure (Pre-existing)
`TelemetryTests.CanEnableFileTracingExporterViaEnvVariable(exporterName:
"adbcfile")` fails with the `c078a8ec` version of the hiveserver2
submodule (current `main` baseline). This failure is **unrelated to this
PR** — the same test passes in PR #282 which updates the submodule to
`e42efb47`. Once PR #282 merges, this failure will be resolved.
The failure is caused by a bug in `TelemetryTests.cs` line 69:
`Assert.True(string.IsNullOrEmpty(tc.ActivitySourceName))` should be
`Assert.False`. The assertion exception is swallowed by the catch block,
leaving `activitySourceName` as `""` and the trace file
unclosed/unflushed before the length check.
Closes PECO-2949
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 9f7d8ec commit 440f8e8
File tree
3 files changed
+244
-4
lines changed- csharp
- src/StatementExecution
- test/Unit/StatementExecution
3 files changed
+244
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
Lines changed: 28 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
409 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
410 | 415 | | |
411 | 416 | | |
412 | 417 | | |
| |||
442 | 447 | | |
443 | 448 | | |
444 | 449 | | |
| 450 | + | |
445 | 451 | | |
446 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
447 | 464 | | |
448 | 465 | | |
449 | 466 | | |
450 | | - | |
| 467 | + | |
451 | 468 | | |
452 | 469 | | |
453 | 470 | | |
| |||
613 | 630 | | |
614 | 631 | | |
615 | 632 | | |
| 633 | + | |
| 634 | + | |
616 | 635 | | |
617 | 636 | | |
618 | 637 | | |
619 | | - | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
620 | 644 | | |
621 | 645 | | |
622 | 646 | | |
| |||
Lines changed: 213 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 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 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 | + | |
0 commit comments