I was hoping if someone could give me more insights on how fields are handled in flux lang.
Let’s say I have a measurement “m1” with two fields “f1” and “f2” how should I use flux if we need both the fields in the same graph.
This gives me an error saying “f2” does not exist.
I believe this is because for each time I have two records one with “f1” and other with “f2”.
Also, If I want to show two fields in a graph each from a different measurement should I use a join or union which is a better way.
As far as I understand the data is visualized based on the number of tables returned by the flux query, each table will be a line.
Please correct me if I am wrong.
@Sameer_Raj You’re correct in saying that each table is its own line in the graph. So the goal is to ensure that f1 and f2 are in separate tables, which they should be by default since _field is part of the group key.
In your results, it’s important to understand that f1 and f2 are not column names. They are values in the _field column. To get them to be their own columns, you need to use pivot() right after your filter.
I notice that you do two aggregates later in the query. The 2nd one won’t actually work since aggregate functions drop columns that 1) aren’t in the group key or 2) aren’t the specified aggregate column. So after you sum f1, f2 won’t exist anymore. You can use reduce() to aggregate them and preserve them. Looking at your query as a whole, this should give you what you’re trying to do:
Hi Scott,
Thanks for the explanation , and I appreciate the level of details. As of now I was using joins but I will now replace most of my queries with the reducer which seems more logical and let you know my feed back.