Documentation

csv.from() function

Flux 0.14.0+

The csv.from() function retrieves data from a comma-separated value (CSV) data source. It returns a stream of tables. Each unique series is contained within its own table. Each record in the table represents a single point in the series.

import "csv"

csv.from(
  csv: csvData,
  mode: "annotations"
)

// OR

csv.from(
  file: "/path/to/data-file.csv",
  mode: "annotations"
)

Parameters

csv

CSV data. Supports annotated CSV or raw CSV. Use mode to specify the parsing mode.

Annotated CSV data must include all annotation rows.

file

The file path of the CSV file to query. The path can be absolute or relative. If relative, it is relative to the working directory of the fluxd process. The CSV file must exist in the same file system running the fluxd process.

InfluxDB OSS and InfluxDB Cloud user interfaces do not support the file parameter. Neither allow access to the underlying filesystem. However, the Flux REPL does support the file parameter.

mode

CSV parsing mode. Default is annotations.

Available modes
  • annotations: Use CSV annotations to determine column data types.
  • raw: Parse all columns as strings and use the first row as the header row and all subsequent rows as data.

Examples

Query annotated CSV data from a file
import "csv"

csv.from(file: "/path/to/data-file.csv")
Query raw CSV data from a file
import "csv"
csv.from(
  file: "/path/to/data-file.csv",
  mode: "raw"
)
Query an annotated CSV string
import "csv"

csvData = "
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double
#group,false,false,false,false,false,false,false,false
#default,,,,,,,,
,result,table,_start,_stop,_time,region,host,_value
,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
"

csv.from(csv: csvData)
Query a raw CSV string
import "csv"
csvData = "
_start,_stop,_time,region,host,_value
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
"
csv.from(
  csv: csvData,
  mode: "raw"
)

Function updates


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.