springnick opened a new issue #8590:
URL: https://github.com/apache/shardingsphere/issues/8590
## Bug Report
Which version of ShardingSphere did you use?
A: 4.1.1
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
A: ShardingSphere-JDBC
Expected behavior
A: sql should be able to be parsed correctly,
Actual behavior
A: got an exception when parsing a simple sql
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:658)
at
org.apache.shardingsphere.sql.parser.sql.util.SQLUtil.getParenthesesOffset(SQLUtil.java:98)
at
org.apache.shardingsphere.sql.parser.sql.util.SQLUtil.getExpressionWithoutOutsideParentheses(SQLUtil.java:92)
at
org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ExpressionProjectionSegment.<init>(ExpressionProjectionSegment.java:47)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.createProjection(MySQLDMLVisitor.java:474)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjection(MySQLDMLVisitor.java:434)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjection(MySQLDMLVisitor.java:127)
at
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$ProjectionContext.accept(MySQLStatementParser.java:5370)
at
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjections(MySQLDMLVisitor.java:410)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitProjections(MySQLDMLVisitor.java:127)
at
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$ProjectionsContext.accept(MySQLStatementParser.java:4865)
at
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitSelectClause(MySQLDMLVisitor.java:329)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitSelectClause(MySQLDMLVisitor.java:127)
at
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$SelectClauseContext.accept(MySQLStatementParser.java:4551)
at
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitUnionClause(MySQLDMLVisitor.java:322)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitUnionClause(MySQLDMLVisitor.java:127)
at
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$UnionClauseContext.accept(MySQLStatementParser.java:4446)
at
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitSelect(MySQLDMLVisitor.java:314)
at
org.apache.shardingsphere.sql.parser.mysql.visitor.impl.MySQLDMLVisitor.visitSelect(MySQLDMLVisitor.java:127)
at
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser$SelectContext.accept(MySQLStatementParser.java:3098)
at
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
at
org.apache.shardingsphere.sql.parser.SQLParserEngine.parse0(SQLParserEngine.java:80)
at
org.apache.shardingsphere.sql.parser.SQLParserEngine.parse(SQLParserEngine.java:61)
at com.example.nick1.ParserTest.testParse2(ParserTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at
com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Reason analyze (If you can)
A: not sure, please check the exception message
Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
A: with ShardingSphere 4.1.1, write a simple junit test case to parse a
simple sql as following:
public class ParserTest {
@Test
public void testParse2(){
SQLParserEngine parserEngine=
SQLParserEngineFactory.getSQLParserEngine("MySQL");
String sql="select user_id, name, '' name2 from t_user where name=?";
SQLStatement sqlStatement=parserEngine.parse(sql,false);
Assert.notNull(sqlStatement,"statement should not be null");
}
}
### Example codes for reproduce this issue (such as a github link).
public class ParserTest {
@Test
public void testParse2(){
SQLParserEngine parserEngine=
SQLParserEngineFactory.getSQLParserEngine("MySQL");
String sql="select user_id, name, '' name2 from t_user where name=?";
SQLStatement sqlStatement=parserEngine.parse(sql,false);
Assert.notNull(sqlStatement,"statement should not be null");
}
}
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]