Commit c2ad803
Fix PreparedStatement.getMetaData() crash for SQL type aliases (#1289)
## Summary
Completes the fix for #1064 — `PreparedStatement.getMetaData()` throws
`IllegalArgumentException` for SQL type aliases.
- `PreparedStatement.getMetaData()` triggers a DESCRIBE QUERY
internally, and the response type names are mapped via
`ColumnInfoTypeName.valueOf()`. SQL type aliases like VARCHAR, INTEGER,
NUMERIC, DEC, REAL, NVARCHAR, NCHAR have no enum entry, causing
`IllegalArgumentException`
- Replace `valueOf()` with `DatabricksTypeUtil.getColumnInfoType()`
which handles all alias mappings and falls back to `USER_DEFINED_TYPE`
instead of crashing
- Extend `getColumnInfoType()` to cover all missing SQL standard
aliases, plus VARIANT, GEOMETRY, GEOGRAPHY, and multi-word INTERVAL
sub-types
- Fix incorrect DATE to TIMESTAMP mapping (DATE is a distinct JDBC type)
**Background:** Issue #1064 reported crashes for BIGINT, SMALLINT,
TINYINT, INTERVAL, VOID, GEOMETRY, GEOGRAPHY. Some of these (BIGINT,
SMALLINT, TINYINT) were already fixed on main by adding enum entries.
This PR addresses the remaining aliases and replaces the fragile
`valueOf()` pattern with a safe mapping function.
## Scope
Changes affect **only** `PreparedStatement.getMetaData()` — the DESCRIBE
QUERY code path. Verified by tracing all call sites:
- `DatabricksTypeUtil.getColumnInfoType()` is called from 2 places:
1. `DatabricksResultSetMetaData` DESCRIBE QUERY constructor (line 453) —
**only used by PreparedStatement.getMetaData()**
2. `DatabricksPreparedStatement` parameter metadata (line 859) — **also
PreparedStatement-only**
- Regular `ResultSet.getMetaData()` uses different constructors that
take `DatabricksColumn` objects from server responses — **unaffected**
- `DatabaseMetaData` operations (`getColumns`, `getTables`, etc.) use
`MetadataResultSetBuilder` — **unaffected**
- Normal query execution — **unaffected**
## Test plan
- [x] DatabricksTypeUtilTest — 83 tests (parameterized tests for all
aliases, INTERVAL sub-types, full type-to-JDBC-code chain)
- [x] DatabricksResultSetMetaDataTest — 28 tests (DESCRIBE QUERY
coverage for GEOGRAPHY, GEOMETRY, BIGINT, SMALLINT, TINYINT, VARCHAR,
INTEGER)
- [x] Full jdbc-core suite — 111 tests pass, 0 failures
- [x] Live E2E verification against dogfood warehouse
## Testing
### Live E2E verification (May 21, 2026)
Tested against dogfood warehouse
(`e2-dogfood.staging.cloud.databricks.com`, warehouse
`dd43ee29fedd958d`).
**Setup:** Created a table with type alias columns to exercise DESCRIBE
QUERY:
```sql
CREATE TABLE main.jdbc_test_schema.type_alias_test_pr1289 (
col_varchar VARCHAR(100),
col_integer INTEGER,
col_numeric NUMERIC(10,2),
col_dec DEC(10,2),
col_real REAL,
col_int INT,
col_string STRING,
col_double DOUBLE,
col_boolean BOOLEAN,
col_date DATE,
col_timestamp TIMESTAMP
)
```
**Test 1: Table with DDL type aliases — PASSED**
```
PreparedStatement ps = conn.prepareStatement("SELECT * FROM type_alias_test_pr1289");
ResultSetMetaData meta = ps.getMetaData();
```
| Column | Type Alias | Returned Type | JDBC Code | Precision | Scale |
|--------|-----------|---------------|-----------|-----------|-------|
| col_varchar | VARCHAR(100) | STRING | 12 | 255 | 0 |
| col_integer | INTEGER | INT | 4 | 10 | 0 |
| col_numeric | NUMERIC(10,2) | DECIMAL | 3 | 10 | 2 |
| col_dec | DEC(10,2) | DECIMAL | 3 | 10 | 2 |
| col_real | REAL | FLOAT | 6 | 7 | 0 |
| col_int | INT | INT | 4 | 10 | 0 |
| col_string | STRING | STRING | 12 | 255 | 0 |
| col_double | DOUBLE | DOUBLE | 8 | 15 | 0 |
| col_boolean | BOOLEAN | BOOLEAN | 16 | 1 | 0 |
| col_date | DATE | DATE | 91 | 10 | 0 |
| col_timestamp | TIMESTAMP | TIMESTAMP | 93 | 29 | 9 |
**Test 2: CAST expressions with type aliases — PASSED**
```sql
SELECT CAST('hello' AS VARCHAR(100)), CAST(2 AS INTEGER),
CAST(3.14 AS NUMERIC(10,2)), CAST(4.14 AS DEC(10,2)), CAST(5.0 AS REAL)
```
All 5 columns returned correct metadata without
`IllegalArgumentException`.
**Test 3: Standard types (regression) — PASSED**
```sql
SELECT CAST(1 AS INT), CAST('hello' AS STRING), CAST(1.5 AS DOUBLE)
```
**Test 4: INTERVAL type — PASSED**
```sql
SELECT INTERVAL '1' YEAR as col_interval
```
Returned `type=INTERVAL YEAR (12)`.
**Test 5: VARIANT type — PASSED**
```sql
SELECT PARSE_JSON('{"key": "value"}') as col_variant
```
Returned `type=VARIANT (12)`.
### Before-fix behavior (reproduced via unit test)
Without the fix, `PreparedStatement.getMetaData()` on any query
returning VARCHAR, INTEGER, NUMERIC, DEC, or REAL columns throws:
```
java.lang.IllegalArgumentException: No enum constant
com.databricks.jdbc.common.ColumnInfoTypeName.VARCHAR
at java.lang.Enum.valueOf(Enum.java:273)
at DatabricksResultSetMetaData.<init>(DatabricksResultSetMetaData.java:454)
```
Closes #1064
This pull request was AI-assisted by Isaac.
---------
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 06476c8 commit c2ad803
32 files changed
Lines changed: 391 additions & 302 deletions
File tree
- src
- main/java/com/databricks/jdbc
- api/impl
- common/util
- test
- java/com/databricks/jdbc
- api/impl
- common/util
- resources
- cloudfetchapi/preparedstatementintegrationtests/testsetdate/mappings
- sqlexecapi/preparedstatementintegrationtests/testsetdate/mappings
- thriftserverapi/preparedstatementintegrationtests/testsetdate/mappings
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
| |||
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| 73 | + | |
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
| |||
Lines changed: 5 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
455 | | - | |
456 | | - | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
457 | 459 | | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | 460 | | |
467 | 461 | | |
468 | 462 | | |
| |||
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
59 | 66 | | |
60 | 67 | | |
61 | 68 | | |
| |||
73 | 80 | | |
74 | 81 | | |
75 | 82 | | |
76 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
77 | 89 | | |
78 | 90 | | |
79 | 91 | | |
| 92 | + | |
80 | 93 | | |
81 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
82 | 97 | | |
| 98 | + | |
83 | 99 | | |
84 | 100 | | |
85 | 101 | | |
| |||
91 | 107 | | |
92 | 108 | | |
93 | 109 | | |
| 110 | + | |
94 | 111 | | |
95 | 112 | | |
96 | 113 | | |
97 | 114 | | |
98 | 115 | | |
| 116 | + | |
99 | 117 | | |
100 | 118 | | |
101 | 119 | | |
| |||
104 | 122 | | |
105 | 123 | | |
106 | 124 | | |
| 125 | + | |
| 126 | + | |
107 | 127 | | |
108 | 128 | | |
109 | 129 | | |
| |||
118 | 138 | | |
119 | 139 | | |
120 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
121 | 149 | | |
122 | 150 | | |
123 | 151 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
203 | 210 | | |
204 | 211 | | |
205 | 212 | | |
| |||
Lines changed: 55 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| 281 | + | |
280 | 282 | | |
281 | 283 | | |
282 | 284 | | |
283 | 285 | | |
| 286 | + | |
| 287 | + | |
284 | 288 | | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
288 | 292 | | |
289 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
290 | 297 | | |
291 | 298 | | |
292 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
293 | 306 | | |
294 | 307 | | |
295 | 308 | | |
| |||
300 | 313 | | |
301 | 314 | | |
302 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
303 | 356 | | |
304 | 357 | | |
305 | 358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
This file was deleted.
0 commit comments