aws / aws/amazon-redshift-jdbc-driver

Column metadata type changed when upgrading driver version for SUPER type

Open
#143 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
71
Forks
42
PR merge metrics
No merged PRs in 30d

Description

Hello

I have the following table in Redshift:

```sql
CREATE TABLE
test_resources_v1.types
(
id BIGINT NOT NULL,
null_double_array SUPER,
long_array SUPER,
string_array SUPER,

PRIMARY KEY (id)
);

INSERT INTO
test_resources_v1.types
(
id,
null_double_array,
long_array,
string_array)
VALUES
(1,
ARRAY(1.1, 10.01, 100.001), ARRAY(10, 15, 30), ARRAY('value', 'other-value')),
(2,
ARRAY(200.002, 20, 2.2), ARRAY(56, 202, 304), ARRAY('value 1', 'other value 3')),
(4,
null, null, null);

```

I use the following code to query this table:

```java
@Test
void testArrayTypes() throws SQLException {

final Connection connection = DriverManager.getConnection(RedshiftTestConstants.REDSHIFT_JDBC_URL + RedshiftTestConstants.TEST_DATABASE_NAME,
RedshiftTestConstants.getUsername(),
RedshiftTestConstants.getRedshiftPassword());

ResultSet columns = connection.getMetaData()
.getColumns(
RedshiftTestConstants.TEST_DATABASE_NAME,
RedshiftTestConstants.TEST_SCHEMA_NAME,
"types",
"null_double_array");

columns.next();
int typeInt = columns.getInt("DATA_TYPE");
System.out.println("null_double_array typeInt = " + typeInt);

columns = connection.getMetaData()
.getColumns(
RedshiftTestConstants.TEST_DATABASE_NAME,
RedshiftTestConstants.TEST_SCHEMA_NAME,
"types",
"long_array");

columns.next();
typeInt = columns.getInt("DATA_TYPE");
System.out.println("long_array typeInt = " + typeInt);

columns = connection.getMetaData()
.getColumns(
RedshiftTestConstants.TEST_DATABASE_NAME,
RedshiftTestConstants.TEST_SCHEMA_NAME,
"types",
"string_array");

columns.next();
typeInt = columns.getInt("DATA_TYPE");
System.out.println("string_array typeInt = " + typeInt);
}
```

When running the previous code with the JDBC driver 2.1.0.30, it returns:

```
null_double_array typeInt = -16
long_array typeInt = -16
string_array typeInt = -16
```

With the JDBC driver version 2.1.0.32 (I skipped 2.1.0.31, as your CHANGELOG mentioned it was yanked)
```
null_double_array typeInt = -1
long_array typeInt = -1
string_array typeInt = -1
```

I assume it is a regression, otherwise I would have expected a changelog entry.

It does break the following code, as we do not get the same JDBC type:

```java
final int typeInt = resultSet.getInt("DATA_TYPE");
final JDBCType jdbcType = JDBCType.valueOf(typeInt);
```
This provokes a breakage downstream, as we were relying on this type to convert it to array

If it is on purpose, could you document the change and explain how to migrate ?

Contributor guide

Open the contributing guide

Research direction

Start with the testArrayTypes entry point and reproduce the metadata calls against the shown SUPER table using JDBC driver versions 2.1.0.30 and 2.1.0.32. Compare the DATA_TYPE returned by getColumns; done means the behavior is made consistent with the intended JDBC type, or the changed behavior is documented with a migration path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.