ResultSetMetadata of the ResultSet from DatabaseMetadata.getColumns() is Incorrect for Some Columns #1751
Labels
Backlog
The topic in question has been recognized and added to development backlog
Driver version
10.2.0
SQL Server version
Microsoft Azure SQL Data Warehouse - 10.0.13655.0 Oct 23 2021 03:49:53 Copyright (c) Microsoft Corporation
Client Operating System
Windows 10/RHEL 7
JAVA/JVM version
Corretto 11.0.10_9
Table schema
Note that the attached test program will create/drop the above database objects
Problem description
The ResultSetMetaData.getColumnClassName (and also ResultSetMetaData.getColumnType) of the ResultSet returned by DatabaseMetaData.getColumns() return incorrect values per the JDBC API specification for ResultSetMetadata.getColumns(). (https://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html#getColumns-java.lang.String-java.lang.String-java.lang.String-java.lang.String-).
Expected behavior
The DatabaseMetaData.getColumns(...).getColumnClassName(x) should either be the class specified in the API, or assignable to class in the spec.
For DatabaseMetaData.getColumns().getColumnType(i), the values are not as prescribed, but obviously something with Types.INTEGER will not produce a String and vice-versa.
Actual behavior
The output of the attached test program shows which columns are wrong per the spec given the simple schema above with one table and one view.
Any other details that can be helpful
From debugging the code the problem arises in SQLServerDatabaseMetaData.generateAzureDWSelect and SQLServerDatabaseMetaData.generateAzureDWEmptyRS because the are generating UNIONs of SQL literals retrieved from the sp_columns_100 procedure. The generated SQL then looks like the following for the above table when making the call getColumns(null, null, "test_get_cols_rsmd_t", null):
The issue lies in the untyped NULLs and numbers (for the columns which should be shorts). Each generated NULL literal and number should be wrapped in a convert/cast to the correct type.
mssql-synapse-get-columns-bug.tar.gz
The text was updated successfully, but these errors were encountered: