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

Query with math returns field with no name #5730

Closed
jwilder opened this issue Feb 17, 2016 · 6 comments
Closed

Query with math returns field with no name #5730

jwilder opened this issue Feb 17, 2016 · 6 comments
Assignees
Milestone

Comments

@jwilder
Copy link
Contributor

jwilder commented Feb 17, 2016

Using math on a field returns a field with an empty name. If this used used in a continuous query or select into, it the points can't be inserted and causes some of the issues seen in #5697.

To repro:

> select value from cpu
name: cpu
---------
time            value
1455686412499134533 1
1455686413602752226 2
1455686415066866003 3
> select value * 10 from cpu
name: cpu
---------
time
1455686412499134533 10
1455686413602752226 20
1455686415066866003 30

Notice the second example is missing a value column header.

Selecting multiple columns doesn't fix it.

> select value * 10, value * 2 from cpu
name: cpu
---------
time
1455686412499134533 10  2
1455686413602752226 20  4
1455686415066866003 30  6

Using an as alias does work though:

> select value * 10 as scaled from cpu
name: cpu
---------
time            scaled
1455686412499134533 10
1455686413602752226 20
1455686415066866003 30
@jwilder jwilder added this to the 0.11.0 milestone Feb 17, 2016
@jwilder
Copy link
Contributor Author

jwilder commented Feb 17, 2016

@jsternberg

@jsternberg jsternberg self-assigned this Feb 17, 2016
@jsternberg
Copy link
Contributor

I found where the error is coming from. What should the column name be where there are multiple fields in the binary expression?

@jwilder
Copy link
Contributor Author

jwilder commented Feb 17, 2016

For something like?

select user / total from cpu

Maybe concatenate the fields w/ _? So that query would return user_total.

@jsternberg
Copy link
Contributor

Sure! Should we remove duplicates? If we have SELECT (user + total) / total FROM cpu should it be user_total_total, total_user, or maybe user_total?

@jwilder
Copy link
Contributor Author

jwilder commented Feb 18, 2016

I would probably go with user_total_total or user_total since they are in the order that they were defined in the query. No strong opinion though.

@jsternberg
Copy link
Contributor

I'll go with user_total_total for now since the implementation is much easier.

jsternberg added a commit that referenced this issue Feb 18, 2016
The name of the column will be every measurement located inside of the
math expression in the order they are encountered in within the
expression.

Fixes #5730.
jsternberg added a commit that referenced this issue Feb 18, 2016
The name of the column will be every measurement located inside of the
math expression in the order they are encountered in within the
expression.

Also handle `*influxql.ParenExpr` in the function
`(*influxql.Field).Name()`

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

No branches or pull requests

2 participants