Commit f2b2453
Fix driver crash when using INTERVAL types (databricks#1085)
## Description
This PR fixes a driver crash that occurs when executing a query
returning an `INTERVAL` type mentioned in
databricks#1083 issue.
Previously, `PreparedStatement.getMetaData()` failed with:
```
IllegalArgumentException: No enum constant ColumnInfoTypeName.INTERVAL DAY TO SECOND
```
This happened because the driver attempted to map interval types to an
enum that did not support multi-word SQL type names such as `INTERVAL
DAY TO SECOND`.
### What has been done
* Added support for INTERVAL types in metadata handling.
* Ensured `DatabricksPreparedStatement.getMetaData()` and supporting
code paths correctly parse and map interval type names.
* Changed visibility of `SIGNED_TYPES` from private to public (just a
suggestion — it seems useful and potentially reusable).
This PR addresses the issue described in *Follow-up databricks#1064* and fixes the
metadata retrieval for interval expressions such as:
```sql
SELECT current_timestamp() - '2025-01-01 00:00:00.0'
SELECT INTERVAL '15' MINUTE
```
---
## Testing
~**Still planning to add automated tests — this is a DRAFT.**~
Manual testing performed so far:
* Used a small Java program (included below) that:
* Prepares a statement returning an interval value.
* Calls `getMetaData()` to verify that no exceptions are thrown.
* Prints metadata fields (type, name, precision, scale, etc.).
* Executes the query and validates that values can be retrieved via both
`getObject()` and `getString()`.
Tested on driver version **3.0.4**.
Before this fix → driver crashes.
With this PR → metadata is returned successfully and the interval value
can be fetched.
### How to manually test the change
You can use the following standalone Java snippet to test the fix
end-to-end:
```java
public static void main(String[] args) {
String url = "...";
Properties props = new Properties();
Driver driver = Driver.getInstance();
try (Connection conn = driver.connect(url, props)) {
try (PreparedStatement st = conn.prepareStatement("SELECT INTERVAL '15' MINUTE")) {
ResultSetMetaData rsmd = st.getMetaData();
System.out.println("=== ResultSetMetaData ===");
System.out.println("Column count: " + rsmd.getColumnCount());
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println("\nColumn " + i + ":");
System.out.println(" Name: " + rsmd.getColumnName(i));
System.out.println(" Label: " + rsmd.getColumnLabel(i));
System.out.println(" Type: " + rsmd.getColumnType(i));
System.out.println(" Type Name: " + rsmd.getColumnTypeName(i));
System.out.println(" Class Name: " + rsmd.getColumnClassName(i));
System.out.println(" Display Size: " + rsmd.getColumnDisplaySize(i));
System.out.println(" Precision: " + rsmd.getPrecision(i));
System.out.println(" Scale: " + rsmd.getScale(i));
}
try (ResultSet rs = st.executeQuery()) {
System.out.println("=== Query Results ===");
while (rs.next()) {
Object value = rs.getObject(1);
String stringValue = rs.getString(1);
System.out.println("Value (Object): " + value);
System.out.println("Value (String): " + stringValue);
System.out.println("Value class: " + (value != null ? value.getClass() : "null"));
}
}
} catch (SQLException e) {
System.err.println("SQL Error: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
}
} catch (SQLException e) {
System.err.println("Connection Error: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
}
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
System.out.printf("\nThe driver {%s} has been initialized.%n", Driver.class);
}
```
---
## Additional Notes to the Reviewer
~* **This PR is a DRAFT** — unit tests will be added before marking it
ready.~
* Early feedback is welcome, especially regarding:
* The chosen mapping strategy for interval types.
* Whether exposing `SIGNED_TYPES` is acceptable.
* Enum / type-parsing paths that may need to be refactored.
* If there are other interval forms worth testing (e.g., `INTERVAL DAY`,
`INTERVAL SECOND`, mixed units), please let me know.
* I’m open to suggestions on where interval-related tests should live in
the test suite.
---------
Signed-off-by: Roman Dryndik <dryndikroman@gmail.com>
Co-authored-by: Samikshya Chand <148681192+samikshya-db@users.noreply.github.com>1 parent e88e562 commit f2b2453
File tree
5 files changed
+72
-3
lines changed- src
- main/java/com/databricks/jdbc
- api/impl
- common/util
- test/java/com/databricks/jdbc
- api/impl
- common/util
5 files changed
+72
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| 459 | + | |
| 460 | + | |
459 | 461 | | |
460 | 462 | | |
461 | 463 | | |
| |||
492 | 494 | | |
493 | 495 | | |
494 | 496 | | |
495 | | - | |
496 | 497 | | |
497 | 498 | | |
498 | 499 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | 56 | | |
58 | 57 | | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| |||
Lines changed: 64 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 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
203 | 266 | | |
204 | 267 | | |
205 | 268 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
287 | 288 | | |
288 | 289 | | |
289 | 290 | | |
| |||
0 commit comments