# Issues with multiple @let statements in Query.jl

**URL:** <https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494>\
**Category:** Data\
**Tags:** question\
**Created:** [June 27, 2017, 3:18pm UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494 "2017-06-27T15:18:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Amos](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@Matt\_Amos](https://discourse.julialang.org/u/Matt_Amos)\
**Post date:** [June 27, 2017, 3:18pm UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/1 "2017-06-27T15:18:01Z")

</div>

Whenever I try to use more than two @let statements in my query I get an error (Julia version 0.6.0, Query.jl 0.6.0).

**DataFrame sink:**

```julia
type TypeofBottom has no field parameters

```

**Array sink:**

```julia
TypeError: getfield: expected Symbol, got Expr

```

**Code that generates error:**

```julia
using DataFrames, Query

df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,2,2])
x = @from i in df begin
    @let count = length(i.name)
    @let kids_per_year = i.children / i.age
    @let isjohn = i.name == "John" ? 1 : 0
    @where count > 4
    @select {i.name, Count=count, KPY=kids_per_year}
    @collect DataFrame
end

```

Commenting out the third @let avoids the issue…any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [June 28, 2017, 8:30am UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/2 "2017-06-28T08:30:17Z")

</div>

This appears to be a bug in Query.jl. AFAICT, the `find_names_to_put_in_scope` expansion of `transparentidentifier` seems to be fairly hairy, but has never been tested with that many variables, and does not normalize them correctly to `a.b` expressions if it recurses. There’s an insufficient amount of comments and whitespace in that code base for me to dig further just now, though.

I recommend opening an issue on Query.jl with your repro bug report. I think it should be enough for David to go on to fix the issue.

---

<div class="post-metadata">

**Author:** ![Matt\_Amos](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@Matt\_Amos](https://discourse.julialang.org/u/Matt_Amos)\
**Post date:** [June 28, 2017, 12:14pm UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/3 "2017-06-28T12:14:56Z")

</div>

Thanks for looking into this, I just posted the issue: [#133](https://github.com/davidanthoff/Query.jl/issues/133)

---

<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:** [June 28, 2017, 7:08pm UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/4 "2017-06-28T19:08:40Z")

</div>

Thanks, I’ll try to take a look soon, but it might be a couple of days, this week is a bit hectic with other stuff.

---

<div class="post-metadata">

**Author:** ![mdmilgrom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mdmilgrom/32/1886_2.png) [@mdmilgrom](https://discourse.julialang.org/u/mdmilgrom)\
**Post date:** [September 27, 2017, 3:34pm UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/5 "2017-09-27T15:34:52Z")

</div>

I get the same error with:

```julia
data = @from u in userdata begin
    @join s in screens on u.Screen_Id equals s.screen_id
    @group u by u.Date into a
    @select {a.screen_name, Count=length(a)}
    @collect DataFrame
end

```

“userdata” and “screens” are both `CSV.source`s with weakrefstrings set to false.

---

<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:** [September 29, 2017, 5:38am UTC](https://discourse.julialang.org/t/issues-with-multiple-let-statements-in-query-jl/4494/6 "2017-09-29T05:38:19Z")

</div>

I think the main issue here is that `a.screen_name` is not valid in this query. The `@group` clause will create a stream of `Grouping`s, i.e. each `a` will be an instance of `Grouping`. `Grouping` won’t have a field `a`, though. It will have one field `key` that will hold the value of `u.Date`, and then it is like a vector, where each element is an instance `u`.

Could you maybe post the structure of the input tables? I.e. what columns they have? That would make it easier to understand what you are trying to do. I’ll be offline until Tue, though, so will take a while to respond.
