InfluxElixir.Client.Local.SQLWhere (InfluxElixir v0.1.40)

Copy Markdown View Source

The WHERE clause of a SQL text: a boolean expression over predicates (verified against InfluxDB 3 Core).

expr   := term (OR term)*
term   := factor (AND factor)*
factor := NOT factor | '(' expr ')' | predicate

AND binds tighter than OR, as in SQL. The result is a conjunction list; OR and NOT appear as nodes inside it, so a plain a AND b is still the flat list every executor path already understands. A predicate is a comparison, IN, BETWEEN, LIKE / ILIKE, a regular-expression match, IS [NOT] NULL or a bare boolean column; a $name is kept as a node for InfluxElixir.Client.Local.SQLBind.

Summary

Types

A predicate: operator, left operand, right side.

A WHERE conjunction is a list of nodes: a predicate, an {:or, branches} node whose branches are conjunctions, or a {:not, conjunction} node.

The comparison, set and pattern operators of a predicate.

A WHERE operand: a column name, or an arithmetic expression over columns and literals (price <= med * 3).

Functions

Compiles a SQL regular expression for the match operator op (~, ~*, !~, !~*); an invalid pattern is the optimizer's error.

A type error found in a time clause, kept as a clause for the planner to raise when it types the query.

A LIKE (or, with case_insensitive, ILIKE) pattern as an anchored regular expression.

The operator that holds when the two sides of a comparison swap places.

Parses the WHERE ... clause (if any) out of the text after FROM <table>.

The SQL symbol of a comparison operator.

Types

clause()

@type clause() ::
  {op(), binary() | {:expr, InfluxElixir.Client.Local.SQLExpr.t()}, term()}

A predicate: operator, left operand, right side.

node_t()

@type node_t() :: clause() | {:or, [[node_t()]]} | {:not, [node_t()]}

A WHERE conjunction is a list of nodes: a predicate, an {:or, branches} node whose branches are conjunctions, or a {:not, conjunction} node.

op()

@type op() ::
  :eq
  | :gt
  | :lt
  | :gte
  | :lte
  | :ne
  | :in
  | :not_in
  | :is_null
  | :is_not_null
  | :between
  | :not_between
  | :like
  | :not_like
  | :regex
  | :not_regex
  | :time_type_error

The comparison, set and pattern operators of a predicate.

operand()

@type operand() :: binary() | {:expr, InfluxElixir.Client.Local.SQLExpr.t()}

A WHERE operand: a column name, or an arithmetic expression over columns and literals (price <= med * 3).

Functions

compile_regex(pattern, op)

@spec compile_regex(binary(), binary()) ::
  {:ok, Regex.t()} | {:error, InfluxElixir.Client.Local.SQLError.t()}

Compiles a SQL regular expression for the match operator op (~, ~*, !~, !~*); an invalid pattern is the optimizer's error.

deferred_clause(error)

@spec deferred_clause(InfluxElixir.Client.Local.SQLError.t()) :: clause()

A type error found in a time clause, kept as a clause for the planner to raise when it types the query.

like_regex(pattern, case_insensitive)

@spec like_regex(binary(), boolean()) :: Regex.t()

A LIKE (or, with case_insensitive, ILIKE) pattern as an anchored regular expression.

mirror(op)

@spec mirror(op()) :: op()

The operator that holds when the two sides of a comparison swap places.

nodes(rest)

@spec nodes(binary()) ::
  {:ok, [node_t()]} | {:error, InfluxElixir.Client.Local.SQLError.t()}

Parses the WHERE ... clause (if any) out of the text after FROM <table>.

symbol(atom)

@spec symbol(op()) :: binary()

The SQL symbol of a comparison operator.