TL;DR InfluxDB Tech Tips – Add Temporary Data with Flux

Navigate to:

In this post, we share a way to generate a table with Flux.

Q: I want to perform a task that executes a join() but I don’t always have data for one of the input tables. How can I create an initial or default state for that one input table? A: Generate temporary data with Flux.

Generating temporary data with Flux

  1. Navigate to the Data Explorer tab. Use the query builder to return data that’s in a similar shape to the new table you want to generate. Click the CSV download icon. This will download an Annotated CSV. This approach is recommended because manually creating an Annotated CSV can be frustrating. In this example, I have data about the number of cats and dogs in a shelter. I want to add a table with data about bunnies. temporary data Flux

  2. Open the Annotated CSV and copy the headers as well as the first line.

#group,false,false,true,true,false,false,true,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,shelter,type
,,0,2020-05-01T15:06:27Z,2020-07-09T15:06:27.516Z,2020-05-15T18:50:33.262484Z,3,young,cats,B,calico
  1. Slightly modify the CSV as needed. For example, you can change the values and tags. If you need to add or remove a column make sure to change all three Annotations to reflect the change.  Generate a temporary table with the Flux csv.from() function in InfluxDB 2.0. I will be adding a data point about 2 brown bunnies that came into shelter “B” on 05/15/2020.
import "csv"

csv.from(csv: " #group,false,false,true,true,false,false,true,true,true,true
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,double,string,string,string,string
#default,_result,,,,,,,,,
,result,table,_start,_stop,_time,_value,_field,_measurement,shelter,type
,,0,2020-05-01T15:06:27Z,2020-07-09T15:06:27.516Z,2020-05-15T18:50:33.262484Z,2,young,bunny,B,brown")

Tip: Please make sure that you don’t have a preceding whitespace like so csv.from(csv: "  #group…." as this will confuse the parser. Please read this TL;DR Tech Tip if you want help understanding the Annotated CSV format. 

adding datapoint Flux

Please note: This TL;DR was created in response to community questions. While this isn’t the most elegant solution, please know a better UX version of this feature is in the works. In the meantime, we hope this workaround helps.