Skip to content

Conversation

@chernser
Copy link
Contributor

@chernser chernser commented May 7, 2025

Summary

  • Replaces custom SQL parsing logic with Antlr4 parse. (because CH repo has grammar for it and easy to use)
  • Reimplement several checks using parser
  • Does a small cleanup of some utility methods

Closes #2348
Closes #2325
Closes #2283
Closes #2354

Checklist

Delete items not relevant to your PR:

@chernser chernser requested review from Paultagoras and mzitnik May 8, 2025 19:59
@chernser chernser marked this pull request as ready for review May 8, 2025 20:00
@mshustov mshustov requested a review from Copilot May 9, 2025 08:37
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 replaces the custom SQL parsing logic with an Antlr4-based parser and refactors how SQL statements (including prepared statements and batch operations) are built and executed.

  • Removes the legacy StatementParser in favor of a new SqlParser based on Antlr4.
  • Refactors both regular statements and prepared statements (including batch insert logic) to use the new parser and updated string substitution methods.
  • Updates various supporting utilities and adapts test classes to the new parsing and statement-building mechanisms.

Reviewed Changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/SqlParser.java Introduces the new Antlr4-based parser implementation.
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ParsedPreparedStatement.java Implements a listener that collects parsed details for prepared statements.
jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java Refactors SQL building and batch insert logic to use the new parser information and string replacement logic.
jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java Updates statement execution to use the new "lastStatementSql" variable and revised query settings.
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/StatementParser.java Removed legacy SQL parsing logic.
jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java Integrates the new SqlParser and adjusts schema/table handling for beta features.
Other test and utility files Minor cleanup and adaptation to the new parsing architecture.
Files not reviewed (2)
  • jdbc-v2/pom.xml: Language not supported
  • jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseLexer.g4: Language not supported

Copy link
Contributor

@mzitnik mzitnik left a comment

Choose a reason for hiding this comment

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

Can we also add some performance tests to measure the time it takes for the parser


if (parsedStatement.isInsert() && config.isBetaFeatureEnabled(DriverProperties.BETA_ROW_BINARY_WRITER)) {
/*
* RowBinary can be used when
Copy link
Contributor

Choose a reason for hiding this comment

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

It is more accurate to say. Only if all the fields of the table are included (and in the same order)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we can.

@@ -0,0 +1,300 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you provide a source(link) for this information

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry did not get the question - what information?

Copy link
Contributor

Choose a reason for hiding this comment

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

Where did you take all the definitions

@ethlo
Copy link

ethlo commented May 13, 2025

This PR is a game-changer! Is there a chance to get this merged in for 0.8.6?

@mshustov
Copy link
Member

@ethlo yes, it's the main topic for 0.8.6

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
63.6% Coverage on New Code (required ≥ 80%)
5.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@chernser chernser merged commit 41f1ea8 into main May 14, 2025
24 of 25 checks passed
@chernser chernser deleted the antlr4_parser branch May 14, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants