You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "lin-fy (via GitHub)" <gi...@apache.org> on 2023/04/11 08:57:03 UTC

[GitHub] [shardingsphere] lin-fy opened a new issue, #25106: sharejdbc5.2.1 using custom algorithm for sharding, and Error reporting when executing select sql with NPE(GroupByMemoryMergedResult.getValueCaseSensitiveFromTables)

lin-fy opened a new issue, #25106:
URL: https://github.com/apache/shardingsphere/issues/25106

   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response anymore and we cannot reproduce it on current information, we will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   springboot  2.7.6
   shardingsphere-jdbc-core-spring-boot-starter 5.2.1
   mybatis-plus-boot-starter 3.5.2
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   
   ### Expected behavior
   SQL executed successfully
   
   ### Actual behavior
   ![1 (2)](https://user-images.githubusercontent.com/38689113/231105220-56014759-079e-41d4-badb-b9647540ecc8.png)
   ![2](https://user-images.githubusercontent.com/38689113/231105234-96155ac6-2f05-422c-a13b-30f37ab691e4.png)
   ```### Cause: java.lang.NullPointerException
           at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
           at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:153)
           at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:171)
           at org.apache.ibatis.session.defaults.DefaultSqlSession.select(DefaultSqlSession.java:161)
           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)
           ... 128 common frames omitted
   Caused by: java.lang.NullPointerException: null
           at org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult.getValueCaseSensitiveFromTables(GroupByMemoryMergedResult.java:135)
           at org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult.getValueCaseSensitive(GroupByMemoryMergedResult.java:125)
           at org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult.init(GroupByMemoryMergedResult.java:73)
           at org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult.init(GroupByMemoryMergedResult.java:53)
           at org.apache.shardingsphere.infra.merge.result.impl.memory.MemoryMergedResult.<init>(MemoryMergedResult.java:52)
           at org.apache.shardingsphere.sharding.merge.dql.groupby.GroupByMemoryMergedResult.<init>(GroupByMemoryMergedResult.java:56)
           at org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger.getGroupByMergedResult(ShardingDQLResultMerger.java:118)
           at org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger.build(ShardingDQLResultMerger.java:88)
           at org.apache.shardingsphere.sharding.merge.dql.ShardingDQLResultMerger.merge(ShardingDQLResultMerger.java:66)
           at org.apache.shardingsphere.infra.merge.MergeEngine.executeMerge(MergeEngine.java:82)
           at org.apache.shardingsphere.infra.merge.MergeEngine.merge(MergeEngine.java:71)
           at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.mergeQuery(ShardingSpherePreparedStatement.java:517)
           at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.getResultSet(ShardingSpherePreparedStatement.java:465)
           at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke(Method.java:498)
   ```
   
   ### Reason analyze (If you can)
   I tried to review this bug in local but failed. I executed it locally successfully, but it reported an error when running the jar package in the online Linux environment. 
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   This is the sql i want to execute :
   ```
   SELECT
               lpv.id,
               lpv.log_id as logId,
               lpv.millisecond,
               lpv.trigger_time as triggerTime,
               lpv.url,
               lpv.create_time as createTime,
               lpv.entry_time as entryTime,
               log.appid,
               log.equip_type as equipType,
               log.ip,
               log.uid,
               log.session_id as sessionId,
               zk_phone_key.phone,
               lpv.page_id as pageId
           FROM
           zk_log log
           JOIN zk_log_pv_view lpv ON log.id = lpv.log_id
           JOIN zk_phone_key ON zk_phone_key.session_id = log.session_id
           <where>
               <if test="startTime != null and endTime != null ">
                   and log.create_time BETWEEN #{startTime} AND #{endTime}
               </if>
               <if test="appid != null and appid != ''">
                   and log.appid = #{appid}
               </if>
               <if test="equipType != null and equipType != ''">
                   and log.equip_type = #{equipType}
               </if>
               <if test="url != null and url != ''">
                   and lpv.url = #{url}
               </if>
               <if test="urlReg != null and urlReg != ''">
                   and lpv.url REGEXP #{urlReg}
               </if>
           </where>
   ```
   yml:
   ```
     shardingsphere:
       datasource:
         names: zkLogStat
         zkLogStat:
           type: com.alibaba.druid.pool.DruidDataSource
           driverClassName: com.mysql.jdbc.Driver
           url: jdbc:mysql://localhost:3306/zk_log?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
           username: root
           password: root
       rules:
         sharding:
           tables:
             zk_log:
               actualDataNodes: zkLogStat.zk_log_$->{2023}$->{(1..2).collect{t ->t.toString().padLeft(2,'0')}}
               tableStrategy:
                 standard:
                   shardingColumn: create_time
                   shardingAlgorithmName: log-inline
             zk_log_event:
               actualDataNodes: zkLogStat.zk_log_event_$->{2023}$->{(1..2).collect{t ->t.toString().padLeft(2,'0')}}
               tableStrategy:
                 standard:
                   shardingColumn: create_time
                   shardingAlgorithmName: log-inline
           sharding-algorithms:
             log-inline:
               type: QUARTER_HIS
               props:
                 strategy: STANDARD
                 algorithmClassName: QuarterStandardShardingAlgorithm
           binding‐tables: #
             - zk_log, zk_log_event
       props:
         sql-show: true
   
   ```
   QuarterStandardShardingAlgorithm.java
   ```
   
   public class QuarterStandardShardingAlgorithm implements StandardShardingAlgorithm<Date> {
   
       private Properties props;
   
       /**
        * add
        *
        * @param collection
        * @param preciseShardingValue
        * @return
        */
       @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<Date> preciseShardingValue) {
           StringBuilder resultTableName = new StringBuilder();
           String logicTableName = preciseShardingValue.getLogicTableName();
           resultTableName.append(logicTableName)
    .append("_").append(DateUtil.year(preciseShardingValue.getValue())).append("0").append(DateUtil.quarter(preciseShardingValue.getValue()));
           return resultTableName.toString();
   
       }
   
       /**
        * select
        *
        * @param collection
        * @param rangeShardingValue
        * @return
        */
       @Override
       public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Date> rangeShardingValue) {
           String logicTableName = rangeShardingValue.getLogicTableName();
           Range<Date> valueRange = rangeShardingValue.getValueRange();
           Date startTime = valueRange.lowerEndpoint();
           Date endTime = valueRange.upperEndpoint();
           Integer endYear = DateUtil.year(endTime);
           Integer endQuarter = DateUtil.quarter(endTime);
   
   
           HashSet<String> tableName = new HashSet<>();
           StringBuilder resultTableName = null;
           Integer tempYear = DateUtil.year(startTime);
           Integer tempQuarter = DateUtil.quarter(startTime);
   
           while (endYear > tempYear ||  endQuarter >= tempQuarter) {
               resultTableName = new StringBuilder();
               resultTableName.append(logicTableName).append("_").append(tempYear).append("0").append(tempQuarter);
               tableName.add(resultTableName.toString());
   
               if (tempQuarter == 4) {
                   tempQuarter = 1;
                   tempYear++;
               } else {
                   tempQuarter++;
               }
           }
           return tableName;
       }
   }
   ```
   
   
   ### 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-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] lin-fy closed issue #25106: sharejdbc5.2.1 using custom algorithm for sharding, and Error reporting when executing select sql with NPE(GroupByMemoryMergedResult.getValueCaseSensitiveFromTables)

Posted by "lin-fy (via GitHub)" <gi...@apache.org>.
lin-fy closed issue #25106: sharejdbc5.2.1 using  custom algorithm for sharding, and Error reporting when executing select sql with NPE(GroupByMemoryMergedResult.getValueCaseSensitiveFromTables)
URL: https://github.com/apache/shardingsphere/issues/25106


-- 
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-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org