Skip to content

Conversation

@chernser
Copy link
Contributor

@chernser chernser commented Jun 4, 2025

Summary

Adds CREATE USER statement grammar.

Closes #2398
Closes #2428

Checklist

Delete items not relevant to your PR:

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

💡 To request another review, post a new comment with "/windsurf-review".

Comment on lines +145 to +152
| CREATE USER ((IF NOT EXISTS) | (OR REPLACE))? userIdentifier (COMMA userIdentifier)* clusterClause?
userIdentifiedClause?
userCreateHostClause?
validUntilClause?
(DEFAULT ROLE identifier (COMMA identifier)*)?
(DEFAULT DATABASE identifier | NONE)?

settingsClause? #CreateUserStmt
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests are required for the new CREATE USER statement grammar. Please add unit and/or integration tests to ensure the parser correctly handles valid and invalid CREATE USER statements.

@chernser chernser requested a review from mzitnik June 4, 2025 18:06
@mshustov
Copy link
Member

mshustov commented Jun 5, 2025

@chernser do we need to contribute the changes to the clickhouse upstream?

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.

In general LGTM

}

@Test(groups = {"integration"})
public void testDDLStatements() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can expand testing with a few more examples (to see that the parser works correctly)
Here we can find the https://clickhouse.com/docs/sql-reference/statements/create/user
like adding

  • "CREATE USER IF NOT EXISTS 'user011' IDENTIFIED WITH no_password"
  • "IDENTIFIED WITH plaintext_password BY 'qwerty'"
    and a few more options

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, will do this.

@chernser
Copy link
Contributor Author

chernser commented Jun 5, 2025

@mshustov yes, we need. Will do it later. I need sometime to prepare PR to CH repo - it is not just 1-to-1 change.

@mzitnik ok - will extend.

@mshustov
Copy link
Member

mshustov commented Jun 5, 2025

/windsurf-review

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

💡 To request another review, post a new comment with "/windsurf-review".

try {
lastStatementSql = parseJdbcEscapeSyntax(sql);
LOG.debug("SQL Query: {}", lastStatementSql);
LOG.trace("SQL Query: {}", lastStatementSql); // this is not secure for create statements because of passwords
Copy link
Contributor

Choose a reason for hiding this comment

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

Logging full SQL queries, even at TRACE level, may expose sensitive information such as passwords in CREATE USER statements. Consider redacting sensitive data from the SQL before logging, or ensure users are aware of this risk in documentation or configuration.

@Test(groups = { "integration" })
void testRecursiveWithClause() throws Exception {
if (ClickHouseVersion.of(getServerVersion()).check("(,24.3]")) {
return; // recursive CTEs were introduces in 24.4
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in comment: 'introduces' should be 'introduced'.


public class SqlParser {

private static Logger LOG = LoggerFactory.getLogger(SqlParser.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider declaring the logger as 'private static final Logger LOG = LoggerFactory.getLogger(SqlParser.class);' to follow best practices for static loggers.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 5, 2025

@chernser chernser merged commit fbc2248 into main Jun 5, 2025
23 of 25 checks passed
@chernser chernser deleted the jdbc_fix_parser_issue branch June 5, 2025 20:01
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-v2] Antl4 parser and lexer don't use logger and prints to stderr instead DLL statement failures with the v2 of the JDBC driver

4 participants