You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/09/06 08:20:43 UTC

[GitHub] [ignite] zstan commented on a change in pull request #9148: IGNITE-14681 Calcite engine. Extend return type of sum() aggregate function

zstan commented on a change in pull request #9148:
URL: https://github.com/apache/ignite/pull/9148#discussion_r702701146



##########
File path: modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/BaseAggregateTest.java
##########
@@ -512,6 +513,98 @@ public void sumOnDifferentRowsCount() throws IgniteCheckedException {
         }
     }
 
+    /** */
+    @Test
+    public void sumIntegerOverflow() {
+        ExecutionContext<Object[]> ctx = executionContext(F.first(nodes()), UUID.randomUUID(), 0);
+        IgniteTypeFactory tf = ctx.getTypeFactory();
+        RelDataType rowType = TypeUtils.createRowType(tf, int.class, int.class);
+        ScanNode<Object[]> scan = new ScanNode<>(ctx, rowType, Arrays.asList(
+            row(0, Integer.MAX_VALUE / 2),
+            row(0, Integer.MAX_VALUE / 2 + 11)
+        ));
+
+        AggregateCall call = AggregateCall.create(
+            SqlStdOperatorTable.SUM,
+            false,
+            false,
+            false,
+            ImmutableIntList.of(1),
+            -1,
+            RelCollations.EMPTY,
+            tf.createJavaType(BigDecimal.class),
+            null);
+
+        ImmutableList<ImmutableBitSet> grpSets = ImmutableList.of(ImmutableBitSet.of(0));
+
+        RelDataType aggRowType = TypeUtils.createRowType(tf, int.class);
+
+        SingleNode<Object[]> aggChain = createAggregateNodesChain(
+            ctx,
+            grpSets,
+            call,
+            rowType,
+            aggRowType,
+            rowFactory(),
+            scan
+        );
+
+        RootNode<Object[]> root = new RootNode<>(ctx, aggRowType);
+        root.register(aggChain);
+
+        assertTrue(root.hasNext());
+
+        Assert.assertArrayEquals(row(0, new BigDecimal(Integer.MAX_VALUE).add(new BigDecimal(10))), root.next());

Review comment:
       it`s a bit confused why 
   
   >             row(0, Integer.MAX_VALUE / 2),
   and
   >            row(0, Integer.MAX_VALUE / 2 + 11)
   gives 
   > new BigDecimal(Integer.MAX_VALUE).add(new BigDecimal(10) ))
   may be more clear to rewrite test with  Integer.MIN_VALUE ?  i.e. :
               > row(0, Integer.MIN_VALUE / 2),
               > row(0, Integer.MIN_VALUE / 2 - 11)
   
   > Assert.assertArrayEquals(row(0, new BigDecimal(Integer.MIN_VALUE).add(new BigDecimal(-11))), root.next());
   but it`s up to you of course.




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

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