Hi, I am performing some operations on my data stream in Flux and I want to add new records in the middle of a table or optionally to a new table if a certain condition is met.
Example data:
_time,status
2023-05-28T00:00:29Z,online
2023-05-28T00:03:29Z,offline
2023-05-28T00:08:29Z,online
So let’s say that when “status” is “offline”, I would like to add a row with a timestamp a minute later (in this case 2023-05-28T00:04:29Z) and a “newColumn” column with the value “machine_offline” to this table or to some temporary table where I will store only these added rows and return them as the result of the query.
I thought map() could do this, but this function only allows to return one row, so I can’t return, for example, the union of the base row and the created.
Is there a way to somehow iterate over the table creating new row each time when this certain condition is met?
1 Like
I was looking for something very similar! (I’m calculating the individual time periods when the value was above a certain threshold, and I’m using a mixture of filter, aggregateWindow, stateDuration and elapsed. The only issue is when the last data point of the period is still above the threshold - in order to handle that situation the easiest thing to do would be to add a row at the end which is below the threshold.
If you’ve been able to find the solution to this, it’d be great if you updated it here! 
Thanks,
Sridhar
hello @sridhar_rajagopal,
You can add a row to your table with array.from() and union.
Thank you! array.from and union worked, but I had to be careful to match the group by of the original table for the generated one from array.from . I also had to sort by _time , and everything worked in the end!
Thank you! 
1 Like
@sridhar_rajagopal of course! yah the grouping and such is tricky. I’m glad you figured it out though!