Convert SQL-like request to InfluxDB

Hello everyone

I need to draw two lines on the same diagram, each represents a r[“_field”]. First - “bytes_rx”, second - “wan_inbound_bw”. When I just use r[“_field”] == “bytes_rx” or “wan_inbound_bw”, it only shows one of the two fields. I think this happens because each of them needs different filters, and filters which is ok for one field, returns empy values for another. So I came up with this line, which works:

|> filter(fn: (r) => ((r[“_field”] == “bytes_rx” or r[“_field”] == “bytes_tx”) and r[“interface_name”] == “wan0” and r[“traffic_type”] == “all_traffic” and r[“hostname”] == “name1”) or ( r[“_field”] == “wan_inbound_bw” and r[“_measurement”] == “deployment_info” and r[“hostname”] == “name1” and r[“interface_name”] == “wan0”))

But I want to make it more like common InfluxDB code with multiple “|> filter(fn: (r) =>” lines. Is it possible? How to write it properly?

Hello @Dmitry,
Welcome!
Have you tried using multiple yield() functions? I would grab your data at a high level:

data = from(bucket: "ex") 
|> range() 
|> filter for top level filter maybe a measurement 

first_line = data |> filter for maybe a tag that both fields share
|> filter for one field and a second
|> yield(name: "first_line") 


second_line = data |> filter for maybe a tag that both fields share
|> filter for one field and a second
|> yield(name: "second_line") 

The above is the general structure. I hope that helps!

Hello Anaisdg

Thanks, I will give it a try