Generating .CSV file with normal headers from InfluxDB2

Hi,

InfluxDB2 is really cool, however i am having issues with the .CSV export. It generates .CSV file in a format where the columns have a unique identifier “0”,“1”… with values and time stamp in different columns.

I am looking more for having my measurements as headers of the CSV file and corresponding values below the respective column headers. I did try building a query but Influx db spits out the same report every time.

import "influxdata/influxdb/schema"
from(bucket: "azfunc-test-influx-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "temperature" or r["_measurement"] == "pressure" or r["_measurement"] == "humidity")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["device_id"] == "14aitbr8ccq")
  |> schema.fieldsAsCols()  

report which is actually generated

image

I am looking to have the headers like temperature, pressure and humidity as headers and values below.

Hello @Rahul_Chandrashekar,
That’s odd, that’s not what I get:

import "influxdata/influxdb/schema"
from(bucket: "cpu")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r._measurement == "cpu")
    |> limit(n: 2)
    |> group() 
    |> schema.fieldsAsCols()  

Returns:

#group,false,false,false,false,false,false,false,false,false,false,false,false,false
#datatype,string,long,dateTime:RFC3339,double,double,double,double,double,double,double,double,double,double
#default,_result,,,,,,,,,,,,
,result,table,_time,usage_iowait,usage_idle,usage_system,usage_nice,usage_user,usage_guest,usage_guest_nice,usage_softirq,usage_irq,usage_steal
,,0,2023-03-09T16:30:20Z,0,89.24999999989923,3.983333333332363,0,21.36068034018222,0,0,0,0,0
,,0,2023-03-09T16:30:40Z,0,85.30734632683179,4.348007163382563,0,22.899999999999636,0,0,0,0,0

What version of InfluxDB are you using?
What are you using to query?
Can you please share a screenshot of the output of the query in table form?

Hi Anai,

I did try your script and pls find the screenshot for your reference.

image

Pls find my updated script.

import "influxdata/influxdb/schema"
from(bucket: "cva-azfunc-test-influx-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |>filter(fn: (r) => r["_measurement"] == "temperature" or r["_measurement"] == "pressure" or r["_measurement"] == "humidity")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["device_id"] == "14aitbr8ccq")
  |> group() 
  |> schema.fieldsAsCols() 

and when i try to use

|> pivot(rowKey: ["_time"], columnKey: ["_measurement"], valueColumn: "_value")

I get a report like this - but it does not fill the rows.

Hello @Rahul_Chandrashekar,
Is there any way you can share the output of

import "influxdata/influxdb/schema"
from(bucket: "cva-azfunc-test-influx-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |>filter(fn: (r) => r["_measurement"] == "temperature" or r["_measurement"] == "pressure" or r["_measurement"] == "humidity")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["device_id"] == "14aitbr8ccq")
  |> filter(fn: (r) => r["device_name"] == "Gentherm_ReadyCare")
  |> limit(n:2) 

Thank you!

Hi Anai,
emailed.

Regds
Rahul.