InfluxElixir.Query.ResponseParser (InfluxElixir v0.1.35)

Copy Markdown View Source

Parses InfluxDB query responses in JSON, JSONL, and Flux annotated CSV formats, and passes Parquet bodies through untouched.

Type Coercion

  • Timestamps → DateTime.t() with microsecond precision. JSON carries no column types, so this is by shape and by name: any string in InfluxDB 3's zone-less timestamp rendering (2023-11-14T22:13:20[.fraction]) is a timestamp whatever its column is called (DATE_BIN aliases, selector_*(...)['time'], MAX(time)); the zoned RFC3339 form is decoded only under time, _time, _start and _stop, where v2 emits it. A string field holding exactly that zone-less shape is decoded too — store zoned RFC3339 strings if the distinction matters.
  • JSON / JSONL numbers and booleans keep the types Jason decodes
  • CSV cells are typed from the Flux #datatype annotation row when the query requested one (double, long, unsignedLong, boolean, dateTime:RFC3339[Nano]); without it (InfluxDB 3's format: :csv) every cell stays a string. An empty cell is left out of the row, as a null column is in JSON: CSV writes a null and an empty string alike. A newline inside a value is restored: InfluxDB 2's CSV writer sends it as \r\n

Summary

Functions

Coerces known value types in a row map.

Parses a response body based on the specified format.

Functions

coerce_types(row)

@spec coerce_types(map()) :: map()

Coerces known value types in a row map.

Converts timestamp strings to DateTime (see "Type Coercion" in the moduledoc for which strings count as timestamps); leaves everything else as-is.

parse(body, format \\ :json)

@spec parse(binary(), atom()) :: {:ok, [map()] | binary()} | {:error, term()}

Parses a response body based on the specified format.

Parameters

  • body - response body binary
  • format - one of :json, :jsonl, :csv, :parquet

Returns

  • {:ok, [map()]} — list of row maps ({:ok, binary()} for :parquet)
  • {:error, reason} — parse failure