Skip to content

Conversation

@chernser
Copy link
Contributor

@chernser chernser commented May 27, 2025

Summary

  • Adds test for WITH clause with parameters to PreparedStatementImplTests

Closes #2391

Checklist

Delete items not relevant to your PR:

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
66.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mshustov mshustov requested a review from Copilot May 28, 2025 07:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds integration tests for the WITH clause using parameters in prepared statements and cleans up unused overrides in several JDBC classes.

  • Added a new test, testWithClauseWithParams, in PreparedStatementTest.java to validate parameterized WITH statements.
  • Removed redundant overridden methods from StatementImpl, DataSourceImpl, and ConnectionImpl to streamline their implementations.

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.

File Description
jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java Added tests for WITH clause and improved test structure by scoping variable declarations.
jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java Removed unused override methods to rely on default implementations.
jdbc-v2/src/main/java/com/clickhouse/jdbc/DataSourceImpl.java Removed unused methods and corresponding imports related to connection building and sharding.
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java Revised the array creation implementation and removed deprecated sharding key methods.
Files not reviewed (2)
  • clickhouse-client/pom.xml: Language not supported
  • pom.xml: Language not supported
Comments suppressed due to low confidence (2)

jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java:332

  • Consider using a consistent method (either column labels or column indexes) for accessing result set values to improve clarity and reduce the risk of issues if the column order changes.
Assert.assertEquals(rs.getTimestamp("target_time").toLocalDateTime().truncatedTo(ChronoUnit.SECONDS), target_time.toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime().truncatedTo(ChronoUnit.SECONDS));

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:553

  • [nitpick] If there's no specific need for streaming the elements, consider using Arrays.asList(elements) to simplify the code and improve readability, assuming that a direct conversion is acceptable.
List<Object> list = (elements == null || elements.length == 0) ? Collections.emptyList() : Arrays.stream(elements, 0, elements.length).collect(Collectors.toList());

@mshustov
Copy link
Member

/windsurf-review

@chernser chernser merged commit bed84ee into main May 28, 2025
21 of 23 checks passed
@chernser chernser deleted the fix_with_statement branch May 28, 2025 19:13
@mshustov
Copy link
Member

mshustov commented Jun 2, 2025

/windsurf-review


ResultSet rs = stmt.executeQuery();
int count = 0;
int expected = 4; // 4,5,6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a mismatch between the comment and the assertion. The comment on line 398 says expected is 4 for numbers 4,5,6 (which is actually 3 numbers), but the assertion on line 404 correctly checks for 3. Please update the comment to match the assertion.

Comment on lines +553 to +555
List<Object> list =
(elements == null || elements.length == 0) ? Collections.emptyList() : Arrays.stream(elements, 0, elements.length).collect(Collectors.toList());
return new com.clickhouse.jdbc.types.Array(list, typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)).getVendorTypeNumber());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Arrays.stream approach for handling array elements could potentially have issues with null elements within the array. Consider using a more robust approach that explicitly handles null elements within the array:

Suggested change
List<Object> list =
(elements == null || elements.length == 0) ? Collections.emptyList() : Arrays.stream(elements, 0, elements.length).collect(Collectors.toList());
return new com.clickhouse.jdbc.types.Array(list, typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)).getVendorTypeNumber());
List<Object> list = Collections.emptyList();
if (elements != null && elements.length > 0) {
list = Arrays.stream(elements)
.collect(Collectors.toList());
}

" WHERE n > ?)" +
") " +
"SELECT * FROM data WHERE n < ?")) {
//"WITH data AS ( (SELECT number AS n FROM numbers(?) WHERE n > ?)) SELECT * FROM data WHERE n < ?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out SQL query on line 391 should be removed as it appears to be for debugging purposes only.

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

Successfully merging this pull request may close these issues.

[jdbc] Parsing statement containing WITH clause fails on client side

3 participants