csv.from() function

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.

*Function type: Input*

  1. import "csv"
  2. csv.from(csv: csvData)
  3. // OR
  4. csv.from(file: "/path/to/data-file.csv")

Parameters

csv

Annotated CSV text.

CSV data must use Annotated CSV syntax and include all annotation rows. For more information, see Annotated CSV.

*Data type: String*

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.

*Data type: String*

Examples

Query CSV data from a file

  1. import "csv"
  2. csv.from(file: "/path/to/data-file.csv")

Query raw CSV-formatted text

  1. import "csv"
  2. csvData = "
  3. #datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double
  4. #group,false,false,false,false,false,false,false,false
  5. #default,,,,,,,,
  6. ,result,table,_start,_stop,_time,region,host,_value
  7. ,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:00Z,east,A,15.43
  8. ,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:20Z,east,B,59.25
  9. ,mean,0,2018-05-08T20:50:00Z,2018-05-08T20:51:00Z,2018-05-08T20:50:40Z,east,C,52.62
  10. "
  11. csv.from(csv: csvData)