@@ -6,7 +6,7 @@ function as(new_name_model_row::Pair{Symbol, <: SourceCode}; options...)
66end
77
88@code_instead QueryOperators. drop SourceCode Integer
9- @translate :: typeof (QueryOperators. drop) :OFFSET
9+ @translate_default :: typeof (QueryOperators. drop) :OFFSET
1010
1111@code_instead QueryOperators. filter SourceCode Any Expr
1212function translate_dispatch (:: typeof (QueryOperators. filter), iterator, call, call_expression; options... )
@@ -16,25 +16,73 @@ function translate_dispatch(::typeof(QueryOperators.filter), iterator, call, cal
1616 )
1717end
1818
19+ @code_instead QueryOperators. groupby SourceCode Any Expr Any Expr
20+
21+ struct GroupOfRows{Group, Row}
22+ group:: Group
23+ row:: Row
24+ end
25+
26+ function key (group_of_rows:: GroupOfRows )
27+ translate (getfield (group_of_rows, :group ))
28+ end
29+
30+ function getproperty (group_of_rows:: GroupOfRows , column_name:: Symbol )
31+ getproperty (getfield (group_of_rows, :row ), column_name)
32+ end
33+
34+ function length (group_of_rows:: GroupOfRows )
35+ length (first (getfield (group_of_rows, :row )))
36+ end
37+
38+ function model_row_dispatch (:: typeof (QueryOperators. groupby), ungrouped, group_function, group_function_expression, map_selector, map_function_expression; options... )
39+ model = model_row (ungrouped; options... )
40+ GroupOfRows (group_function (model), model)
41+ end
42+
43+ function translate_dispatch (:: typeof (QueryOperators. groupby), ungrouped, group_function, group_function_expression, map_selector, map_function_expression; options... )
44+ # TODO : map_selector
45+ model = model_row (ungrouped; options... )
46+ SQLExpression (Symbol (" GROUP BY" ),
47+ translate (ungrouped; options... ),
48+ translate (group_function (model). code; options... )
49+ )
50+ end
51+
1952@code_instead QueryOperators. join SourceCode SourceCode Any Expr Any Expr Any Expr
2053function translate_dispatch (:: typeof (QueryOperators. join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; options... )
21- model_row_1 = model_row (source1; other = true )
22- model_row_2 = model_row (source2; other = true )
23- SQLExpression (:ON ,
24- SQLExpression (Symbol ( " INNER JOIN " ) ,
25- SQLExpression (:SELECT ,
54+ model_row_1 = model_row (source1; other = true , options ... )
55+ model_row_2 = model_row (source2; other = true , options ... )
56+ SQLExpression (:SELECT ,
57+ SQLExpression (:ON ,
58+ SQLExpression (Symbol ( " INNER JOIN " ) ,
2659 translate (source1; options... ),
27- Generator (
28- pair -> as (pair; options... ),
29- pairs (combine (model_row_1, model_row_2))
30- )...
60+ translate (source2; other = true , options... )
3161 ),
32- translate (source2; other = true , options... )
62+ SQLExpression (:(= ),
63+ translate (key1 (model_row_1). code; options... ),
64+ translate (key2 (model_row_2). code; other = true , options... )
65+ )
3366 ),
34- SQLExpression (:(= ),
35- translate (key1 (model_row_1). code; options... ),
36- translate (key2 (model_row_2). code; other = true , options... )
37- )
67+ Generator (
68+ pair -> as (pair; options... ),
69+ pairs (combine (model_row_1, model_row_2))
70+ )...
71+ )
72+ end
73+
74+ @code_instead QueryOperators. map SourceCode Any Expr
75+ function model_row_dispatch (:: typeof (QueryOperators. map), iterator, call, call_expression; options... )
76+ call (model_row (iterator; options... ))
77+ end
78+
79+ function translate_dispatch (:: typeof (QueryOperators. map), select_table, call, call_expression; options... )
80+ SQLExpression (
81+ Symbol (" SELECT" ), translate (select_table; options... ),
82+ Generator (
83+ pair -> as (pair; options... ),
84+ pairs (call (model_row (select_table; options... )))
85+ )...
3886 )
3987end
4088
@@ -72,23 +120,8 @@ function translate_dispatch(::typeof(QueryOperators.thenby_descending), unordere
72120 )
73121end
74122
75- @code_instead QueryOperators. map SourceCode Any Expr
76- function model_row_dispatch (:: typeof (QueryOperators. map), iterator, call, call_expression; options... )
77- call (model_row (iterator; options... ))
78- end
79-
80- function translate_dispatch (:: typeof (QueryOperators. map), select_table, call, call_expression; options... )
81- SQLExpression (
82- Symbol (" SELECT" ), translate (select_table; options... ),
83- Generator (
84- pair -> as (pair; options... ),
85- pairs (call (model_row (select_table; options... )))
86- )...
87- )
88- end
89-
90123@code_instead QueryOperators. take SourceCode Any
91- @translate :: typeof (QueryOperators. take) :LIMIT
124+ @translate_default :: typeof (QueryOperators. take) :LIMIT
92125
93126@code_instead QueryOperators. unique SourceCode Any Expr
94127function translate_dispatch (:: typeof (QueryOperators. unique), repeated, key_function, key_function_expression; options... )
0 commit comments