LanceDB.Expr (LanceDB v0.2.0)

Copy Markdown View Source

Composable SQL expressions for filters, projections and writes.

Column names are quoted exactly (including case and dots); values are always literals. Use col/2 for a merge relation and field/2 for a nested field. Expressions follow SQL null semantics: use is_null/1, not eq(column, nil). Existing APIs continue to accept SQL strings as well.

alias LanceDB.Expr, as: E
predicate = E.all([E.gte(E.col(:price), 10), E.eq(E.col(:category), "books")])
LanceDB.Query.query(table, filter: predicate, select: [cost: E.mul(E.col(:price), 2)])
LanceDB.Table.update(table, %{price: E.add(E.col(:price), 1)}, filter: predicate)

call/2 invokes a scalar function registered in the pinned SDK. Function existence, argument types and column resolution are checked when executed. Builders raise ArgumentError for invalid inputs.

Summary

Functions

Combines two expressions using SQL +. Plain values become literals.

Combines predicates with AND. An empty list is true.

Combines predicates with OR. An empty list is false.

Builds an arbitrary binary literal.

Invokes a registered scalar function with expression or literal arguments.

References an exact column name, optionally qualified by a relation (such as source or target).

Combines two expressions using SQL /. Plain values become literals.

Combines two expressions using SQL =. Plain values become literals.

References a child of a struct expression.

Combines two expressions using SQL >. Plain values become literals.

Combines two expressions using SQL >=. Plain values become literals.

Combines two expressions using SQL ILIKE. Plain values become literals.

Tests membership in a list of expressions or literals. An empty list is false.

Tests whether an expression is non-null.

Tests whether an expression is SQL NULL.

Combines two expressions using SQL LIKE. Plain values become literals.

Builds a literal; strings are UTF-8 text. Use binary/1 for arbitrary bytes.

Combines two expressions using SQL <. Plain values become literals.

Combines two expressions using SQL <=. Plain values become literals.

Combines two expressions using SQL *. Plain values become literals.

Negates a predicate using SQL NOT.

Combines two expressions using SQL <>. Plain values become literals.

Combines two expressions using SQL -. Plain values become literals.

Serializes an expression to SQL, quoting identifiers and literals.

Types

input()

@type input() :: t() | nil | boolean() | number() | String.t() | Date.t()

t()

@opaque t()

Functions

add(left, right)

@spec add(input(), input()) :: t()

Combines two expressions using SQL +. Plain values become literals.

all(values)

@spec all([input()]) :: t()

Combines predicates with AND. An empty list is true.

any(values)

@spec any([input()]) :: t()

Combines predicates with OR. An empty list is false.

binary(value)

@spec binary(binary()) :: t()

Builds an arbitrary binary literal.

call(name, args)

@spec call(atom() | String.t(), [input()]) :: t()

Invokes a registered scalar function with expression or literal arguments.

col(name, opts \\ [])

@spec col(atom() | String.t(), keyword()) :: t()

References an exact column name, optionally qualified by a relation (such as source or target).

div(left, right)

@spec div(input(), input()) :: t()

Combines two expressions using SQL /. Plain values become literals.

eq(left, right)

@spec eq(input(), input()) :: t()

Combines two expressions using SQL =. Plain values become literals.

field(expression, name)

@spec field(input(), atom() | String.t()) :: t()

References a child of a struct expression.

gt(left, right)

@spec gt(input(), input()) :: t()

Combines two expressions using SQL >. Plain values become literals.

gte(left, right)

@spec gte(input(), input()) :: t()

Combines two expressions using SQL >=. Plain values become literals.

ilike(left, right)

@spec ilike(input(), input()) :: t()

Combines two expressions using SQL ILIKE. Plain values become literals.

in_list(value, values)

@spec in_list(input(), [input()]) :: t()

Tests membership in a list of expressions or literals. An empty list is false.

is_not_null(value)

@spec is_not_null(input()) :: t()

Tests whether an expression is non-null.

is_null(value)

@spec is_null(input()) :: t()

Tests whether an expression is SQL NULL.

like(left, right)

@spec like(input(), input()) :: t()

Combines two expressions using SQL LIKE. Plain values become literals.

lit(expression)

@spec lit(input()) :: t()

Builds a literal; strings are UTF-8 text. Use binary/1 for arbitrary bytes.

lt(left, right)

@spec lt(input(), input()) :: t()

Combines two expressions using SQL <. Plain values become literals.

lte(left, right)

@spec lte(input(), input()) :: t()

Combines two expressions using SQL <=. Plain values become literals.

mul(left, right)

@spec mul(input(), input()) :: t()

Combines two expressions using SQL *. Plain values become literals.

negate(value)

@spec negate(input()) :: t()

Negates a predicate using SQL NOT.

neq(left, right)

@spec neq(input(), input()) :: t()

Combines two expressions using SQL <>. Plain values become literals.

sub(left, right)

@spec sub(input(), input()) :: t()

Combines two expressions using SQL -. Plain values become literals.

to_sql(expr)

@spec to_sql(t()) :: String.t()

Serializes an expression to SQL, quoting identifiers and literals.