Skip to content

Commit

Permalink
Merge pull request #195 from queryverse/proper-groupcolumn-syntax
Browse files Browse the repository at this point in the history
Replace .. with . for group column extraction syntax
  • Loading branch information
davidanthoff authored Aug 29, 2018
2 parents ca28908 + a5a9b60 commit f60b257
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 55 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Documenter 0.19.3
IterableTables 0.8.2
DataValues 0.4.4
MacroTools 0.4.4
QueryOperators 0.3.0
QueryOperators 0.4.0
2 changes: 1 addition & 1 deletion example/25-ab-syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ df = DataFrame(name=repeat(["John", "Sally", "Kirk"],inner=[1],outer=[2]),

x = @from i in df begin
@group i by i.state into g
@select {group=key(g),mage=mean(g..age), oldest=maximum(g..age), youngest=minimum(g..age)}
@select {group=key(g),mage=mean(g.age), oldest=maximum(g.age), youngest=minimum(g.age)}
@collect DataFrame
end

Expand Down
10 changes: 0 additions & 10 deletions src/query_translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ function helper_replace_anon_func_syntax(ex)
end
end

function helper_replace_field_extraction_syntax(ex)
postwalk(ex) do x
iscall(x, :(..)) ? :(map(i->i.$(x.args[3]), $(x.args[2]))) : x
end
end

function query_expression_translation_phase_A(qe)
i = 1
while i<=length(qe)
Expand All @@ -83,10 +77,6 @@ function query_expression_translation_phase_A(qe)
end
i+=1
end

for i in eachindex(qe)
qe[i] = helper_replace_field_extraction_syntax(qe[i])
end
end

function query_expression_translation_phase_B(qe)
Expand Down
63 changes: 21 additions & 42 deletions src/standalone_query_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ macro groupby(source, elementSelector, resultSelector)
q_resultSelector = Expr(:quote, resultSelector_as_anonym_func)

return :(QueryOperators.groupby(QueryOperators.query($(esc(source))), $(esc(elementSelector_as_anonym_func)), $(esc(q_elementSelector)), $(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro groupby(elementSelector, resultSelector)
Expand All @@ -31,8 +30,7 @@ macro groupby(elementSelector, resultSelector)
q_resultSelector = Expr(:quote, resultSelector_as_anonym_func)

return :( i -> QueryOperators.groupby(QueryOperators.query(i), $(esc(elementSelector_as_anonym_func)), $(esc(q_elementSelector)), $(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro groupby(elementSelector)
Expand All @@ -43,8 +41,7 @@ macro groupby(elementSelector)
q_resultSelector = Expr(:quote, resultSelector_as_anonym_func)

return :( i -> QueryOperators.groupby(QueryOperators.query(i), $(esc(elementSelector_as_anonym_func)), $(esc(q_elementSelector)), $(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro groupjoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector)
Expand All @@ -61,8 +58,7 @@ macro groupjoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector
$(esc(outerKeySelector_as_anonym_func)), $(esc(q_outerKeySelector)),
$(esc(innerKeySelector_as_anonym_func)), $(esc(q_innerKeySelector)),
$(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)),)) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro groupjoin(inner, outerKeySelector, innerKeySelector, resultSelector)
Expand All @@ -79,8 +75,7 @@ macro groupjoin(inner, outerKeySelector, innerKeySelector, resultSelector)
$(esc(outerKeySelector_as_anonym_func)), $(esc(q_outerKeySelector)),
$(esc(innerKeySelector_as_anonym_func)), $(esc(q_innerKeySelector)),
$(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)),)) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro join(outer, inner, outerKeySelector, innerKeySelector, resultSelector)
Expand All @@ -97,8 +92,7 @@ macro join(outer, inner, outerKeySelector, innerKeySelector, resultSelector)
$(esc(outerKeySelector_as_anonym_func)), $(esc(q_outerKeySelector)),
$(esc(innerKeySelector_as_anonym_func)), $(esc(q_innerKeySelector)),
$(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)),)) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro join(inner, outerKeySelector, innerKeySelector, resultSelector)
Expand All @@ -115,88 +109,77 @@ macro join(inner, outerKeySelector, innerKeySelector, resultSelector)
$(esc(outerKeySelector_as_anonym_func)), $(esc(q_outerKeySelector)),
$(esc(innerKeySelector_as_anonym_func)), $(esc(q_innerKeySelector)),
$(esc(resultSelector_as_anonym_func)), $(esc(q_resultSelector)),)) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro orderby(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.orderby(QueryOperators.query($(esc(source))), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro orderby(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, helper_replace_anon_func_syntax(f_as_anonym_func))
return :( i -> QueryOperators.orderby(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro orderby_descending(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.orderby_descending(QueryOperators.query($(esc(source))), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro orderby_descending(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, helper_replace_anon_func_syntax(f_as_anonym_func))
return :( i -> QueryOperators.orderby_descending(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro thenby(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.thenby($(esc(source)), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro thenby(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, helper_replace_anon_func_syntax(f_as_anonym_func))
return :( i -> QueryOperators.thenby(i, $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro thenby_descending(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.thenby_descending($(esc(source)), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro thenby_descending(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, helper_replace_anon_func_syntax(f_as_anonym_func))
return :( i -> QueryOperators.thenby_descending(i, $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro map(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.map(QueryOperators.query($(esc(source))), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro map(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :( i-> QueryOperators.map(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q))) ) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro mapmany(source, collectionSelector,resultSelector)
Expand All @@ -209,8 +192,7 @@ macro mapmany(source, collectionSelector,resultSelector)
return :(QueryOperators.mapmany(QueryOperators.query($(esc(source))),
$(esc(collectionSelector_as_anonym_func)), $(esc(collectionSelector_q)),
$(esc(resultSelector_as_anonym_func)), $(esc(resultSelector_q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro mapmany(collectionSelector,resultSelector)
Expand All @@ -223,24 +205,21 @@ macro mapmany(collectionSelector,resultSelector)
return :( i-> QueryOperators.mapmany(QueryOperators.query(i),
$(esc(collectionSelector_as_anonym_func)), $(esc(collectionSelector_q)),
$(esc(resultSelector_as_anonym_func)), $(esc(resultSelector_q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro filter(source, f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :(QueryOperators.filter(QueryOperators.query($(esc(source))), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro filter(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, helper_replace_anon_func_syntax(f_as_anonym_func))
return :( i -> QueryOperators.filter(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q)))) |>
helper_namedtuples_replacement |>
helper_replace_field_extraction_syntax
helper_namedtuples_replacement
end

macro take(source, n)
Expand Down
2 changes: 1 addition & 1 deletion test/test_dplyr-syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using Test

x = @from i in df begin
@group i by i.state into g
@select {group=key(g),mage=mean(g..age), oldest=maximum(g..age), youngest=minimum(g..age)}
@select {group=key(g),mage=mean(g.age), oldest=maximum(g.age), youngest=minimum(g.age)}
@collect DataFrame
end

Expand Down

0 comments on commit f60b257

Please sign in to comment.