Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS_AUTOINCREMENT & IS_GENERATEDCOLUMN returning the incorrect type (Azure DW) #1352

Closed
tsegall opened this issue Jun 4, 2020 · 6 comments
Closed

Comments

@tsegall
Copy link

tsegall commented Jun 4, 2020

Driver version

8.2.0

SQL Server version

Microsoft Azure SQL Data Warehouse - 10.0.11115.0 May 16 2020 02:43:26 Copyright (c) Microsoft Corporation

Client Operating System

MacOS X 10.15.4 (although the problem is present on both Windows & Linux)

JAVA/JVM version

OpenJDK Runtime Environment Corretto-8.202.08.2 (build 1.8.0_202-b08)

Table schema

Problem description

  1. Expected Behavior
    databaseMetaData.getColumns(catalog, schema, tableName, null))
    should return the correct type for all columns

  2. Actual behaviour:
    The correct type is not returned for the columns IS_AUTOINCREMENT and IS_GENERATEDCOLUMN. These are returned as type 4 (Int) when they should actually be a string. This means that when you attempt to do a resultSet.getInt() you receive a ClassCastException. The actual value should be YES or NO - so the issue is that the type being returned is Int. Note: this is an Azure DW problem only and does not impact the other MS databases.

Reproduction code

Have a code example that illustrates the issue - if that would help, but the bug is relatively easy to reproduce.

@ulvii
Copy link
Contributor

ulvii commented Jun 5, 2020

Hi @tsegall ,

This means that when you attempt to do a resultSet.getInt() you receive a ClassCastException.

I am confused a bit, are you trying to retrieve IS_AUTOINCREMENT, IS_GENERATEDCOLUMN using resultSet.getInt()? This will obviously result in ClassCastException the possible values for these columns are YES/NO.

These are returned as type 4 (Int) when they should actually be a string.

I can't reproduce this behavior, the driver returns YES/NO, please share a table schema and JDBC repro code if you want us to investigate this further.

@tsegall
Copy link
Author

tsegall commented Jun 5, 2020

The issue is that the result of calling rsmd.getColumnType(i) on these two columns returns 4 and hence according to the JDBC specification you should use getInt() to retrieve their values.

I have attached sample code which illustrates this problem - if you run this sample code an another database (e.g. Oracle, Postgres, etc) it will work in addition the code will work on SQL Server (both hosted and on-premise. It does not work on Azure DW.
Regards, Tim.

tiny.txt](https://github.com/microsoft/mssql-jdbc/files/4733613/tiny.txt)

@ulvii
Copy link
Contributor

ulvii commented Jun 9, 2020

Hi @tsegall ,
Thanks for the repro code, I can confirm that this is a deficiency in the driver. I also created #1356 to fix, the PR has a jar attached to it, would you give it a try and let us know if your issues are resolved?

@tsegall
Copy link
Author

tsegall commented Jun 9, 2020

I can confirm the jar you supplied does in fact address the defect raised. Many thanks for the speedy resolution - it appears that this fix will make it into 8.4.0, is this correct. If so I can relay this to our customer who is looking for a fix.

@ulvii
Copy link
Contributor

ulvii commented Jun 9, 2020

Yes, we will try to have the fix in 8.4.0 release.

@ulvii
Copy link
Contributor

ulvii commented Jun 15, 2020

#1356 merged.

@ulvii ulvii closed this as completed Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants