[
https://issues.apache.org/jira/browse/IGNITE-16191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17484710#comment-17484710
]
Andrey Mashenkov edited comment on IGNITE-16191 at 1/31/22, 2:21 PM:
---------------------------------------------------------------------
Seems, queries like this are not correct:
{noformat}
SELECT COUNT(null, 1){noformat}
The SQL standard says that COUNT accepts a single argument.
I wrote a test and it looks fine.
{code:java}
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (3, 4), (3, 4), (2, 4), (3, null), (null, 4),
(null, null);
query IIIII
SELECT COUNT(*), COUNT(i), COUNT(j), COUNT(COALESCE(i, j)), COUNT(null) FROM
integers
----
6
4
4
5
0 {code}
was (Author: amashenkov):
Seems, queries like this are not correct:
{noformat}
SELECT COUNT(null, 1){noformat}
The SQL standard says that COUNT accepts a single argument.
I wrote a test and it looks fine.
{code:java}
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (3, 4), (3, 4), (2, 4), (3, null), (null, 4),
(null, null);
query IIIII
SELECT COUNT(*), COUNT(i), COUNT(j), COUNT(COALESCE(i, j)), COUNT(null) FROM
integers
----
6
4
4
5
0 {code}
> Calcite engine. Unexpected result of COUNT with multiple parameters
> -------------------------------------------------------------------
>
> Key: IGNITE-16191
> URL: https://issues.apache.org/jira/browse/IGNITE-16191
> Project: Ignite
> Issue Type: Bug
> Components: sql
> Reporter: Aleksey Plekhanov
> Assignee: Andrey Mashenkov
> Priority: Major
> Labels: calcite2-required, calcite3-required
>
> The calcite engine supports the {{COUNT}} aggregate function with multiple
> parameters. Such a function should return the number of input rows for which
> parameters are wholly not null.
> But currently queries like:
> {noformat}
> SELECT COUNT(null, 1)
> SELECT COUNT(1, null)
> {noformat}
> Return 0 (expected 1).
> Query:
> {noformat}
> SELECT COUNT(null, null)
> {noformat}
> Throw an exception:
> {noformat}
> Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
> at java.util.ArrayList.rangeCheck(ArrayList.java:657)
> at java.util.ArrayList.get(ArrayList.java:433)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.AccumulatorsFactory$WrapperPrototype$1.apply(AccumulatorsFactory.java:226)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.AccumulatorsFactory$WrapperPrototype$1.apply(AccumulatorsFactory.java:223)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.AccumulatorsFactory$AccumulatorWrapperImpl.add(AccumulatorsFactory.java:305)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.rel.HashAggregateNode$Grouping.addOnMapper(HashAggregateNode.java:294)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.rel.HashAggregateNode$Grouping.add(HashAggregateNode.java:265)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.rel.HashAggregateNode$Grouping.access$100(HashAggregateNode.java:222)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.rel.HashAggregateNode.push(HashAggregateNode.java:127)
> at
> org.apache.ignite.internal.processors.query.calcite.exec.rel.ScanNode.push(ScanNode.java:107)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)