You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/02/23 11:00:59 UTC

[GitHub] [shardingsphere] terrymanu opened a new issue #15593: Fix IT error for accurate of AVG

terrymanu opened a new issue #15593:
URL: https://github.com/apache/shardingsphere/issues/15593


   The IT result is different with load data from database.
   
   Case name: SELECT AVG(user_id) AS user_id_avg FROM t_order
   Expected: is "19"
   but: was "19.5000"
   
   Please see `dql-integration-test-cases.xml` and search `FIXME #`
   


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



[GitHub] [shardingsphere] strongduanmu commented on issue #15593: Fix IT error for accurate of AVG

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #15593:
URL: https://github.com/apache/shardingsphere/issues/15593#issuecomment-1049471467


   I have investigated the current processing logic of ShardingSphere MergeEngine for AVG functions, and they all use the precision of 4 decimal places. This logic needs to be investigated and kept consistent with the database.
   
   ```java
   /**
    * Average aggregation unit.
    */
   @RequiredArgsConstructor
   public final class AverageAggregationUnit implements AggregationUnit {
       
       private BigDecimal count;
       
       private BigDecimal sum;
       
       @Override
       public void merge(final List<Comparable<?>> values) {
           if (null == values || null == values.get(0) || null == values.get(1)) {
               return;
           }
           if (null == count) {
               count = new BigDecimal("0");
           }
           if (null == sum) {
               sum = new BigDecimal("0");
           }
           count = count.add(new BigDecimal(values.get(0).toString()));
           sum = sum.add(new BigDecimal(values.get(1).toString()));
       }
       
       @Override
       public Comparable<?> getResult() {
           if (null == count || BigDecimal.ZERO.equals(count)) {
               return count;
           }
           // TODO use metadata to fetch float number precise for database field
           return sum.divide(count, 4, RoundingMode.HALF_UP);
       }
   }
   ```


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



[GitHub] [shardingsphere] strongduanmu commented on issue #15593: Fix IT error for accurate of AVG

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #15593:
URL: https://github.com/apache/shardingsphere/issues/15593#issuecomment-1048673317


   @terrymanu Thank you for your feedback, I will investigate this issue.
   
   


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