Closed
Description
CrateDB version
5.7.0 and 5.6.3
CrateDB setup information
Number of nodes: 3
Problem description
The query below (an anonymised and simplified version of a much more complex query I was trying to run), fails with an ArrayIndexOutOfBoundsException
.
Please note that removing any one of the following elements the query runs without error messages:
unused_field1
- the
ORDER BY sorting_field
- the filters in the
sorting_field
subquery FROM information_schema.tables limit 1
Steps to Reproduce
WITH cte1
AS (
SELECT 'def' AS field1
,5 AS unused_field1
FROM information_schema.tables limit 1
)
,cte2
AS (
SELECT 'abc' AS field2
,cte1.field1
,(
SELECT count(*)
FROM (
SELECT 2 AS id
,'abc' AS field2
,'def' AS field1
) subquery2
WHERE 'abc' = subquery2.field2
AND cte1.field1 = subquery2.field1
) AS sorting_field
FROM cte1
)
SELECT (
SELECT cte2.field2
FROM cte2
WHERE cte2.field2 = subquery1.target_field2
ORDER BY sorting_field LIMIT 1
) AS field3
FROM (
SELECT 'abc' AS target_field2
,'def' AS field1
) subquery1;
Actual Result
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at io.crate.data.BiArrayRow.get(BiArrayRow.java:57)
at io.crate.execution.engine.collect.RowCollectExpression.setNextRow(RowCollectExpression.java:42)
at io.crate.execution.engine.collect.RowCollectExpression.setNextRow(RowCollectExpression.java:29)
at io.crate.execution.engine.sort.BoundedSortingLimitAndOffsetCollector.onNextRow(BoundedSortingLimitAndOffsetCollector.java:129)
at io.crate.data.BatchIterator.lambda$collect$1(BatchIterator.java:228)
at io.crate.data.BatchIterator.move(BatchIterator.java:164)
at io.crate.data.BatchIterator.lambda$move$0(BatchIterator.java:182)
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)
at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2179)
at io.crate.data.BatchIterators.lambda$collect$1(BatchIterators.java:50)
at io.crate.data.BatchIterator.move(BatchIterator.java:167)
at io.crate.data.BatchIterators.collect(BatchIterators.java:47)
at io.crate.data.CollectingRowConsumer.accept(CollectingRowConsumer.java:40)
at io.crate.execution.engine.InterceptingRowConsumer.lambda$tryForwardResult$1(InterceptingRowConsumer.java:93)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Expected Result
field3
--------
abc
(1 row)