Commit 3ef8603
authored
Fix DatabaseMetaData.getColumns() returning type name in COLUMN_DEF for columns with no default (#1270)
## Summary
- `COLUMN_DEF` (column 13 of `getColumns()`) was returning the column's
**type name** instead of `null` for columns with no default value,
violating the JDBC spec.
- Root cause: `COLUMN_DEF_COLUMN` was mapped to the `"columnType"`
result-set field, so both the SQL path (default switch case) and the
Thrift path (explicit `case "COLUMN_DEF"`) returned the type name.
- Neither `SHOW COLUMNS` nor the Thrift `TGetColumns` RPC exposes column
default values, so `COLUMN_DEF` must always be `null` for now.
- Fix: added `COLUMN_DEF_COLUMN` to `NULL_COLUMN_COLUMNS` (handles the
Thrift path) and added an explicit `case "COLUMN_DEF": object = null` in
`getRows()` (handles the SQL path).
## Test plan
- added uts
- Tested with legacy driver too : we return null only if it is null, we
don't have a way to determine if default has been set
```
Driver: DatabricksJDBC v02.07.06.1023
id: TYPE_NAME=INT, COLUMN_DEF=null
name: TYPE_NAME=STRING, COLUMN_DEF=null
description: TYPE_NAME=VARCHAR, COLUMN_DEF=null
status: TYPE_NAME=STRING, COLUMN_DEF=null ← has DEFAULT 'active'
score: TYPE_NAME=INT, COLUMN_DEF=null ← has DEFAULT 0
```
Test :
```
String catalog = "samikshya-catalog";
String schema = "newschema";
String table = "simba_test_column_def";
con.createStatement().execute(
"CREATE TABLE IF NOT EXISTS `" + catalog + "`.`" + schema +
"`.`" + table + "`"
+ " (id INT NOT NULL, name STRING NOT NULL, description
VARCHAR(255),"
+ " status STRING NOT NULL DEFAULT 'active', score INT
DEFAULT 0)"
+ " TBLPROPERTIES('delta.feature.allowColumnDefaults' =
'supported')");
try (ResultSet rs = con.getMetaData().getColumns(catalog, schema,
table, null)) {
while (rs.next()) {
System.out.println(rs.getString("COLUMN_NAME")
+ ": TYPE_NAME=" + rs.getString("TYPE_NAME")
+ ", COLUMN_DEF=" + rs.getString("COLUMN_DEF"));
}
}
con.createStatement().execute("DROP TABLE IF EXISTS `" + catalog +
"`.`" + schema + "`.`" + table + "`");
con.close();
}
}
```
Closes #1267
---------
Signed-off-by: samikshya-chand_data <samikshya.chand@databricks.com>1 parent 93cf304 commit 3ef8603
3 files changed
Lines changed: 65 additions & 3 deletions
File tree
- src
- main/java/com/databricks/jdbc/dbclient/impl/common
- test/java/com/databricks/jdbc/dbclient/impl/common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
687 | 691 | | |
688 | 692 | | |
689 | 693 | | |
| |||
1412 | 1416 | | |
1413 | 1417 | | |
1414 | 1418 | | |
1415 | | - | |
1416 | | - | |
1417 | | - | |
1418 | 1419 | | |
1419 | 1420 | | |
1420 | 1421 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
769 | 829 | | |
0 commit comments