diff --git a/REQUIRE b/REQUIRE index 577d82b9..3007b9d7 100644 --- a/REQUIRE +++ b/REQUIRE @@ -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 diff --git a/example/25-ab-syntax.jl b/example/25-ab-syntax.jl index 142134f9..7550b083 100644 --- a/example/25-ab-syntax.jl +++ b/example/25-ab-syntax.jl @@ -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 diff --git a/src/query_translation.jl b/src/query_translation.jl index 4b0b6ed0..14d50802 100644 --- a/src/query_translation.jl +++ b/src/query_translation.jl @@ -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) @@ -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) diff --git a/src/standalone_query_macros.jl b/src/standalone_query_macros.jl index 71cda29d..57034821 100644 --- a/src/standalone_query_macros.jl +++ b/src/standalone_query_macros.jl @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/test/test_dplyr-syntax.jl b/test/test_dplyr-syntax.jl index 4111665d..3f1a21a8 100644 --- a/test/test_dplyr-syntax.jl +++ b/test/test_dplyr-syntax.jl @@ -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