Skip to content

Commit

Permalink
Make WindowFrames more specific (#16741)
Browse files Browse the repository at this point in the history
Changes the WindowFrame internals / representation a bit; introduces dedicated frametypes for rows and groups which corresponds to the implemented processing methods
  • Loading branch information
kgyrtkirk authored Jul 25, 2024
1 parent ca78788 commit 7e3fab5
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 369 deletions.
3 changes: 0 additions & 3 deletions docs/querying/sql-window-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,8 @@ Druid has guardrail logic to prevent you from executing window function queries

For example:
- You cannot set expressions as bounds for window frames.
- You cannot use two FOLLOWING expressions in the window frame. For example: `ROWS BETWEEN 2 ROWS FOLLOWING and 3 ROWS FOLLOWING`.
- You can only use a RANGE frames when both endpoints are unbounded or current row.

If you write a query that violates one of these conditions, Druid throws an error: "The query contains a window frame which may return incorrect results. To disregard this warning, set `windowingStrictValidation` to false in the query context."

## Window function reference

|Function|Notes|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testWindowOnFooWithPartitionByAndInnerGroupBy(String contextName, Ma
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d0")
};
Expand Down Expand Up @@ -196,7 +196,7 @@ public void testWindowOnFooWithFirstWindowPartitionNextWindowEmpty(String contex
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d1")
};
Expand Down Expand Up @@ -306,7 +306,7 @@ public void testWindowOnFooWith2WindowsBothWindowsHavingPartitionByInnerGroupBy(
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d1")
};
Expand Down Expand Up @@ -419,7 +419,7 @@ public void testWindowOnFooWith2WindowsBothPartitionByWithOrderReversed(
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d0")
};
Expand Down Expand Up @@ -523,7 +523,7 @@ public void testWindowOnFooWithEmptyOverWithGroupBy(String contextName, Map<Stri
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d0")
};
Expand Down Expand Up @@ -589,7 +589,7 @@ public void testWindowOnFooWithNoGroupByAndPartition(String contextName, Map<Str
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -654,7 +654,7 @@ public void testWindowOnFooWithNoGroupByAndPartitionOnTwoElements(String context
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -725,7 +725,7 @@ public void testWindowOnFooWithNoGroupByAndPartitionByAnother(String contextName
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -793,7 +793,7 @@ public void testWindowOnFooWithGroupByAndInnerLimit(String contextName, Map<Stri
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "d1")
};
Expand Down Expand Up @@ -878,7 +878,7 @@ public void testWindowOnFooWithNoGroupByAndPartitionAndVirtualColumns(String con
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -951,7 +951,7 @@ public void testWindowOnFooWithNoGroupByAndEmptyOver(String contextName, Map<Str
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1028,17 +1028,7 @@ public void testWindowOnFooWithPartitionByOrderBYWithJoin(String contextName, Ma
.add("m2", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(
WindowFrame.PeerType.RANGE,
true,
0,
false,
0,
ImmutableList.of(new ColumnWithDirection(
"m1",
ColumnWithDirection.Direction.ASC
))
);
final WindowFrame theFrame = WindowFrame.forOrderBy("m1");
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1142,14 +1132,7 @@ public void testWindowOnFooWithEmptyOverWithJoin(String contextName, Map<String,
.add("m2", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(
WindowFrame.PeerType.ROWS,
true,
0,
true,
0,
null
);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1233,7 +1216,7 @@ public void testWindowOnFooWithDim2(String contextName, Map<String, Object> cont
.add("cc", ColumnType.DOUBLE)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1322,14 +1305,7 @@ public void testWindowOnFooWithEmptyOverWithUnnest(String contextName, Map<Strin
.add("d3", ColumnType.STRING)
.build();

final WindowFrame theFrame = new WindowFrame(
WindowFrame.PeerType.ROWS,
true,
0,
true,
0,
null
);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1412,14 +1388,7 @@ public void testWindowOnFooWithPartitionByAndWithUnnest(String contextName, Map<
.add("d3", ColumnType.STRING)
.build();

final WindowFrame theFrame = new WindowFrame(
WindowFrame.PeerType.ROWS,
true,
0,
true,
0,
null
);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new DoubleSumAggregatorFactory("w0", "m1")
};
Expand Down Expand Up @@ -1796,7 +1765,7 @@ public void testSelectWithWikipedia(String contextName, Map<String, Object> cont
.add("cc", ColumnType.LONG)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new LongSumAggregatorFactory("w0", "added")
};
Expand Down Expand Up @@ -1887,7 +1856,7 @@ public void testSelectWithWikipediaWithPartitionKeyNotInSelect(String contextNam
.add("cc", ColumnType.LONG)
.build();

final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new LongSumAggregatorFactory("w0", "added")
};
Expand Down Expand Up @@ -2001,7 +1970,7 @@ public void testGroupByWithWikipedia(String contextName, Map<String, Object> con
.build();


final WindowFrame theFrame = new WindowFrame(WindowFrame.PeerType.ROWS, true, 0, true, 0, null);
final WindowFrame theFrame = WindowFrame.unbounded();
final AggregatorFactory[] theAggs = {
new LongSumAggregatorFactory("w0", "d1")
};
Expand Down
Loading

0 comments on commit 7e3fab5

Please sign in to comment.