InfluxElixir.Client.Local.LineProtocolParser (InfluxElixir v0.1.28)

Copy Markdown View Source

Line protocol parser for InfluxElixir.Client.Local.

Turns a line-protocol payload into point maps, honouring the escaping rules of the format (escaped spaces, commas, equals signs, backslashes and quotes) and the write precision. Each line is parsed on its own so a caller can store the good lines and report the bad ones, which is what InfluxDB 3 does ("partial write of line protocol occurred").

Per-line rules verified against InfluxDB 3 Core: an integer must fit in 64 bits (u marks an unsigned one), time is a reserved column, and a key cannot be both a tag and a field on one line.

Summary

Types

One rejected line, in the shape InfluxDB 3's partial-write response lists (the original line is truncated to 20 characters, as the engine does).

A line's outcome: the point with its line number and text, or the error.

A parsed point: fields and tags as string-keyed maps, timestamp in ns.

Functions

The engine's name for a column kind: iox::column_type::tag or iox::column_type::field::<integer | uinteger | float | string | boolean>.

Builds a line_error/0 the way the engine reports one.

Parses a line-protocol payload line by line.

Undoes line-protocol escaping in a measurement name (\, \,, \\).

Types

line_error()

@type line_error() :: %{
  error_message: binary(),
  line_number: pos_integer(),
  original_line: binary()
}

One rejected line, in the shape InfluxDB 3's partial-write response lists (the original line is truncated to 20 characters, as the engine does).

line_result()

@type line_result() ::
  {:ok, point(), pos_integer(), binary()} | {:error, line_error()}

A line's outcome: the point with its line number and text, or the error.

point()

@type point() :: %{
  measurement: binary(),
  tags: %{required(binary()) => binary()},
  fields: %{required(binary()) => term()},
  timestamp: integer() | nil
}

A parsed point: fields and tags as string-keyed maps, timestamp in ns.

Functions

column_type(atom, value)

@spec column_type(:tag | :field, term()) :: binary()

The engine's name for a column kind: iox::column_type::tag or iox::column_type::field::<integer | uinteger | float | string | boolean>.

line_error(message, number, line)

@spec line_error(binary(), pos_integer(), binary()) :: line_error()

Builds a line_error/0 the way the engine reports one.

parse_lines(text, precision)

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

Parses a line-protocol payload line by line.

Blank lines and # comments are skipped. precision is one of :nanosecond | :microsecond | :millisecond | :second and scales numeric timestamps to nanoseconds. A point without a timestamp keeps nil; the caller assigns the server time. A newline inside a quoted string field value is part of the value, as the engine reads it.

Returns {:error, ...} only for a payload with no lines at all ("incoming write was empty" on the engine); every other problem is a per-line {:error, line_error} in the list, numbered as the engine numbers it.

unescape_measurement(str)

@spec unescape_measurement(binary()) :: binary()

Undoes line-protocol escaping in a measurement name (\, \,, \\).