I’m a bit confused about why something (admittedly stupid) I was trying to do didn’t work.
Using Query.jl you can write something like:
x = @from i in df begin
@where i.age>50
@select {i.name, i.children}
@collect DataFrame
end
Which goes through a DataFrame df
, finds all rows where df[:age]
is greater than 50 and returns df[:name]
and df[:children]
. I’d like to use these macros with variables for the data frame columns.
My idea was to do something like eval(parse("i.$variable"))
. That way I could create a function taking in variable
, which then gets read into the string, which goes through parse and eval and (in my mind) should just act as i.variable
in the @where
macro.
Doing this with some random type works fine and returns the field variable
of that type, if it exists. But in the @where
macro it says that i
is not defined. I assume this happens because of the scope of the @where
macro, but I clearly don’t understand how macros work well enough to know why it doesn’t work.
Could somebody help me out a bit? For context, my final goal is to make simple way to go through a large-ish amount of data given a couple of selection criteria, so I’m trying to make a function which could take in a text input and parse parts of it as Query.jl query statements.
So effectively I’d like to make a function that takes in a string like "age>50, name children"
and puts i.age>50
into @where
and i.name, i.children
into @select
.