Mercurial > urweb
comparison src/monoize.sml @ 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 |
---|---|
297 (L'.TFfi ("Basis", "string"), loc) | 297 (L'.TFfi ("Basis", "string"), loc) |
298 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) => | 298 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) => |
299 (L'.TRecord [], loc) | 299 (L'.TRecord [], loc) |
300 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) => | 300 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) => |
301 (L'.TRecord [], loc) | 301 (L'.TRecord [], loc) |
302 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_partition"), _), _), _), _), _), _) => | |
303 (L'.TFfi ("Basis", "string"), loc) | |
302 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window"), _), _), _), _), _), _), _), _) => | 304 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_window"), _), _), _), _), _), _), _), _) => |
303 (L'.TFfi ("Basis", "string"), loc) | 305 (L'.TFfi ("Basis", "string"), loc) |
304 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) => | 306 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) => |
305 (L'.TRecord [], loc) | 307 (L'.TRecord [], loc) |
306 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) => | 308 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) => |
2742 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm) | 2744 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm) |
2743 | L.ECApp ((L.EFfi ("Basis", "sql_summable_option"), _), _) => | 2745 | L.ECApp ((L.EFfi ("Basis", "sql_summable_option"), _), _) => |
2744 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc), | 2746 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc), |
2745 (L'.ERecord [], loc)), loc), | 2747 (L'.ERecord [], loc)), loc), |
2746 fm) | 2748 fm) |
2747 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _), _), _) => | 2749 | L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _) => |
2748 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc), | 2750 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), |
2749 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), | 2751 (L'.EPrim (Prim.String "AVG"), loc)), loc), |
2750 (L'.EPrim (Prim.String "AVG"), loc)), loc)), loc), | |
2751 fm) | 2752 fm) |
2752 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _), _), _) => | 2753 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _), _), _) => |
2753 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc), | 2754 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc)), loc), |
2754 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), | 2755 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc), |
2755 (L'.EPrim (Prim.String "SUM"), loc)), loc)), loc), | 2756 (L'.EPrim (Prim.String "SUM"), loc)), loc)), loc), |
2781 fm) | 2782 fm) |
2782 | 2783 |
2783 | L.ECApp ( | 2784 | L.ECApp ( |
2784 (L.ECApp ( | 2785 (L.ECApp ( |
2785 (L.ECApp ( | 2786 (L.ECApp ( |
2787 (L.EFfi ("Basis", "sql_no_partition"), _), | |
2788 _), _), | |
2789 _), _), | |
2790 _) => ((L'.EPrim (Prim.String ""), loc), fm) | |
2791 | L.ECApp ( | |
2792 (L.ECApp ( | |
2793 (L.ECApp ( | |
2794 (L.ECApp ( | |
2795 (L.EFfi ("Basis", "sql_partition"), _), | |
2796 _), _), | |
2797 _), _), | |
2798 _), _), | |
2799 _) => | |
2800 let | |
2801 val s = (L'.TFfi ("Basis", "string"), loc) | |
2802 in | |
2803 ((L'.EAbs ("e", s, s, strcat [(L'.EPrim (Prim.String "PARTITION BY "), loc), (L'.ERel 0, loc)]), loc), | |
2804 fm) | |
2805 end | |
2806 | |
2807 | L.ECApp ( | |
2808 (L.ECApp ( | |
2809 (L.ECApp ( | |
2786 (L.ECApp ( | 2810 (L.ECApp ( |
2787 (L.EFfi ("Basis", "sql_window"), _), | 2811 (L.EFfi ("Basis", "sql_window"), _), |
2788 _), _), | 2812 _), _), |
2789 _), _), | 2813 _), _), |
2790 _), _), | 2814 _), _), |
2791 _) => | 2815 _) => |
2792 let | 2816 let |
2817 val () = if #windowFunctions (Settings.currentDbms ()) then | |
2818 () | |
2819 else | |
2820 ErrorMsg.errorAt loc "The DBMS you've selected doesn't support window functions." | |
2821 | |
2793 val s = (L'.TFfi ("Basis", "string"), loc) | 2822 val s = (L'.TFfi ("Basis", "string"), loc) |
2794 fun sc s = (L'.EPrim (Prim.String s), loc) | 2823 fun sc s = (L'.EPrim (Prim.String s), loc) |
2795 | 2824 |
2796 val main = strcat [(L'.ERel 0, loc), | 2825 val main = strcat [(L'.ERel 2, loc), |
2797 sc " OVER ()"] | 2826 sc " OVER (", |
2798 in | 2827 (L'.ERel 1, loc), |
2799 ((L'.EAbs ("w", s, s, main), loc), | 2828 (L'.ECase ((L'.ERel 0, loc), |
2829 [((L'.PPrim (Prim.String ""), loc), | |
2830 sc ""), | |
2831 ((L'.PWild, loc), | |
2832 strcat [sc " ORDER BY ", | |
2833 (L'.ERel 0, loc)])], | |
2834 {disc = s, | |
2835 result = s}), loc), | |
2836 sc ")"] | |
2837 in | |
2838 ((L'.EAbs ("w", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc), | |
2839 (L'.EAbs ("p", s, (L'.TFun (s, s), loc), | |
2840 (L'.EAbs ("o", s, s, | |
2841 main), loc)), loc)), loc), | |
2800 fm) | 2842 fm) |
2801 end | 2843 end |
2802 | 2844 |
2803 | L.ECApp ( | 2845 | L.ECApp ( |
2804 (L.ECApp ( | 2846 (L.ECApp ( |