You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "Akshat-Jain (via GitHub)" <gi...@apache.org> on 2024/08/08 07:33:38 UTC

[PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Akshat-Jain opened a new pull request, #16865:
URL: https://github.com/apache/druid/pull/16865

   ### Description
   
   Currently, queries like the following give IndexOutOfBoundsException error because we attempt to create a frame writer for empty RAC.
   
   ```sql
   select countryName, row_number() over () as c1
   from wikipedia
   where countryName in ('non-existent-country')
   group by countryName, cityName, channel
   ```
   
   The above query gives:
   
   ```java
    Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
   	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
   	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
   	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
   	at java.base/java.util.Objects.checkIndex(Objects.java:374)
   	at java.base/java.util.ArrayList.get(ArrayList.java:459)
   	at org.apache.druid.query.rowsandcols.ConcatRowsAndColumns.findColumn(ConcatRowsAndColumns.java:95)
   	at org.apache.druid.query.rowsandcols.semantic.DefaultColumnSelectorFactoryMaker$ColumnAccessorBasedColumnSelectorFactory.withColumnAccessor(DefaultColumnSelectorFactoryMaker.java:183)
   	at org.apache.druid.query.rowsandcols.semantic.DefaultColumnSelectorFactoryMaker$ColumnAccessorBasedColumnSelectorFactory.makeDimensionSelector(DefaultColumnSelectorFactoryMaker.java:83)
   	at org.apache.druid.frame.field.FieldWriters.makeStringWriter(FieldWriters.java:132)
   	at org.apache.druid.frame.field.FieldWriters.create(FieldWriters.java:78)
   	at org.apache.druid.frame.write.RowBasedFrameWriterFactory.makeFieldWriters(RowBasedFrameWriterFactory.java:117)
   	at org.apache.druid.frame.write.RowBasedFrameWriterFactory.newFrameWriter(RowBasedFrameWriterFactory.java:76)
   	at org.apache.druid.msq.querykit.WindowOperatorQueryFrameProcessor.createFrameWriterIfNeeded(WindowOperatorQueryFrameProcessor.java:407)
   	at org.apache.druid.msq.querykit.WindowOperatorQueryFrameProcessor.flushAllRowsAndCols(WindowOperatorQueryFrameProcessor.java:394)
   ```
   
   This PR fixes it and adds a test that fails with the above stacktrace without this PR's change.
   
   <hr>
   
   This PR has:
   
   - [x] been self-reviewed.
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1709057595


##########
processing/src/main/java/org/apache/druid/query/rowsandcols/ConcatRowsAndColumns.java:
##########
@@ -92,6 +92,9 @@ public Column findColumn(String name)
     if (columnCache.containsKey(name)) {
       return columnCache.get(name);
     } else {
+      if (racBuffer.isEmpty()) {

Review Comment:
   @kgyrtkirk Done



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1708930747


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/WindowOperatorQueryFrameProcessor.java:
##########
@@ -326,6 +326,9 @@ public Closeable goOrContinue(Closeable continuationObject, Receiver receiver)
    */
   private void runAllOpsOnMultipleRac(ArrayList<RowsAndColumns> listOfRacs)
   {
+    if (listOfRacs.isEmpty()) {

Review Comment:
   Have moved the change to `ConcatRowsAndColumns`, and added a test in `ConcatRowsAndColumnsTest` which fails with `IndexOutOfBoundsException` without the code changes.
   
   Hope that works.



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe merged PR #16865:
URL: https://github.com/apache/druid/pull/16865


-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "Akshat-Jain (via GitHub)" <gi...@apache.org>.
Akshat-Jain commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1708848385


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/WindowOperatorQueryFrameProcessor.java:
##########
@@ -203,7 +203,9 @@ public ReturnOrAwait<Object> runIncrementally(IntSet readableInputs)
         final Frame frame = inputChannel.read();
         convertRowFrameToRowsAndColumns(frame);
       } else if (inputChannel.isFinished()) {
-        runAllOpsOnMultipleRac(frameRowsAndCols);
+        if (!frameRowsAndCols.isEmpty()) {
+          runAllOpsOnMultipleRac(frameRowsAndCols);

Review Comment:
   Have made the change.



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1708885839


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/WindowOperatorQueryFrameProcessor.java:
##########
@@ -326,6 +326,9 @@ public Closeable goOrContinue(Closeable continuationObject, Receiver receiver)
    */
   private void runAllOpsOnMultipleRac(ArrayList<RowsAndColumns> listOfRacs)
   {
+    if (listOfRacs.isEmpty()) {

Review Comment:
   I don't think we should workaround this with such an `if`
   this will not fix `ConcatRowsAndColumns` - or changes its contract ; so the problem lives on...but will not be encountered "here"...
   
   please:
   * add testcase which reproduces the issue to `RowsAndColumnsTestBase`
   * run `ConcatRowsAndColumnsTest`
   * fix `ConcatRowsAndColumns`
   * you may optionally also remove this line
   



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1708843561


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/WindowOperatorQueryFrameProcessor.java:
##########
@@ -203,7 +203,9 @@ public ReturnOrAwait<Object> runIncrementally(IntSet readableInputs)
         final Frame frame = inputChannel.read();
         convertRowFrameToRowsAndColumns(frame);
       } else if (inputChannel.isFinished()) {
-        runAllOpsOnMultipleRac(frameRowsAndCols);
+        if (!frameRowsAndCols.isEmpty()) {
+          runAllOpsOnMultipleRac(frameRowsAndCols);

Review Comment:
   Shouldn't the check be inside runAllOpsMulitpleRAC ?



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Fix IndexOutOfBoundsException for MSQ window function queries with empty RAC (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16865:
URL: https://github.com/apache/druid/pull/16865#discussion_r1708950629


##########
processing/src/main/java/org/apache/druid/query/rowsandcols/ConcatRowsAndColumns.java:
##########
@@ -92,6 +92,9 @@ public Column findColumn(String name)
     if (columnCache.containsKey(name)) {
       return columnCache.get(name);
     } else {
+      if (racBuffer.isEmpty()) {

Review Comment:
   while we are at this; can you also add a `Preconditions` check to the constructor?
   
   please also check&test other possibly affected methods as well ; I guess `getColumnNames()` would throw the same error



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org