Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ OCTAL_LITERAL : '0' OCT_DIGIT+;
DECIMAL_LITERAL : DEC_DIGIT+;
HEXADECIMAL_LITERAL : '0' X HEX_DIGIT+;

CAST_OP : '::';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add unit or integration tests to verify the correct handling of the new CAST_OP token and cast grammar (e.g., ?::integer, ?::UUID). This ensures the lexer and parser changes are covered and prevents regressions.


// It's important that quote-symbol is a single character.
STRING_LITERAL:
QUOTE_SINGLE (~([\\']) | (BACKSLASH .) | (QUOTE_SINGLE QUOTE_SINGLE))* QUOTE_SINGLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ columnExpr
| LBRACKET columnExprList? RBRACKET # ColumnExprArray
| columnIdentifier # ColumnExprIdentifier
| QUERY # ColumnExprParam
| QUERY CAST_OP identifier # ColumnExprParamWithCast
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 cast operation grammar (e.g., ?::integer). Please add or update unit/integration tests to ensure this functionality is covered.

;

columnArgList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void enterColumnExprParam(ClickHouseParser.ColumnExprParamContext ctx) {
appendParameter(ctx.start.getStartIndex());
}

@Override
public void enterColumnExprParamWithCast(ClickHouseParser.ColumnExprParamWithCastContext ctx) {
appendParameter(ctx.start.getStartIndex());
}

@Override
public void visitErrorNode(ErrorNode node) {
setHasErrors(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.clickhouse.data.ClickHouseVersion;
import com.clickhouse.jdbc.internal.DriverProperties;
import org.apache.commons.lang3.RandomStringUtils;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.deser.std.UUIDDeserializer;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Ignore;
Expand Down Expand Up @@ -1051,4 +1052,27 @@ public void testNullValues() throws Exception {
}
}
}

@Test
public void testParamWithCast() throws Exception {
final String sql = " SELECT ?::integer, '?::integer', 123, ?:: UUID, ?";
try (Connection conn = getJdbcConnection()) {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, "1000");
UUID uuid = UUID.randomUUID();
stmt.setString(1, "1000");
stmt.setString(2, uuid.toString());
stmt.setInt(3, 3003001);

try (ResultSet rs = stmt.executeQuery()) {
assertTrue(rs.next());
Assert.assertEquals(rs.getInt(1), 1000);
Assert.assertEquals(rs.getString(2), "?::integer");
Assert.assertEquals(rs.getInt(3), 123);
Assert.assertEquals(rs.getString(4), uuid.toString());
Assert.assertEquals(rs.getInt(5), 3003001);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clickhouse.jdbc.internal;


import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -193,4 +194,20 @@ public void testEscapeQuotes() {
assertEquals(SqlParser.escapeQuotes(inStr[i]), outStr[i]);
}
}

@Test
public void testStmtWithCasts() {
String sql = "SELECT ?::integer, ?, '?::integer' FROM table WHERE v = ?::integer"; // CAST(?, INTEGER)
SqlParser parser = new SqlParser();
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
Assert.assertEquals(stmt.getArgCount(), 3);
}

@Test
public void testStmtWithFunction() {
String sql = "SELECT `parseDateTimeBestEffort`(?, ?) as dt FROM table WHERE v > `parseDateTimeBestEffort`(?, ?) ";
SqlParser parser = new SqlParser();
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
Assert.assertEquals(stmt.getArgCount(), 4);
}
}
Loading