xiaotianlongxing opened a new issue #2597: Sharding-Proxy throws NPE when query 
by primary key
URL: https://github.com/apache/incubator-shardingsphere/issues/2597
 
 
   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   4.0.0-RC1-sharding-proxy
   
   ### Which project did you use? Sharding-JDBC or Sharding-Proxy?
   Sharding-Proxy
   
   ### Expected behavior
   no error 
   
   ### Actual behavior
   
   [INFO ] 17:27:35.208 [ShardingSphere-Command-13] ShardingSphere-SQL - Rule 
Type: sharding
   [INFO ] 17:27:35.208 [ShardingSphere-Command-13] ShardingSphere-SQL - Logic 
SQL: SET PROFILING = 1
   [INFO ] 17:27:35.208 [ShardingSphere-Command-13] ShardingSphere-SQL - 
SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, 
tables=Tables(tables=[]), 
routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
sqlTokens=[], parametersIndex=0, logicSQL=null))
   [INFO ] 17:27:35.208 [ShardingSphere-Command-13] ShardingSphere-SQL - Actual 
SQL: ds ::: SET PROFILING = 1
   [INFO ] 17:27:35.212 [ShardingSphere-Command-15] ShardingSphere-SQL - Rule 
Type: sharding
   [INFO ] 17:27:35.212 [ShardingSphere-Command-15] ShardingSphere-SQL - Logic 
SQL: SHOW STATUS
   [INFO ] 17:27:35.212 [ShardingSphere-Command-15] ShardingSphere-SQL - 
SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, 
tables=Tables(tables=[]), 
routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
sqlTokens=[], parametersIndex=0, logicSQL=null))
   [INFO ] 17:27:35.212 [ShardingSphere-Command-15] ShardingSphere-SQL - Actual 
SQL: ds ::: SHOW STATUS
   [INFO ] 17:27:35.218 [ShardingSphere-Command-14] ShardingSphere-SQL - Rule 
Type: sharding
   [INFO ] 17:27:35.218 [ShardingSphere-Command-14] ShardingSphere-SQL - Logic 
SQL: SHOW STATUS
   [INFO ] 17:27:35.218 [ShardingSphere-Command-14] ShardingSphere-SQL - 
SQLStatement: DALStatement(super=AbstractSQLStatement(type=DAL, 
tables=Tables(tables=[]), 
routeConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
sqlTokens=[], parametersIndex=0, logicSQL=null))
   [INFO ] 17:27:35.218 [ShardingSphere-Command-14] ShardingSphere-SQL - Actual 
SQL: ds ::: SHOW STATUS
   [INFO ] 17:27:35.230 [ShardingSphere-Command-0] ShardingSphere-SQL - Rule 
Type: sharding
   [INFO ] 17:27:35.231 [ShardingSphere-Command-0] ShardingSphere-SQL - Logic 
SQL: select * from book where book_id = 1
   [INFO ] 17:27:35.231 [ShardingSphere-Command-0] ShardingSphere-SQL - 
SQLStatement: 
SelectStatement(super=DQLStatement(super=AbstractSQLStatement(type=DQL, 
tables=Tables(tables=[Table(name=book, alias=Optional.absent())]), 
routeConditions=Conditions(orCondition=OrCondition(andConditions=[AndCondition(conditions=[Condition(column=Column(name=book_id,
 tableName=book), operator=EQUAL, compareOperator==, positionValueMap={0=1}, 
positionIndexMap={})])])), 
encryptConditions=Conditions(orCondition=OrCondition(andConditions=[])), 
sqlTokens=[TableToken(tableName=book, quoteCharacter=NONE, 
schemaNameLength=0)], parametersIndex=0, logicSQL=select * from book where 
book_id = 1)), containStar=true, firstSelectItemStartIndex=7, 
selectListStopIndex=7, groupByLastIndex=0, 
items=[StarSelectItem(owner=Optional.absent())], groupByItems=[], 
orderByItems=[], limit=null, subqueryStatement=null, subqueryStatements=[], 
subqueryConditions=[])
   [INFO ] 17:27:35.231 [ShardingSphere-Command-0] ShardingSphere-SQL - Actual 
SQL: ds_1 ::: select * from book_1 where book_id = 1
   [ERROR] 17:27:35.235 [ShardingSphere-Command-0] 
o.a.s.s.f.c.CommandExecutorTask - Exception occur: 
   java.lang.NullPointerException: null
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.createConnection(JDBCBackendDataSource.java:142)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:115)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection.getConnectionFromUnderlying(BackendConnection.java:186)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection.getConnectionsWithoutTransaction(BackendConnection.java:169)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection.getConnections(BackendConnection.java:138)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.execute.callback.ProxyJDBCExecutePrepareCallback.getConnections(ProxyJDBCExecutePrepareCallback.java:55)
           at 
org.apache.shardingsphere.core.execute.sql.prepare.SQLExecutePrepareTemplate.getSQLExecuteGroups(SQLExecutePrepareTemplate.java:89)
           at 
org.apache.shardingsphere.core.execute.sql.prepare.SQLExecutePrepareTemplate.getSynchronizedExecuteUnitGroups(SQLExecutePrepareTemplate.java:67)
           at 
org.apache.shardingsphere.core.execute.sql.prepare.SQLExecutePrepareTemplate.getExecuteUnitGroups(SQLExecutePrepareTemplate.java:59)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.execute.JDBCExecuteEngine.execute(JDBCExecuteEngine.java:78)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:94)
           at 
org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:80)
           at 
org.apache.shardingsphere.shardingproxy.backend.text.query.QueryBackendHandler.execute(QueryBackendHandler.java:54)
           at 
org.apache.shardingsphere.shardingproxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:71)
           at 
org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:86)
           at 
org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:66)
           at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
           at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
           at java.lang.Thread.run(Thread.java:748)
   
   ### Reason analyze (If you can)
   
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   the config-sharding.yaml as follows :
   dataSources:
     ds:
       url: 
jdbc:mysql://xxxx/test?characterEncoding=utf8&useSSL=true&allowMultiQueries=true&serverTimezone=UTC
       username: root
       password: 
       connectionTimeoutMilliseconds: 30000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 50
   
   shardingRule:
     tables:
       book:
         actualDataNodes: ds.book_0,ds.book_1
         tableStrategy:
           inline:
             shardingColumn: book_id
             algorithmExpression: book_${book_id % 2}
         keyGenerator:
           type: SNOWFLAKE
           column: book_id
     bindingTables:
       - book
     defaultDatabaseStrategy:
       inline:
         shardingColumn: book_id
         algorithmExpression: ds_${book_id % 2}
     defaultTableStrategy:
       none:
   
   book table as follows:
   CREATE TABLE `book`  (
     `book_id` bigint(20) NOT NULL AUTO_INCREMENT ,
     `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
     `number` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
     `create_time` bigint(13) NULL DEFAULT NULL,
     PRIMARY KEY (`book_id`) USING BTREE
   ) ENGINE = InnoDB AUTO_INCREMENT = 1004 CHARACTER SET = utf8 COLLATE = 
utf8_general_ci  ROW_FORMAT = Compact;
   
   the book_0 and the book_1 are the same
   
   ### Example codes for reproduce this issue (such as a github link).
   select * from book where book_id = 1;  is wrong
   select * from book where name = 1; is ok
   
   Just because the book_id  is primary key

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to