Skip to content

Regression when binding variable to aggregate FILTER clause #2630

@lukaseder

Description

@lukaseder

Description

Steps to reproduce

// Works (no bind values)
try (PreparedStatement s = connection.prepareStatement(
    """
    select count(*) filter (where 1 = 1)
    """
)) {
    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getInt(1));
    }
}

// Works (ClickHouse specific syntax)
try (PreparedStatement s = connection.prepareStatement(
    """
    select countIf(*, 1 = ?)
    """
)) {
    s.setInt(1, 1);

    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getInt(1));
    }
}

// Doesn't work
try (PreparedStatement s = connection.prepareStatement(
    """
    select count(*) filter (where 1 = ?)
    """
)) {
    s.setInt(1, 1);

    try (ResultSet rs = s.executeQuery()) {
        while (rs.next())
            System.out.println(rs.getInt(1));
    }
}

Error Log or Exception StackTrace

The above prints

1
1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.clickhouse.jdbc.PreparedStatementImpl.setInt(PreparedStatementImpl.java:180)
	at org.jooq.testscripts.JDBC.main(JDBC.java:69)

Expected Behaviour

All three statements should work. They did with driver version 0.7.0.

Configuration

Environment

  • Client version: com.clickhouse:clickhouse-jdbc:0.9.2
  • Language version: OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
  • OS: Microsoft Windows [Version 10.0.26100.6899]

ClickHouse Server

  • ClickHouse Server version: 25.8.2.29

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions