# Query.jl: Automatize multiple @select at once

**URL:** <https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948>\
**Category:** Data\
**Tags:** metaprogramming, query\
**Created:** [July 19, 2017, 3:16pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948 "2017-07-19T15:16:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaslusimoes](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kaslusimoes](https://discourse.julialang.org/u/kaslusimoes)\
**Post date:** [July 19, 2017, 3:16pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/1 "2017-07-19T15:16:45Z")

</div>

Suppose I have a DataFrame with a great number of fields and the number of these columns I want to select using Query.jl. is also large. Is there any way to automatize this?

For example, I have a vector v naming the fields that are interesting to me:

```julia
v = [name, sex, age, ..., grade20]

```

What is the best way to select all those fields inside a query?

I tried some metaprogramming but it didn’t work out:

```julia
str = ""
for i in v
     str = str * "i.$i, "
end
str = str[1:length(str)-2]
parse(str)

ERROR: ParseError("extra token \"0.1\" after end of expression")

```

I would like that something like the following worked:

```julia
newdf = @from i in df begin
    @select {i.v}
    @collect DataFrame
end

```

Is there any easy way that I am not thinking?  
Thank you

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [July 19, 2017, 9:44pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/2 "2017-07-19T21:44:02Z")

</div>

There is no way to do this right now.

I have this scenario firmly on my radar, but for some pretty fundamental technical reasons I’ll only be able to implement a solution for this once we have named tuples in base ([https://github.com/JuliaLang/julia/pull/22194](https://github.com/JuliaLang/julia/pull/22194)). Which, unfortunately, means that the earliest we might have a solution for this scenario will be in the julia 0.7/1.0 timeframe…

---

<div class="post-metadata">

**Author:** ![kaslusimoes](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kaslusimoes](https://discourse.julialang.org/u/kaslusimoes)\
**Post date:** [July 20, 2017, 3:07pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/3 "2017-07-20T15:07:31Z")

</div>

I see =/  
Well, thanks anyway for the reply! I found a way around in my particular situation without using Query:

```julia
df; # huge DataFrame
v = ["sex", "age", ...]; # smaller vector of selected relevant features
relevant_df = df[:, [parse(i) for i in v]]; # 'constrained' DataFrame

```

Then I use Query if needed. It’s not optimal because I have to do it in two steps, but in my case at least this is functional.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [July 20, 2017, 5:19pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/4 "2017-07-20T17:19:58Z")

</div>

Should be totally possible with [LazyQuery](https://bramtayl.github.io/LazyQuery.jl/stable/)

```julia
using LazyQuery
@new_environment; @use_in_environment LazyQuery

@chain @evaluate begin
    columns = [:a, :b, :c]
    DataFrame(a = 1, b = 2, c = 3, d = 4)
    query(it)
    make_from(it, columns...)
    collect(it, DataFrame)
end

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [July 20, 2017, 5:35pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/5 "2017-07-20T17:35:10Z")

</div>

@bramtayl Just out of curiosity, how is a row represented in this? With a NamedTuple?

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [July 20, 2017, 5:37pm UTC](https://discourse.julialang.org/t/query-jl-automatize-multiple-select-at-once/4948/6 "2017-07-20T17:37:47Z")

</div>

Yup. The query in the above is just an exported version of `Query.query`
