comparison src/urweb.grm @ 1777:59b07fdae1ff

Partitioning and ordering for window functions
author Adam Chlipala <adam@chlipala.net>
date Sat, 02 Jun 2012 16:47:09 -0400
parents 8f28c3295148
children 818d4097e2ed
comparison
equal deleted inserted replaced
1776:8f28c3295148 1777:59b07fdae1ff
301 [] => (EVar (["Basis"], "noStyle", Infer), pos) 301 [] => (EVar (["Basis"], "noStyle", Infer), pos)
302 | props => 302 | props =>
303 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "oneProperty", Infer), pos), e), pos), parseProperty s pos), pos)) 303 foldl (fn (s, e) => (EApp ((EApp ((EVar (["Basis"], "oneProperty", Infer), pos), e), pos), parseProperty s pos), pos))
304 (EVar (["Basis"], "noStyle", Infer), pos) props 304 (EVar (["Basis"], "noStyle", Infer), pos) props
305 305
306 fun applyWindow loc e window =
307 let
308 val (pb, ob) = getOpt (window, ((EVar (["Basis"], "sql_no_partition", Infer), dummy),
309 (ECApp ((EVar (["Basis"], "sql_order_by_Nil", Infer), dummy),
310 (CWild (KRecord (KType, dummy), dummy), dummy)),
311 dummy)))
312 val e' = (EVar (["Basis"], "sql_window", Infer), loc)
313 val e' = (EApp (e', e), loc)
314 val e' = (EApp (e', pb), loc)
315 in
316 (EApp (e', ob), loc)
317 end
318
306 %% 319 %%
307 %header (functor UrwebLrValsFn(structure Token : TOKEN)) 320 %header (functor UrwebLrValsFn(structure Token : TOKEN))
308 321
309 %term 322 %term
310 EOF 323 EOF
454 | fident of con 467 | fident of con
455 | seli of select_item 468 | seli of select_item
456 | selis of select_item list 469 | selis of select_item list
457 | select of select 470 | select of select
458 | sqlexp of exp 471 | sqlexp of exp
459 | window of unit option 472 | window of (exp * exp) option
473 | pbopt of exp
460 | wopt of exp 474 | wopt of exp
461 | groupi of group_item 475 | groupi of group_item
462 | groupis of group_item list 476 | groupis of group_item list
463 | gopt of group_item list option 477 | gopt of group_item list option
464 | hopt of exp 478 | hopt of exp
2034 NONE => (EVar (["Basis"], "sql_count", Infer), loc) 2048 NONE => (EVar (["Basis"], "sql_count", Infer), loc)
2035 | SOME _ => 2049 | SOME _ =>
2036 let 2050 let
2037 val e = (EVar (["Basis"], "sql_window_count", Infer), loc) 2051 val e = (EVar (["Basis"], "sql_window_count", Infer), loc)
2038 in 2052 in
2039 (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc) 2053 applyWindow loc e window
2040 end 2054 end
2041 end) 2055 end)
2042 | RANK UNIT window (let 2056 | RANK UNIT window (let
2043 val loc = s (RANKleft, windowright) 2057 val loc = s (RANKleft, windowright)
2044 val e = (EVar (["Basis"], "sql_window_rank", Infer), loc) 2058 val e = (EVar (["Basis"], "sql_window_rank", Infer), loc)
2045 in 2059 in
2046 (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc) 2060 applyWindow loc e window
2047 end) 2061 end)
2048 | COUNT LPAREN sqlexp RPAREN window (let 2062 | COUNT LPAREN sqlexp RPAREN window (let
2049 val loc = s (COUNTleft, windowright) 2063 val loc = s (COUNTleft, windowright)
2050 2064
2051 val e = (EVar (["Basis"], "sql_count_col", Infer), loc) 2065 val e = (EVar (["Basis"], "sql_count_col", Infer), loc)
2062 let 2076 let
2063 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc), 2077 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
2064 e), loc) 2078 e), loc)
2065 val e = (EApp (e, sqlexp), loc) 2079 val e = (EApp (e, sqlexp), loc)
2066 in 2080 in
2067 (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc) 2081 applyWindow loc e window
2068 end 2082 end
2069 end) 2083 end)
2070 | sqlagg LPAREN sqlexp RPAREN window (let 2084 | sqlagg LPAREN sqlexp RPAREN window (let
2071 val loc = s (sqlaggleft, windowright) 2085 val loc = s (sqlaggleft, windowright)
2072 2086
2084 let 2098 let
2085 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc), 2099 val e = (EApp ((EVar (["Basis"], "sql_window_aggregate", Infer), loc),
2086 e), loc) 2100 e), loc)
2087 val e = (EApp (e, sqlexp), loc) 2101 val e = (EApp (e, sqlexp), loc)
2088 in 2102 in
2089 (EApp ((EVar (["Basis"], "sql_window", Infer), loc), e), loc) 2103 applyWindow loc e window
2090 end 2104 end
2091 end) 2105 end)
2092 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN 2106 | COALESCE LPAREN sqlexp COMMA sqlexp RPAREN
2093 (let 2107 (let
2094 val loc = s (COALESCEright, sqlexp2right) 2108 val loc = s (COALESCEright, sqlexp2right)
2112 in 2126 in
2113 (EApp (e, query), loc) 2127 (EApp (e, query), loc)
2114 end) 2128 end)
2115 2129
2116 window : (NONE) 2130 window : (NONE)
2117 | OVER LPAREN RPAREN (SOME ()) 2131 | OVER LPAREN pbopt obopt RPAREN (SOME (pbopt, obopt))
2132
2133 pbopt : ((EVar (["Basis"], "sql_no_partition", Infer), dummy))
2134 | PARTITION BY sqlexp (let
2135 val loc = s (PARTITIONleft, sqlexpright)
2136
2137 val e = (EVar (["Basis"], "sql_partition", Infer), loc)
2138 in
2139 (EApp (e, sqlexp), loc)
2140 end)
2118 2141
2119 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright)) 2142 fname : SYMBOL (EVar (["Basis"], "sql_" ^ SYMBOL, Infer), s (SYMBOLleft, SYMBOLright))
2120 | LBRACE eexp RBRACE (eexp) 2143 | LBRACE eexp RBRACE (eexp)
2121 2144
2122 wopt : (sql_inject (EVar (["Basis"], "True", Infer), 2145 wopt : (sql_inject (EVar (["Basis"], "True", Infer),