Skip to content

Regression for nullable metadata with JDBC client between 0.9.1 and 0.9.2 #2586

@NathanEckert

Description

@NathanEckert

Description

Between 0.9.1 and 0.9.2, there was a regression around the metadata for nullability in the JDBC driver.
Note that this affects only the JDBC client, not the Java HTTP client

Steps to reproduce

  1. Create table with nullable column
  2. Run the sample code

Code Example

I have the following table:

create table
  `nullable_key`
(
  `key_1` Nullable(Int64),
  `key_2` Nullable(Int64),
  `value` String NOT NULL
)
ENGINE = MergeTree()
ORDER BY tuple()
;

INSERT INTO
  `nullable_key`
VALUES
(1, null, 'value_1_null'),
(1, 1, 'value_1_1'),
(2, 2, 'value_2_2'),
(null, 2, 'value_null_2'),
(null, null, 'value_null_null');

I query said table the following way:

    @Test
    void testTypes() throws Exception {
        String databaseName = "tck_db_v1";
        String tableName = "nullable_key";

        Client client = CONFIG.getClient();
        TableSchema schemaFromHttpClient = client.getTableSchema(tableName);

        System.out.println("Schema from ClickHouse HTTP client:" + schemaFromHttpClient);

        for (var col : schemaFromHttpClient.getColumns()) {
            System.out.println(col.getColumnName() + " is nullable: " + col.isNullable());
        }

        final var jdbcUrl = "jdbc:clickhouse:"
                + CONFIG.getClient().getEndpoints().iterator().next()
                + "/" + databaseName;
        final Properties properties = new Properties();
        properties.put("user", "default");
        properties.put("password", "");
        System.out.println("JDBC URL: " + jdbcUrl);
        try (Connection connection = DriverManager.getConnection(jdbcUrl, properties)) {
            final ResultSet columns = connection.getMetaData()
                    .getColumns(
                            null,
                            convertToPattern(databaseName),
                            convertToPattern(tableName),
                            null);
            while (columns.next()) {
                final String name = columns.getString("COLUMN_NAME");
                final boolean isNullable = columns.getBoolean("NULLABLE");
                System.out.println(name + " nullable: " + isNullable);
            }
        }
    }

    private static String convertToPattern(String likePattern) {
        return likePattern.replace("_", "\\_");
    }

On 0.9.1, this returns:

Schema from ClickHouse HTTP client:TableSchema{tableName='nullable_key', databaseName='tck_db_v1', columns=[key_1 Nullable(Int64), key_2 Nullable(Int64), value String], colIndex={key_1=0, key_2=1, value=2}, hasDefaults=false}
key_1 is nullable: true
key_2 is nullable: true
value is nullable: false
JDBC URL: jdbc:clickhouse:http://localhost:32859/tck_db_v1
key_1 nullable: true
key_2 nullable: true
value nullable: false

On 0.9.2, this returns:

Schema from ClickHouse HTTP client:TableSchema{tableName='nullable_key', databaseName='tck_db_v1', columns=[key_1 Nullable(Int64), key_2 Nullable(Int64), value String], colIndex={key_1=0, key_2=1, value=2}, hasDefaults=false}
key_1 is nullable: true
key_2 is nullable: true
value is nullable: false
JDBC URL: jdbc:clickhouse:http://localhost:32859/tck_db_v1
key_1 nullable: false
key_2 nullable: false
value nullable: false

On 0.9.2, the value for plain JDBC differs from the HTTP client, and is also a regression vs 0.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions