comparison src/urweb.grm @ 1778:818d4097e2ed

Lighter-weight encoding of window function use
author Adam Chlipala <adam@chlipala.net>
date Sun, 03 Jun 2012 11:29:31 -0400
parents 59b07fdae1ff
children bb942416bf1c
comparison
equal deleted inserted replaced
1777:59b07fdae1ff 1778:818d4097e2ed
307 let 307 let
308 val (pb, ob) = getOpt (window, ((EVar (["Basis"], "sql_no_partition", Infer), dummy), 308 val (pb, ob) = getOpt (window, ((EVar (["Basis"], "sql_no_partition", Infer), dummy),
309 (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy), 309 (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
310 (CWild (KRecord (KType, dummy), dummy), dummy)), 310 (CWild (KRecord (KType, dummy), dummy), dummy)),
311 dummy))) 311 dummy)))
312 val e' = (EVar (["Basis"], "sql_window", Infer), loc) 312 val e' = (EVar (["Basis"], "sql_window_function", Infer), loc)
313 val e' = (EApp (e', e), loc) 313 val e' = (EApp (e', e), loc)
314 val e' = (EApp (e', pb), loc) 314 val e' = (EApp (e', pb), loc)
315 in 315 in
316 (EApp (e', ob), loc) 316 (EApp (e', ob), loc)
317 end 317 end
343 343
344 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING 344 | SELECT | DISTINCT | FROM | AS | CWHERE | GROUP | ORDER | BY | HAVING
345 | UNION | INTERSECT | EXCEPT 345 | UNION | INTERSECT | EXCEPT
346 | LIMIT | OFFSET | ALL 346 | LIMIT | OFFSET | ALL
347 | TRUE | FALSE | CAND | OR | NOT 347 | TRUE | FALSE | CAND | OR | NOT
348 | COUNT | AVG | SUM | MIN | MAX | RANK 348 | COUNT | AVG | SUM | MIN | MAX | RANK | PARTITION | OVER
349 | ASC | DESC | RANDOM 349 | ASC | DESC | RANDOM
350 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE 350 | INSERT | INTO | VALUES | UPDATE | SET | DELETE | NULL | IS | COALESCE | LIKE
351 | CURRENT_TIMESTAMP 351 | CURRENT_TIMESTAMP
352 | NE | LT | LE | GT | GE 352 | NE | LT | LE | GT | GE
353 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES 353 | CCONSTRAINT | UNIQUE | CHECK | PRIMARY | FOREIGN | KEY | ON | NO | ACTION | RESTRICT | CASCADE | REFERENCES
354 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL 354 | JOIN | INNER | CROSS | OUTER | LEFT | RIGHT | FULL
355 | CIF | CTHEN | CELSE 355 | CIF | CTHEN | CELSE
356 | OVER | PARTITION
357 356
358 %nonterm 357 %nonterm
359 file of decl list 358 file of decl list
360 | decls of decl list 359 | decls of decl list
361 | decl of decl list 360 | decl of decl list
1753 loc)], loc) 1752 loc)], loc)
1754 end)) tabs, 1753 end)) tabs,
1755 exps) 1754 exps)
1756 end 1755 end
1757 1756
1757 val exps = map (fn (c, e) => (c, (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc))) exps
1758
1758 val sel = (CRecord sel, loc) 1759 val sel = (CRecord sel, loc)
1759 1760
1760 val grp = case gopt of 1761 val grp = case gopt of
1761 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all", 1762 NONE => (ECApp ((EVar (["Basis"], "sql_subset_all",
1762 Infer), loc), 1763 Infer), loc),
2039 | LPAREN sqlexp RPAREN (sqlexp) 2040 | LPAREN sqlexp RPAREN (sqlexp)
2040 2041
2041 | NULL (sql_inject ((EVar (["Basis"], "None", Infer), 2042 | NULL (sql_inject ((EVar (["Basis"], "None", Infer),
2042 s (NULLleft, NULLright)))) 2043 s (NULLleft, NULLright))))
2043 2044
2044 | COUNT LPAREN STAR RPAREN window (let 2045 | COUNT LPAREN STAR RPAREN window(let
2045 val loc = s (COUNTleft, windowright) 2046 val loc = s (COUNTleft, windowright)
2046 in 2047 in
2047 case window of 2048 case window of
2048 NONE => (EVar (["Basis"], "sql_count", Infer), loc) 2049 NONE => (EVar (["Basis"], "sql_count", Infer), loc)
2049 | SOME _ => 2050 | SOME _ => applyWindow loc (EVar (["Basis"], "sql_window_count", Infer), loc) window
2050 let 2051 end)
2051 val e = (EVar (["Basis"], "sql_window_count", Infer), loc) 2052 | COUNT LPAREN sqlexp RPAREN window(let
2052 in 2053 val loc = s (COUNTleft, RPARENright)
2053 applyWindow loc e window 2054 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
2054 end 2055 in
2055 end) 2056 case window of
2056 | RANK UNIT window (let 2057 NONE =>
2057 val loc = s (RANKleft, windowright) 2058 let
2058 val e = (EVar (["Basis"], "sql_window_rank", Infer), loc) 2059 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc),
2059 in 2060 e), loc)
2060 applyWindow loc e window 2061 in
2061 end) 2062 (EApp (e, sqlexp), loc)
2062 | COUNT LPAREN sqlexp RPAREN window (let 2063 end
2063 val loc = s (COUNTleft, windowright) 2064 | SOME _ =>
2064 2065 let
2065 val e = (EVar (["Basis"], "sql_count_col", Infer), loc) 2066 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
2066 in 2067 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
2067 case window of 2068 e), loc)
2068 NONE => 2069 in
2069 let 2070 applyWindow loc (EApp (e, sqlexp), loc) window
2070 val e = (EApp ((EVar (["Basis"], "sql_aggregate", Infer), loc), 2071 end
2071 e), loc) 2072 end)
2072 in
2073 (EApp (e, sqlexp), loc)
2074 end
2075 | SOME _ =>
2076 let
2077 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
2078 e), loc)
2079 val e = (EApp (e, sqlexp), loc)
2080 in
2081 applyWindow loc e window
2082 end
2083 end)
2084 | sqlagg LPAREN sqlexp RPAREN window (let 2073 | sqlagg LPAREN sqlexp RPAREN window (let
2085 val loc = s (sqlaggleft, windowright) 2074 val loc = s (sqlaggleft, RPARENright)
2086 2075
2087 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc) 2076 val e = (EVar (["Basis"], "sql_" ^ sqlagg, Infer), loc)
2088 in 2077 in
2089 case window of 2078 case window of
2090 NONE => 2079 NONE =>
2091 let 2080 let
2096 end 2085 end
2097 | SOME _ => 2086 | SOME _ =>
2098 let 2087 let
2099 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc), 2088 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
2100 e), loc) 2089 e), loc)
2101 val e = (EApp (e, sqlexp), loc)
2102 in 2090 in
2103 applyWindow loc e window 2091 applyWindow loc (EApp (e, sqlexp), loc) window
2104 end 2092 end
2105 end) 2093 end)
2094 | RANK UNIT window (let
2095 val loc = s (RANKleft, windowright)
2096 in
2097 applyWindow loc (EVar (["Basis"], "sql_rank", Infer), loc) window
2098 end)
2106 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN 2099 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
2107 (let 2100 (let
2108 val loc = s (COALESCEright, sqlexp2right) 2101 val loc = s (COALESCEright, sqlexp2right)
2109 val e = (EVar (["Basis"], "sql_coalesce", Infer), loc) 2102 val e = (EVar (["Basis"], "sql_coalesce", Infer), loc)
2110 val e = (EApp (e, sqlexp1), loc) 2103 val e = (EApp (e, sqlexp1), loc)