is there a way to find out if a from() returned an empty set?
I am working on a larger script with several from() statements returning several tables
x = from()
|> range(…)
|> filter(fn: (r ) => r._measurement == “x” )
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)
I want to join all the different tables at the end with join(), but it could happen that some of the tables are empty. In this case I want to ignore the empty tables in the join() operation and just join the others.
Unfortunately a join will drop all my results in case any of x,y,z returned an empty set.
I want to include some conditional logic like
united_tables = if (exists x) then join(x,y) else y
I have no idea how to implement the “exists x” part. I have tried using the count() function but it will fail, if the original x returned no results. Any way to check if a table is not empty?
But if you found the way to check this I would really very much use this function as well as many times filter does not provide data but following routines expect the data.
I am not completely sure if this is exactly the same usecase (if I understood your post correctly), as I do not want to return 0 but check for existance within the script. There seems to be a command “exists” supported for values but seems not to be working for streams/ tables:
@Aga-Schwarz there is no working solution yet for checking if streams / tables are empty.
I would utilize such a function a lot as well also for my use cases. Many times I am getting just an error in Grafana when no streams are coming from Influxdb and I would like to be in control when there is no tables, present error code for instance.
I was checking around however did not find the answer yet when or even if such a feature will be available
Old thread, but in case someone else lands here looking for answers, an easy way to check for dropped tables (which seems to be more accurate than empty tables given the original example) is: