Commit 81f065f
committed
fix(backend/kernel): comparator parity — async statement retention + intervals_as_string + precision/scale
Three parity-blocking issues surfaced by the python-comparator audit
(tests/comparator-tests/python/), bundled into one PR since they're all
small kernel-backend client changes.
## 1. Async Statement retention (original scope of this PR)
`KernelDatabricksClient.execute_command` closed the parent `Statement`
in `finally` regardless of `async_op`. The kernel's `Statement.close()`
invalidates child handles (see `databricks-sql-kernel/src/statement/
validity.rs`), so the async handle was being killed before the user
could poll it, breaking the entire async surface
(`execute_async` → `is_query_pending` → `get_async_execution_result`).
Fix: when `async_op=True`, retain the parent Statement in a new
`_async_statements` dict alongside `_async_handles`, and close it from
`close_command`, `close_session`, and `get_execution_result` after the
executed handle is done.
Comparator outcome: STATEMENT_ASYNC suite 3/3 match (was 0/3).
## 2. intervals_as_string wire-through (companion to kernel PR #64)
pyarrow's Python bindings cannot decode Arrow's `month_interval` type
at all (id 21 — raises `KeyError` from `.as_py`, `to_pylist`,
`cast(string)`, `to_pandas`). Every kernel-backend `SELECT *` over any
table with an INTERVAL YEAR TO MONTH column was throwing
`ArrowNotImplementedError` — 32/88 audit diffs.
Fix: pass `intervals_as_string=True` to the kernel `Session(...)`
constructor unconditionally. The kernel post-processor then stringifies
Interval / Duration columns server-side to Utf8 (see kernel PR #64), so
pyarrow never sees the unreadable type.
Comparator outcome: bucket A (ArrowNotImplementedError) drops from
32 → 0 diffs.
## 3. Decimal precision/scale extraction (new)
`description_from_arrow_schema` hard-coded `None` for slots 4 and 5 of
the PEP 249 description tuple. For DECIMAL columns the Arrow schema
carries precision/scale on `Decimal128Type.precision` / `.scale`, but
we were silently dropping them — so kernel-backend
`cursor.description[i]` returned
`('decimal_column', 'decimal', None, None, None, None, None)` while
Thrift returned
`('decimal_column', 'decimal', None, None, 10, 2, None)`.
That diff propagates to any consumer that reads PEP 249 slots 4/5
(SQLAlchemy, pandas-read-sql, etc.) so they can't tell DECIMAL(10,2)
from DECIMAL(38,18) on the kernel backend. 88 comparator diffs (44
precision + 44 scale).
Fix: factor out `_precision_scale_for_arrow_type(arrow_type)` and call
it from the description builder. Today it only handles decimals;
future extensions (e.g. fractional-second precision from `Time64Type`)
slot in here without touching the description builder.
Comparator outcome: 88 precision+scale diffs → 0.
## Dependencies
Both intervals_as_string and the empty-result schema fix in kernel
PR #64 are required for the parity gains to land. The driver-side
fixes here work standalone but the comparator outcome numbers assume
PR #64 is also live.
## Headline comparator results
- Before this PR (and PR #64): 60 match / 88 diff (out of 148)
- After this PR + PR #64: 103 match / 45 diff
- 17 of 30 (connection_config × suite) pairs now fully clean.
- Remaining 45 diffs cluster into 4 known causes documented in
~/docs/python-kernel/comparator-diff-tasklist.md (complex types in
fetchall_arrow path, timestamp tz, VOID, METADATA pattern matching).
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>1 parent fb55001 commit 81f065f
2 files changed
Lines changed: 110 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
| |||
167 | 176 | | |
168 | 177 | | |
169 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
170 | 189 | | |
171 | 190 | | |
172 | 191 | | |
| |||
197 | 216 | | |
198 | 217 | | |
199 | 218 | | |
| 219 | + | |
200 | 220 | | |
| 221 | + | |
201 | 222 | | |
202 | 223 | | |
203 | 224 | | |
| |||
211 | 232 | | |
212 | 233 | | |
213 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
214 | 245 | | |
215 | 246 | | |
216 | 247 | | |
| |||
249 | 280 | | |
250 | 281 | | |
251 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
252 | 288 | | |
253 | 289 | | |
254 | 290 | | |
| |||
262 | 298 | | |
263 | 299 | | |
264 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
265 | 307 | | |
266 | 308 | | |
267 | 309 | | |
268 | 310 | | |
269 | 311 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
280 | 321 | | |
281 | 322 | | |
282 | 323 | | |
| |||
307 | 348 | | |
308 | 349 | | |
309 | 350 | | |
| 351 | + | |
310 | 352 | | |
311 | 353 | | |
312 | 354 | | |
313 | 355 | | |
314 | 356 | | |
315 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
316 | 366 | | |
317 | 367 | | |
318 | 368 | | |
319 | 369 | | |
320 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
321 | 379 | | |
322 | 380 | | |
323 | 381 | | |
| |||
378 | 436 | | |
379 | 437 | | |
380 | 438 | | |
| 439 | + | |
381 | 440 | | |
382 | 441 | | |
383 | 442 | | |
| |||
387 | 446 | | |
388 | 447 | | |
389 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
390 | 461 | | |
391 | 462 | | |
392 | 463 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
112 | | - | |
113 | | - | |
| 120 | + | |
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
117 | 124 | | |
118 | 125 | | |
119 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
120 | 146 | | |
121 | 147 | | |
122 | 148 | | |
| |||
0 commit comments