#[sqlfunc]Expand description
Derive function traits for SQL functions.
The sqlfunc attribute macro is used to derive SQL function traits for unary and binary
functions. Depending on the kind of function, it will implement the appropriate traits.
For unary functions, it implements the EagerUnaryFunc trait, and for binary functions,
it implements the EagerBinaryFunc trait.
The macro takes the following arguments:
is_monotone: An expression indicating whether the function is monotone. For unary functions, it should be an expression that evaluates to a boolean. For binary functions, it should be a tuple of two expressions, each evaluating to a boolean. SeeLazyBinaryFuncfor details.sqlname: The SQL name of the function.preserves_uniqueness: A boolean indicating whether the function preserves uniqueness. Unary functions only.inverse: A function that is the inverse of the function. Applies to unary functions only.negate: A function that negates the function. Applies to binary functions only. For example, the!=operator is the negation of the=operator, and we’d mark theEqfunction withnegate = Some(BinaryFunc::NotEq).is_infix_op: A boolean indicating whether the function is an infix operator. Applies to binary functions only.output_type: The output type of the function.output_type_expr: An expression that evaluates to the output type. Applies to binary functions only. The expression has access to theinput_type_aandinput_type_bvariables, and should evaluate to aSqlColumnTypevalue. Requiresintroduces_nulls, and conflicts withoutput_type.could_error: A boolean indicating whether the function could error.propagate_nulls: A boolean indicating whether the function propagates nulls. Applies to binary functions only. If not specified, use the default implementation from the trait. The default is to return true if all input types are not-nullable.introduces_nulls: A boolean indicating whether the function introduces nulls. Applies to all functions. If not specified, use the default implementation from the trait. The default is to return thenullableproperty of the output type.
§Limitations
- The input and output types can contain lifetime parameters, as long as they are
'a. - Unary functions cannot yet receive a
&RowArenaas an argument. - The
output_type
§Examples
ⓘ
use mz_expr_derive::sqlfunc;
#[sqlfunc(sqlname = "!")]
fn negate(a: bool) -> bool {
!a
}