InfluxElixir.Client.Local.SQLFunctions (InfluxElixir v0.1.38)

Copy Markdown View Source

The scalar math functions Client.Local evaluates in SQL expressions, wherever an expression stands (WHERE, the select list, ORDER BY, an aggregate's argument), as InfluxDB 3 does (verified against Core):

  • abs(x) — the magnitude, in the argument's type
  • round(x), round(x, n) — half away from zero (round(-2.5) is -3.0), to n decimal places (negative n rounds left of the point: round(1234.5678, -2) is 1200.0); always a float
  • floor(x), ceil(x) — always a float

A null argument makes the result null. Names are case-insensitive.

The engine checks the arguments' types when it plans the query, so a wrong one fails the query even when no row would reach the call (check/3). The message depends on where the call stands: in WHERE it carries the type_coercion prefix, in ORDER BY it is cut after its first sentence, and in the select list it has neither. floor and ceil with a second argument are the engine's 405.

Summary

Functions

Evaluates a call the planner has accepted (check/3), its arguments already evaluated: numbers, or nil, which makes the result nil.

The engine's planning error for a call, given its arguments' Arrow types (nil where unknown, which is never refused), or :ok.

The function a name (any case) calls, or nil for any other name.

The Arrow type an expression has, given the columns' types, or nil when it cannot be known.

Types

context()

@type context() :: :where | :select | :order_by

name()

@type name() :: :abs | :round | :floor | :ceil

Functions

call(name, args)

@spec call(name(), [number() | nil]) :: number() | nil

Evaluates a call the planner has accepted (check/3), its arguments already evaluated: numbers, or nil, which makes the result nil.

check(name, types, context)

@spec check(name(), [binary() | nil], context()) :: :ok | {:error, map()}

The engine's planning error for a call, given its arguments' Arrow types (nil where unknown, which is never refused), or :ok.

lookup(name)

@spec lookup(binary()) :: name() | nil

The function a name (any case) calls, or nil for any other name.

type_of(arg1, columns)

@spec type_of(InfluxElixir.Client.Local.SQLParser.expr(), %{
  required(binary()) => binary()
}) ::
  binary() | nil

The Arrow type an expression has, given the columns' types, or nil when it cannot be known.