Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

at-querify interprets variables as fields/tags #7

Open
MarcMush opened this issue Aug 14, 2020 · 2 comments
Open

at-querify interprets variables as fields/tags #7

MarcMush opened this issue Aug 14, 2020 · 2 comments

Comments

@MarcMush
Copy link
Contributor

using InfluxDB 

server = InfluxServer("http://localhost:8086") # empty
db = "data"

create_database(server, db)

write(server, db, [
    Measurement("measure",
        Dict("a" => "b"),
        Dict("id" => "b"),
        time()),
    Measurement("measure",
        Dict("a" => "c"),
        Dict("id" => "d"),
        time()),
])

a = "d"
q1 = query(server, db, SELECT(measurements=["measure"], condition=@querify(:id == a)))
q2 = query(server, db, SELECT(measurements=["measure"], condition=InfluxDB.querify(:(:id == $a))))

I would expect the first query to work like the second one
I might try to fix it but macros are a pain so I'll stick with the second option for now

q1[1] = 1×3 DataFrame
│ Row │ time                         │ a      │ id     │
│     │ String                       │ String │ String │
├─────┼──────────────────────────────┼────────┼────────┤
│ 1   │ 2020-08-14T08:49:58.5606848Z │ b      │ b      │
q2[1] = 1×3 DataFrame
│ Row │ time                           │ a      │ id     │
│     │ String                         │ String │ String │
├─────┼────────────────────────────────┼────────┼────────┤
│ 1   │ 2020-08-14T08:49:58.560722944Z │ c      │ d      │
@staticfloat
Copy link
Owner

The @querify macro is.... not built very well. The issue is that it is piecemeal converting Expr's to strings, and it is doing that directly, at compile-time, when what it should be doing is converting Exprs to other Expr's that result in Strings, so that the caller stitches all the Strings together. Without that fundamental change, the macro doesn't have access to the value of the variable you're trying to pass in at compile-time. Whoops.

Anyone who wants to try and rewrite this has my blessing. Even better, if there's a standard query parsing package, that would be even better!

@MarcMush
Copy link
Contributor Author

MarcMush commented Jan 7, 2021

I found it easier to directly write condition as a string, which can be interpolated without problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants