Skip to content

Commit

Permalink
Windowing processing may have run into Exceptions when the whole tabl…
Browse files Browse the repository at this point in the history
…e was processed (#15064)

Earlier when the query was processing the whole table; the planning may have ended with a NPE; as it was not possible to create a scanquery from it.
  • Loading branch information
kgyrtkirk authored Oct 4, 2023
1 parent adef206 commit 3342e03
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1432,17 +1432,14 @@ private WindowOperatorQuery toWindowQuery()
if (windowing == null) {
return null;
}

final DataSource myDataSource;
if (dataSource instanceof TableDataSource) {
// In this case, we first plan a scan query to pull the results up for us before applying the window
myDataSource = new QueryDataSource(toScanQuery());
} else {
myDataSource = dataSource;
// We need a scan query to pull the results up for us before applying the window
// Returning null here to ensure that the planner generates that alternative
return null;
}

return new WindowOperatorQuery(
myDataSource,
dataSource,
new LegacySegmentSpec(Intervals.ETERNITY),
plannerContext.queryContextMap(),
windowing.getSignature(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;

/**
* These tests are file-based, look in resources -> calcite/tests/window for the set of test specifications.
Expand Down Expand Up @@ -101,6 +102,7 @@ public CalciteWindowQueryTest(
@SuppressWarnings("unchecked")
public void windowQueryTest() throws IOException
{
assumeTrue("These tests are only run in sqlCompatible mode!", NullHandling.sqlCompatible());
final Function<String, String> stringManipulator;
if (NullHandling.sqlCompatible()) {
stringManipulator = s -> "".equals(s) ? null : s;
Expand Down
29 changes: 29 additions & 0 deletions sql/src/test/resources/calcite/tests/window/no_grouping.sqlTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type: "operatorValidation"

sql: |
SELECT
m1,
COUNT(m1) OVER () cc
FROM druid.foo

expectedOperators:
- type: "naivePartition"
partitionColumns: []
- type: "window"
processor:
type: "framedAgg"
frame: { peerType: "ROWS", lowUnbounded: true, lowOffset: 0, uppUnbounded: true, uppOffset: 0 }
aggregations:
- type: "filtered"
aggregator: {"type":"count","name":"w0"}
filter:
type: not
field: {"type":"null","column":"m1"}
name: null
expectedResults:
- [1.0,6]
- [2.0,6]
- [3.0,6]
- [4.0,6]
- [5.0,6]
- [6.0,6]

0 comments on commit 3342e03

Please sign in to comment.