Skip to content

Commit 6111dc6

Browse files
committed
Adds parsing, planning, and evaluation of window functions and window clause
Adds AST modeling for window functions Adds plan modeling for window functions Deprecates old window function AST APIs due to incompatibility Adds RANK, DENSE_RANK window functions Adds ROW_NUMBER window function Adds LAG and LEAD window functions Adds support for referencing window clause from window functions
1 parent 73d9f09 commit 6111dc6

File tree

54 files changed

+3330
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3330
-105
lines changed

partiql-ast/api/partiql-ast.api

Lines changed: 278 additions & 2 deletions
Large diffs are not rendered by default.

partiql-ast/src/main/java/org/partiql/ast/AstVisitor.java

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.partiql.ast.expr.ExprVarRef;
5757
import org.partiql.ast.expr.ExprVariant;
5858
import org.partiql.ast.expr.ExprWindow;
59+
import org.partiql.ast.expr.ExprWindowFunction;
5960
import org.partiql.ast.expr.PathStep;
6061
import org.partiql.ast.graph.GraphLabel;
6162
import org.partiql.ast.graph.GraphMatch;
@@ -323,6 +324,126 @@ public R visitExprArray(ExprArray node, C ctx) {
323324
return defaultVisit(node, ctx);
324325
}
325326

327+
/**
328+
* TODO
329+
* @param node TODO
330+
* @param ctx TODO
331+
* @return TODO
332+
*/
333+
public R visitExprWindowFunction(ExprWindowFunction node, C ctx) {
334+
return defaultVisit(node, ctx);
335+
}
336+
337+
/**
338+
* TODO
339+
* @param node TODO
340+
* @param ctx TODO
341+
* @return TODO
342+
*/
343+
public R visitWindowFunctionType(WindowFunctionType node, C ctx) {
344+
return node.accept(this, ctx);
345+
}
346+
347+
/**
348+
* TODO
349+
* @param node TODO
350+
* @param ctx TODO
351+
* @return TODO
352+
*/
353+
public R visitWindowFunctionTypeNoArg(WindowFunctionType.NoArg node, C ctx) {
354+
return defaultVisit(node, ctx);
355+
}
356+
357+
/**
358+
* TODO
359+
* @param node TODO
360+
* @param ctx TODO
361+
* @return TODO
362+
*/
363+
public R visitWindowReference(WindowReference node, C ctx) {
364+
return node.accept(this, ctx);
365+
}
366+
367+
/**
368+
* TODO
369+
* @param node TODO
370+
* @param ctx TODO
371+
* @return TODO
372+
*/
373+
public R visitWindowPartitionClause(WindowPartitionClause node, C ctx) {
374+
return node.accept(this, ctx);
375+
}
376+
377+
/**
378+
* TODO
379+
* @param node TODO
380+
* @param ctx TODO
381+
* @return TODO
382+
*/
383+
public R visitWindowOrderClause(WindowOrderClause node, C ctx) {
384+
return node.accept(this, ctx);
385+
}
386+
387+
/**
388+
* TODO
389+
* @param node TODO
390+
* @param ctx TODO
391+
* @return TODO
392+
*/
393+
public R visitWindowPartition(WindowPartition node, C ctx) {
394+
return node.accept(this, ctx);
395+
}
396+
397+
/**
398+
* TODO
399+
* @param node TODO
400+
* @param ctx TODO
401+
* @return TODO
402+
*/
403+
public R visitWindowPartitionName(WindowPartition.Name node, C ctx) {
404+
return defaultVisit(node, ctx);
405+
}
406+
407+
/**
408+
* TODO
409+
* @param node TODO
410+
* @param ctx TODO
411+
* @return TODO
412+
*/
413+
public R visitWindowReferenceName(WindowReference.Name node, C ctx) {
414+
return defaultVisit(node, ctx);
415+
}
416+
417+
/**
418+
* TODO
419+
* @param node TODO
420+
* @param ctx TODO
421+
* @return TODO
422+
*/
423+
public R visitWindowReferenceInLineSpecification(WindowReference.InLineSpecification node, C ctx) {
424+
return defaultVisit(node, ctx);
425+
}
426+
427+
/**
428+
* TODO
429+
* @param node TODO
430+
* @param ctx TODO
431+
* @return TODO
432+
*/
433+
public R visitWindowFunctionTypeLagOrLead(WindowFunctionType.LeadOrLag node, C ctx) {
434+
return defaultVisit(node, ctx);
435+
}
436+
437+
/**
438+
* TODO
439+
* @param node TODO
440+
* @param ctx TODO
441+
* @return TODO
442+
*/
443+
public R visitWindowSpecification(WindowSpecification node, C ctx) {
444+
return defaultVisit(node, ctx);
445+
}
446+
326447
public R visitExprBag(ExprBag node, C ctx) {
327448
return defaultVisit(node, ctx);
328449
}
@@ -515,6 +636,14 @@ public R visitLet(Let node, C ctx) {
515636
return defaultVisit(node, ctx);
516637
}
517638

639+
public R visitWindowClause(WindowClause node, C ctx) {
640+
return defaultVisit(node, ctx);
641+
}
642+
643+
public R visitWindowDefinition(WindowClause.WindowDefinition node, C ctx) {
644+
return defaultVisit(node, ctx);
645+
}
646+
518647
public R visitWith(With node, C ctx) {
519648
return defaultVisit(node, ctx);
520649
}

