# Replacement for get() in Query

**URL:** <https://discourse.julialang.org/t/replacement-for-get-in-query/17098>\
**Category:** General Usage\
**Created:** [November 2, 2018, 7:48pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098 "2018-11-02T19:48:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [November 2, 2018, 7:48pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/1 "2018-11-02T19:48:35Z")

</div>

@davidanthoff The previous version of `Query` had `get` which was used to unwrap the value within the `DataValue`. Not sure what is the new workflow, but this query no longer works as `occursin` needs the actual string value.

```julia
@from b in df begin
        @where lowercase(b.City) == "san francisco" && b.State == "CA" && 
        occursin(r"\((.*), (.*)\)", b.Business_Location) 
    @select { b.DBA_Name, b.Source_Zipcode, b.NAICS_Code, b.NAICS_Code_Description, b.Business_Location }
    @collect DataFrame
end

```

Using `get(b.Business_Location)` throws:

```julia
ERROR: DataValues.DataValueException()
Stacktrace:
 [1] get at /Users/adrian/.julia/packages/DataValues/SNSrX/src/scalar/core.jl:75 [inlined]

```

Thanks!

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [November 2, 2018, 8:03pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/2 "2018-11-02T20:03:57Z")

</div>

Also, without `get`, things like `ismissing(b.Street_Address)` also fail as it looks like the `ismissing` method is applied to the `DataValue`.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [November 2, 2018, 8:16pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/3 "2018-11-02T20:16:01Z")

</div>

All right, turns out that I needed to explicitly add and use `DataValues`?

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [November 2, 2018, 8:34pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/4 "2018-11-02T20:34:49Z")

</div>

I came up with a working version - so now I think the problem was that I was trying to `get` a missing value. So missing values should be filtered out using `DataValues.isna`

```julia
using DataValues
@from b in df begin
        @where lowercase(b.City) == "san francisco" && b.State == "CA" && 
            ! isna(b.Business_Location) && 
            occursin(r"\((.*), (.*)\)", get(b.Business_Location)) 
    @select { b.DBA_Name, b.Source_Zipcode, b.NAICS_Code, b.NAICS_Code_Description, b.Business_Location }
    @collect 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:** [November 12, 2018, 2:05am UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/5 "2018-11-12T02:05:27Z")

</div>

I believe `get` works still in the same way it always did? If gets the value if there is one, otherwise it throws an error. You can alternatively also use the `[]` syntax to get the value: `b.Business_Location[]` should also work.

And yes, `isna` is the way to test for missing values.

We should probably just add a lifted version of `occursin` to [DataValues.jl](https://github.com/queryverse/DataValues.jl) so that one can just use it without all of this extra effort. I put it onto the [todo](https://github.com/queryverse/DataValues.jl/issues/50).

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 12, 2018, 7:09am UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/6 "2018-11-12T07:09:41Z")

</div>

IMHO it is better to return `missing` and not throw exception if value is missing.

And `occursin` also have to return missing (`occursin(a, b::Missing) = missing`) if we want to have better implemented this: _“Julia provides support for representing missing values in the statistical sense”_ (source: [missing.md](https://github.com/JuliaLang/julia/blob/c37f4aa19a67136015bb03e9bcc78da0cc0b52e7/doc/src/manual/missing.md))

---

<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:** [November 12, 2018, 7:05pm UTC](https://discourse.julialang.org/t/replacement-for-get-in-query/17098/7 "2018-11-12T19:05:21Z")

</div>

[Queryverse.jl](https://github.com/queryverse/Queryverse.jl) doesn’t use the `Missing` construction from base for missing values support. There are a whole bunch of requirements that [Query.jl](https://github.com/queryverse/Query.jl) and friends have for a missing value story that are not met with the current `Missing` implementation in base, so we are using [DataValues.jl](https://github.com/queryverse/DataValues.jl) instead.
