summaryrefslogtreecommitdiff
path: root/src/urweb.grm
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-06-02 16:00:50 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-06-02 16:00:50 -0400
commit6f28076613c975e382014cbcb074cbaa22fdf3e3 (patch)
treeda888caf3fa14afe2943de2d9c8c82830c209de1 /src/urweb.grm
parentf734c97cc7f02a8ada114be16779991b59e6761e (diff)
Compiled a window function use
Diffstat (limited to 'src/urweb.grm')
-rw-r--r--src/urweb.grm90
1 files changed, 67 insertions, 23 deletions
diff --git a/src/urweb.grm b/src/urweb.grm
index 1419ef3f..831ec4a8 100644
--- a/src/urweb.grm
+++ b/src/urweb.grm
@@ -332,7 +332,7 @@ fun parseStyle s pos =
| UNION | INTERSECT | EXCEPT
| LIMIT | OFFSET | ALL
| TRUE | FALSE | CAND | OR | NOT
- | COUNT | AVG | SUM | MIN | MAX
+ | COUNT | AVG | SUM | MIN | MAX | RANK
| ASC | DESC | RANDOM
| INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
| CURRENT_TIMESTAMP
@@ -340,6 +340,7 @@ fun parseStyle s pos =
| CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
| JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
| CIF | CTHEN | CELSE
+ | OVER | PARTITION
%nonterm
file of decl list
@@ -455,6 +456,7 @@ fun parseStyle s pos =
| selis of select_item list
| select of select
| sqlexp of exp
+ | window of unit option
| wopt of exp
| groupi of group_item
| groupis of group_item list
@@ -2025,29 +2027,68 @@ sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", In
| NULL (sql_inject ((EVar (["Basis"], "None", Infer),
s (NULLleft, NULLright))))
- | COUNT LPAREN STAR RPAREN (let
- val loc = s (COUNTleft, RPARENright)
- in
- (EVar (["Basis"], "sql_count", Infer), loc)
- end)
- | COUNT LPAREN sqlexp RPAREN (let
- val loc = s (COUNTleft, RPARENright)
-
- val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
- val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
- e), loc)
- in
- (EApp (e, sqlexp), loc)
- end)
- | sqlagg LPAREN sqlexp RPAREN (let
- val loc = s (sqlaggleft, RPARENright)
+ | COUNT LPAREN STAR RPAREN window (let
+ val loc = s (COUNTleft, windowright)
+ in
+ case window of
+ NONE => (EVar (["Basis"], "sql_count", Infer), loc)
+ | SOME _ =>
+ let
+ val e = (EVar (["Basis"], "sql_window_count", Infer), loc)
+ in
+ (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc)
+ end
+ end)
+ | RANK UNIT window (let
+ val loc = s (RANKleft, windowright)
+ val e = (EVar (["Basis"], "sql_window_rank", Infer), loc)
+ in
+ (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc)
+ end)
+ | COUNT LPAREN sqlexp RPAREN window (let
+ val loc = s (COUNTleft, windowright)
+
+ val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
+ in
+ case window of
+ NONE =>
+ let
+ val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
+ e), loc)
+ in
+ (EApp (e, sqlexp), loc)
+ end
+ | SOME _ =>
+ let
+ val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
+ e), loc)
+ val e = (EApp (e, sqlexp), loc)
+ in
+ (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc)
+ end
+ end)
+ | sqlagg LPAREN sqlexp RPAREN window (let
+ val loc = s (sqlaggleft, windowright)
- val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
- val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
- e), loc)
- in
- (EApp (e, sqlexp), loc)
- end)
+ val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
+ in
+ case window of
+ NONE =>
+ let
+ val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
+ e), loc)
+ in
+ (EApp (e, sqlexp), loc)
+ end
+ | SOME _ =>
+ let
+ val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
+ e), loc)
+ val e = (EApp (e, sqlexp), loc)
+ in
+ (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc)
+ end
+ end)
| COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
(let
val loc = s (COALESCEright, sqlexp2right)
@@ -2072,6 +2113,9 @@ sqlexp : TRUE (sql_inject (EVar (["Basis"], "True", In
(EApp (e, query), loc)
end)
+window : (NONE)
+ | OVER LPAREN RPAREN (SOME ())
+
fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
| LBRACE eexp RBRACE (eexp)