partiql-ast/src/main/java/org/partiql/ast/QueryBody.java

Lines changed: 95 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,43 @@ public static class SFW extends QueryBody {
4040
@Nullable
4141
private final Expr having;
4242

43+
@Nullable
44+
private final WindowClause windowClause;
45+
46+
/**
47+
* Constructs a new SFW query body.
48+
* @param select the select clause
49+
* @param exclude the exclude clause
50+
* @param from the from clause
51+
* @param let the let clause
52+
* @param where the where clause
53+
* @param groupBy the group by clause
54+
* @param having the having clause
55+
* @param window the window clause
56+
*/
57+
public SFW(@NotNull Select select, @Nullable Exclude exclude, @NotNull From from,
58+
@Nullable Let let, @Nullable Expr where, @Nullable GroupBy groupBy,
59+
@Nullable Expr having, @Nullable WindowClause window) {
60+
this.select = select;
61+
this.exclude = exclude;
62+
this.from = from;
63+
this.let = let;
64+
this.where = where;
65+
this.groupBy = groupBy;
66+
this.having = having;
67+
this.windowClause = window;
68+
}
69+
70+
/**
71+
* Constructs a new SFW query body.
72+
* @param select the select clause
73+
* @param exclude the exclude clause
74+
* @param from the from clause
75+
* @param let the let clause
76+
* @param where the where clause
77+
* @param groupBy the group by clause
78+
* @param having the having clause
79+
*/
4380
public SFW(@NotNull Select select, @Nullable Exclude exclude, @NotNull From from,
4481
@Nullable Let let, @Nullable Expr where, @Nullable GroupBy groupBy, @Nullable Expr having) {
4582
this.select = select;
@@ -49,61 +86,100 @@ public SFW(@NotNull Select select, @Nullable Exclude exclude, @NotNull From from
4986
this.where = where;
5087
this.groupBy = groupBy;
5188
this.having = having;
89+
this.windowClause = null;
5290
}
5391

54-
@NotNull
55-
@Override
56-
public List<AstNode> getChildren() {
57-
List<AstNode> kids = new ArrayList<>();
58-
kids.add(select);
59-
if (exclude != null) kids.add(exclude);
60-
kids.add(from);
61-
if (let != null) kids.add(let);
62-
if (where != null) kids.add(where);
63-
if (groupBy != null) kids.add(groupBy);
64-
if (having != null) kids.add(having);
65-
return kids;
66-
}
67-
68-
@Override
69-
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
70-
return visitor.visitQueryBodySFW(this, ctx);
71-
}
72-
92+
/**
93+
* Returns the select clause.
94+
* @return the select clause
95+
*/
7396
@NotNull
7497
public Select getSelect() {
7598
return this.select;
7699
}
77100

101+
/**
102+
* Returns the exclude clause, if any.
103+
* @return the exclude clause, or null if not present
104+
*/
78105
@Nullable
79106
public Exclude getExclude() {
80107
return this.exclude;
81108
}
82109

110+
/**
111+
* Returns the from clause.
112+
* @return the from clause
113+
*/
83114
@NotNull
84115
public From getFrom() {
85116
return this.from;
86117
}
87118

119+
/**
120+
* Returns the let clause, if any.
121+
* @return the let clause, or null if not present
122+
*/
88123
@Nullable
89124
public Let getLet() {
90125
return this.let;
91126
}
92127

128+
/**
129+
* Returns the where clause, if any.
130+
* @return the where clause, or null if not present
131+
*/
93132
@Nullable
94133
public Expr getWhere() {
95134
return this.where;
96135
}
97136

137+
/**
138+
* Returns the group by clause, if any.
139+
* @return the group by clause, or null if not present
140+
*/
98141
@Nullable
99142
public GroupBy getGroupBy() {
100143
return this.groupBy;
101144
}
102145

146+
/**
147+
* Returns the having clause, if any.
148+
* @return the having clause, or null if not present
149+
*/
103150
@Nullable
104151
public Expr getHaving() {
105152
return this.having;
106153
}
154+
155+
/**
156+
* Returns the window clause, if any.
157+
* @return the window clause, or null if not present
158+
*/
159+
@Nullable
160+
public WindowClause getWindow() {
161+
return this.windowClause;
162+
}
163+
164+
@NotNull
165+
@Override
166+
public List<AstNode> getChildren() {
167+
List<AstNode> kids = new ArrayList<>();
168+
kids.add(select);
169+
if (exclude != null) kids.add(exclude);
170+
kids.add(from);
171+
if (let != null) kids.add(let);
172+
if (where != null) kids.add(where);
173+
if (groupBy != null) kids.add(groupBy);
174+
if (having != null) kids.add(having);
175+
if (windowClause != null) kids.add(windowClause);
176+
return kids;
177+
}
178+
179+
@Override
180+
public <R, C> R accept(@NotNull AstVisitor<R, C> visitor, C ctx) {
181+
return visitor.visitQueryBodySFW(this, ctx);
182+
}
107183
}
108184

109185
/**

0 commit comments

Comments
 (0)