Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table's alias is the keyword #34039

Open
daiqiang opened this issue Dec 13, 2024 · 1 comment
Open

table's alias is the keyword #34039

daiqiang opened this issue Dec 13, 2024 · 1 comment

Comments

@daiqiang
Copy link

Bug Report

For English only, other languages will not accept.
my sql parsing failure
select ti.user_name from my_user ti where user_name = 'xxx'
it throws a Execption:
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException: You have an error in your SQL syntax: no viable alternative at input 'ti' at org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine.getException(ShardingSphereSQLParserEngine.java:66) at org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine.parse(ShardingSphereSQLParserEngine.java:59) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.parseSQL(ShardingSpherePreparedStatement.java:164) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:145) at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:117) at org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection.prepareStatement(ShardingSphereConnection.java:141) at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:337) at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java) at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:86) at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88) at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:87) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) 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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) at com.sun.proxy.$Proxy70.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87) at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86) at com.sun.proxy.$Proxy71.sql_s14(Unknown Source)

Which version of ShardingSphere did you use?

    shardingSphere-5.5.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

    ShardingSphere-JDBC

Which DB

    oracle

Expected behavior

   parse SQL sucess

Actual behavior

    `org.apache.shardingsphere.infra.exception.dialect.exception.syntax.sql.DialectSQLParsingException: You have an error in your SQL syntax: no viable alternative at input 'ti'`

Reason analyze (If you can)

   I analyzed this bug , I fined the word "ti" is the keyword in "oralce/Keyword.g4",but I don't know how the Keyword.g4 file affects SQL parsing. In order for the SQL to be parsed correctly, I had to remove the keyword "ti" from the Keyword.g4 file.I have handled many such SQLs in the same way. until I discovered that this is not a good way.
  please somebody who can tell me, if don't remove keyword "ti" or don't modify my table's alias, what can I do to resovle this question?

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  skip

Example codes for reproduce this issue (such as a github link).

    `select ti.user_name from my_user ti where user_name = 'xxx'`
@daiqiang
Copy link
Author

I analyzed this bug , I fined the word "ti" is the keyword in "oralce/Keyword.g4",but I don't know how the Keyword.g4 file affects SQL parsing. In order for the SQL to be parsed correctly, I had to remove the keyword "ti" from the Keyword.g4 file.I have handled many such SQLs in the same way. until I discovered that this is not a good way.
please somebody who can tell me, if don't remove keyword "ti" or don't modify my table's alias, what can I do to resovle this question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants