huang-zs opened a new issue, #35381: URL: https://github.com/apache/shardingsphere/issues/35381
## Bug Report ### Which version of ShardingSphere did you use? ``` <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc</artifactId> <version>5.5.2</version> </dependency> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-parser-sql-clickhouse</artifactId> <version>5.5.2</version> </dependency> <dependency> <groupId>com.clickhouse</groupId> <artifactId>clickhouse-jdbc</artifactId> <classifier>http</classifier> <version>0.6.3</version> </dependency> ``` ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? shardingsphere-jdbc ### Expected behavior jdbcTemplate.execute("select * from sampling_plan_score where plan_student_id in (select id from sampling_plan_student sps)"); only use `com.clickhouse.jdbc.ClickHouseDriver` it work use `org.apache.shardingsphere.driver.ShardingSphereDriver` with `com.clickhouse.jdbc.ClickHouseDriver` it not work ### Actual behavior ``` java.lang.ClassCastException: org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement cannot be cast to org.apache.shardingsphere.sql.parser.statement.sql92.dml.SQL92SelectStatement at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.createInSegment(ClickHouseStatementVisitor.java:297) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitPredicate(ClickHouseStatementVisitor.java:271) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitPredicate(ClickHouseStatementVisitor.java:79) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$PredicateContext.accept(ClickHouseStatementParser.java:5381) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitBooleanPrimary(ClickHouseStatementVisitor.java:252) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitBooleanPrimary(ClickHouseStatementVisitor.java:79) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$BooleanPrimaryContext.accept(ClickHouseStatementParser.java:5157) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitExpr(ClickHouseStatementVisitor.java:202) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor.visitExpr(ClickHouseStatementVisitor.java:79) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$ExprContext.accept(ClickHouseStatementParser.java:4904) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitWhereClause(ClickHouseDMLStatementVisitor.java:438) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitWhereClause(ClickHouseDMLStatementVisitor.java:80) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$WhereClauseContext.accept(ClickHouseStatementParser.java:2824) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitSelectClause(ClickHouseDMLStatementVisitor.java:209) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitSelectClause(ClickHouseDMLStatementVisitor.java:80) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$SelectClauseContext.accept(ClickHouseStatementParser.java:1193) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitCombineClause(ClickHouseDMLStatementVisitor.java:194) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitCombineClause(ClickHouseDMLStatementVisitor.java:80) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$CombineClauseContext.accept(ClickHouseStatementParser.java:1105) at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitSelect(ClickHouseDMLStatementVisitor.java:186) at org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.type.ClickHouseDMLStatementVisitor.visitSelect(ClickHouseDMLStatementVisitor.java:80) at org.apache.shardingsphere.sql.parser.autogen.ClickHouseStatementParser$SelectContext.accept(ClickHouseStatementParser.java:1058) at org.apache.shardingsphere.sql.parser.api.SQLStatementVisitorEngine.visit(SQLStatementVisitorEngine.java:52) at org.apache.shardingsphere.infra.parser.sql.SQLStatementParserExecutor.parse(SQLStatementParserExecutor.java:47) at org.apache.shardingsphere.infra.parser.sql.SQLStatementParserEngine.parse(SQLStatementParserEngine.java:57) at org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine.parse(ShardingSphereSQLParserEngine.java:53) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.createQueryContext(ShardingSphereStatement.java:260) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.execute(ShardingSphereStatement.java:248) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.execute(ShardingSphereStatement.java:196) at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:422) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:381) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:431) ``` ### Reason analyze (If you can) `org.apache.shardingsphere.sql.parser.clickhouse.visitor.statement.ClickHouseStatementVisitor#createInSegment` ``` private InExpression createInSegment(final ClickHouseStatementParser.PredicateContext ctx) { ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0)); ExpressionSegment right; if (null != ctx.subquery()) { right = new SubqueryExpressionSegment(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (SQL92SelectStatement) visit(ctx.subquery()), getOriginalText(ctx.subquery()))); } else { ListExpression listExpression = new ListExpression(ctx.LP_().getSymbol().getStartIndex(), ctx.RP_().getSymbol().getStopIndex()); for (ClickHouseStatementParser.ExprContext each : ctx.expr()) { listExpression.getItems().add((ExpressionSegment) visit(each)); } right = listExpression; } boolean not = null != ctx.NOT(); return new InExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, not); } ``` this method force cast subquery as `SQL92SelectStatement` but acutal is `org.apache.shardingsphere.sql.parser.statement.clickhouse.dml.ClickHouseSelectStatement` ``` private InExpression createInSegment(final ClickHouseStatementParser.PredicateContext ctx) { ExpressionSegment left = (ExpressionSegment) visit(ctx.bitExpr(0)); ExpressionSegment right; if (null != ctx.subquery()) { right = new SubqueryExpressionSegment(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (SelectStatement) visit(ctx.subquery()), getOriginalText(ctx.subquery()))); } else { ListExpression listExpression = new ListExpression(ctx.LP_().getSymbol().getStartIndex(), ctx.RP_().getSymbol().getStopIndex()); for (ClickHouseStatementParser.ExprContext each : ctx.expr()) { listExpression.getItems().add((ExpressionSegment) visit(each)); } right = listExpression; } boolean not = null != ctx.NOT(); return new InExpression(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), left, right, not); } ``` i overwrite this method change force cast `SQL92SelectStatement` to `SelectStatement` , it work ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc. ### Example codes for reproduce this issue (such as a github link). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org