Expression Evaluation#
- group Expression Evaluation
Enums
-
enum class ast_operator : int32_t#
Enum of supported operators.
Values:
-
enumerator ADD#
operator +
-
enumerator SUB#
operator -
-
enumerator MUL#
operator *
-
enumerator DIV#
operator / using common type of lhs and rhs
-
enumerator TRUE_DIV#
operator / after promoting type to floating point
-
enumerator FLOOR_DIV#
operator / after promoting to the common type of lhs and rhs (integral or floating point), and then flooring the result
-
enumerator MOD#
operator %
-
enumerator PYMOD#
operator % using Python’s sign rules for negatives
-
enumerator POW#
lhs ^ rhs
-
enumerator EQUAL#
operator ==: returns NULL when either operand is NULL, otherwise returns whether they are equal
-
enumerator NULL_EQUAL#
null-safe equality (result is never null): returns true if both operands are null, false if one is null, otherwise returns whether they are equal
-
enumerator NOT_EQUAL#
operator !=: returns NULL when either operand is NULL, otherwise returns whether they are unequal
-
enumerator LESS#
operator <
-
enumerator GREATER#
operator >
-
enumerator LESS_EQUAL#
operator <=
-
enumerator GREATER_EQUAL#
operator >=
-
enumerator BITWISE_AND#
operator &
-
enumerator BITWISE_OR#
operator |
-
enumerator BITWISE_XOR#
operator ^
-
enumerator LOGICAL_AND#
operator &&: returns NULL when either operand is NULL, otherwise returns true only if both operands are true
-
enumerator NULL_LOGICAL_AND#
three-valued (Kleene) &&: if any operand is false, returns false; if both operands are true, returns true; otherwise returns null
-
enumerator LOGICAL_OR#
operator ||: returns NULL when either operand is NULL, otherwise returns true only if either or both operands are true
-
enumerator NULL_LOGICAL_OR#
three-valued (Kleene) ||: if any operand is true, returns true; if both operands are false, returns false; otherwise returns null
-
enumerator IDENTITY#
Identity function.
-
enumerator IS_NULL#
Check if operand is null.
-
enumerator SIN#
Trigonometric sine.
-
enumerator COS#
Trigonometric cosine.
-
enumerator TAN#
Trigonometric tangent.
-
enumerator ARCSIN#
Trigonometric sine inverse.
-
enumerator ARCCOS#
Trigonometric cosine inverse.
-
enumerator ARCTAN#
Trigonometric tangent inverse.
-
enumerator SINH#
Hyperbolic sine.
-
enumerator COSH#
Hyperbolic cosine.
-
enumerator TANH#
Hyperbolic tangent.
-
enumerator ARCSINH#
Hyperbolic sine inverse.
-
enumerator ARCCOSH#
Hyperbolic cosine inverse.
-
enumerator ARCTANH#
Hyperbolic tangent inverse.
-
enumerator EXP#
Exponential (base e, Euler number).
-
enumerator LOG#
Natural Logarithm (base e).
-
enumerator SQRT#
Square-root (x^0.5).
-
enumerator CBRT#
Cube-root (x^(1.0/3)).
-
enumerator CEIL#
Smallest integer value not less than arg.
-
enumerator FLOOR#
largest integer value not greater than arg
-
enumerator ABS#
Absolute value.
-
enumerator RINT#
Rounds the floating-point argument arg to an integer value.
-
enumerator BIT_INVERT#
Bitwise Not (~).
-
enumerator NOT#
Logical Not (!).
-
enumerator CAST_TO_INT64#
Cast value to int64_t.
-
enumerator CAST_TO_UINT64#
Cast value to uint64_t.
-
enumerator CAST_TO_FLOAT64#
Cast value to double.
-
enumerator CAST_TO_BOOL8#
Cast value to bool.
-
enumerator CAST_TO_INT8#
Cast value to int8_t.
-
enumerator CAST_TO_INT16#
Cast value to int16_t.
-
enumerator CAST_TO_INT32#
Cast value to int32_t.
-
enumerator CAST_TO_UINT8#
Cast value to uint8_t.
-
enumerator CAST_TO_UINT16#
Cast value to uint16_t.
-
enumerator CAST_TO_UINT32#
Cast value to uint32_t.
-
enumerator CAST_TO_FLOAT32#
Cast value to float.
-
enumerator CAST_TO_DECIMAL32#
Cast numeric to decimal32; decimal scale is preserved, otherwise zero.
-
enumerator CAST_TO_DECIMAL64#
Cast numeric to decimal64; decimal scale is preserved, otherwise zero.
-
enumerator CAST_TO_DECIMAL128#
Cast a decimal value to decimal128, preserving its scale (JIT only).
-
enumerator RESCALE#
Rescale a fixed-point value to the target scale (truncates toward zero).
-
enumerator ADD#
-
struct expression#
- #include <cudf/ast/expressions.hpp>
A generic expression that can be evaluated to return a value.
This class is a part of a “visitor” pattern with the
expression_parserclass. Expressions inheriting from this class can accept parsers as visitors.Subclassed by cudf::ast::column_name_reference, cudf::ast::column_reference, cudf::ast::detail::predicate, cudf::ast::literal, cudf::ast::operation
Public Functions
- inline explicit expression(
- std::optional<int32_t> expression_id = std::nullopt
Constructs an expression with an optional caller-provided identifier.
IDs do not affect common subexpression elimination. When equivalent expressions are merged, the retained expression’s ID is reported. IDs need not be contiguous or fit in the device operator index.
- Parameters:
expression_id – Identifier to report when this expression fails during JIT execution
- virtual cudf::size_type accept(
- detail::expression_parser &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::reference_wrapper<expression const> accept(
- detail::expression_transformer &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_transformertransforming this expression tree- Returns:
Reference wrapper of transformed expression
- virtual std::unique_ptr<cudf::detail::row_ir::node> accept(
- cudf::detail::row_ir::ast_converter &visitor
Accepts an
row_ir::ast_converterclass.- Parameters:
visitor – The
row_ir::ast_converterconverting this expression tree- Returns:
The IR node representing this expression
- inline bool may_evaluate_null(
- table_view const &left,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression (The same is used as right operand)
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
- virtual bool may_evaluate_null(
- table_view const &left,
- table_view const &right,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression
right – The right operand of the expression
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
-
inline std::optional<int32_t> get_expression_id() const#
Returns the caller-provided expression identifier.
- Returns:
Identifier, or std::nullopt if none was supplied
-
inline virtual ~expression()#
Destroy the expression object.
-
class generic_scalar_device_view : public cudf::detail::scalar_device_view_base#
- #include <cudf/ast/expressions.hpp>
A type-erased scalar_device_view where the value is a fixed width type or a string.
Public Functions
-
template<typename T>
inline T const value() const noexcept# Returns the stored value.
- Template Parameters:
T – The desired type
- Returns:
The stored value
-
template<typename T>
inline generic_scalar_device_view( - numeric_scalar<T> &s
Construct a new generic scalar device view object from a numeric scalar.
- Parameters:
s – The numeric scalar to construct from
-
template<typename T>
inline generic_scalar_device_view( - timestamp_scalar<T> &s
Construct a new generic scalar device view object from a timestamp scalar.
- Parameters:
s – The timestamp scalar to construct from
-
template<typename T>
inline generic_scalar_device_view( - duration_scalar<T> &s
Construct a new generic scalar device view object from a duration scalar.
- Parameters:
s – The duration scalar to construct from
-
inline generic_scalar_device_view(string_scalar &s)#
Construct a new generic scalar device view object from a string scalar.
- Parameters:
s – The string scalar to construct from
-
template<typename T>
inline generic_scalar_device_view( - cudf::fixed_point_scalar<T> &s
Construct a new generic scalar device view object from a fixed-point scalar.
- Parameters:
s – The fixed-point scalar to construct from
-
template<typename T>
-
class literal : public cudf::ast::expression#
- #include <cudf/ast/expressions.hpp>
A literal value used in an abstract syntax tree.
Public Functions
-
template<typename T>
inline literal( - cudf::numeric_scalar<T> &value
Construct a new literal object.
- Template Parameters:
T – Numeric scalar template type
- Parameters:
value – A numeric scalar value
-
template<typename T>
inline literal( - cudf::timestamp_scalar<T> &value
Construct a new literal object.
- Template Parameters:
T – Timestamp scalar template type
- Parameters:
value – A timestamp scalar value
-
template<typename T>
inline literal( - cudf::duration_scalar<T> &value
Construct a new literal object.
- Template Parameters:
T – Duration scalar template type
- Parameters:
value – A duration scalar value
-
inline literal(cudf::string_scalar &value)#
Construct a new literal object.
- Parameters:
value – A string scalar value
-
template<typename T>
inline literal( - cudf::fixed_point_scalar<T> &value
Construct a new literal object.
- Parameters:
value – A fixed-point scalar value
-
inline literal(scalar_column_view value)#
Construct a new literal object.
- Parameters:
value – A scalar column view value
-
inline cudf::data_type get_data_type() const#
Get the data type.
- Returns:
The data type of the literal
-
inline bool is_scalar_column_view() const noexcept#
Check whether the literal is backed by a scalar column view.
- Returns:
true if the literal is backed by a scalar column view
-
inline generic_scalar_device_view get_value() const#
Get the value object.
- Returns:
The device scalar object
-
inline scalar_column_view const &get_scalar_column_view() const#
Get scalar column view.
- Returns:
The scalar column view object
- virtual cudf::size_type accept(
- detail::expression_parser &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::reference_wrapper<expression const> accept(
- detail::expression_transformer &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::unique_ptr<cudf::detail::row_ir::node> accept(
- cudf::detail::row_ir::ast_converter &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- inline virtual bool may_evaluate_null(
- table_view const &left,
- table_view const &right,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression
right – The right operand of the expression
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
-
inline bool is_valid(cuda::stream_ref stream) const#
Check if the underlying scalar is valid.
- Parameters:
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
true if the underlying scalar is valid
-
template<typename T>
-
class column_reference : public cudf::ast::expression#
- #include <cudf/ast/expressions.hpp>
A expression referring to data from a column in a table.
Public Functions
- inline column_reference(
- cudf::size_type column_index,
- table_reference table_source = table_reference::LEFT
Construct a new column reference object.
- Parameters:
column_index – Index of this column in the table (provided when the expression is evaluated).
table_source – Which table to use in cases with two tables (e.g. joins)
-
inline cudf::size_type get_column_index() const#
Get the column index.
- Returns:
The column index of the column reference
-
inline table_reference get_table_source() const#
Get the table source.
- Returns:
table_reference The reference to the table containing this column
-
cudf::data_type get_data_type(table_view const &table) const#
Get the data type.
- Parameters:
table – Table used to determine types
- Returns:
The data type of the column
- cudf::data_type get_data_type(
- table_view const &left_table,
- table_view const &right_table
Get the data type.
- Parameters:
left_table – Left table used to determine types
right_table – Right table used to determine types
- Returns:
The data type of the column
- virtual cudf::size_type accept(
- detail::expression_parser &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::reference_wrapper<expression const> accept(
- detail::expression_transformer &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- inline virtual bool may_evaluate_null(
- table_view const &left,
- table_view const &right,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression
right – The right operand of the expression
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
-
class operation : public cudf::ast::expression#
- #include <cudf/ast/expressions.hpp>
An operation expression holds an operator and zero or more operands.
Public Functions
- operation(
- ast_operator op,
- expression const &input,
- std::optional<int32_t> expression_id = std::nullopt
Construct a new unary operation object.
- Parameters:
op – Operator
input – Input expression (operand)
expression_id – Caller identifier reported on JIT evaluation failure
- operation(
- ast_operator op,
- expression const &input,
- numeric::scale_type target_scale,
- std::optional<int32_t> expression_id = std::nullopt
Construct a scale-aware RESCALE operation.
- Parameters:
op – Operator; must be
ast_operator::RESCALEinput – Input fixed-point expression
target_scale – Desired output scale
expression_id – Caller identifier reported on JIT evaluation failure
- operation(
- ast_operator op,
- expression const &left,
- expression const &right,
- std::optional<int32_t> expression_id = std::nullopt
Construct a new binary operation object.
- Parameters:
op – Operator
left – Left input expression (left operand)
right – Right input expression (right operand)
expression_id – Caller identifier reported on JIT evaluation failure
-
inline ast_operator get_operator() const#
Get the operator.
- Returns:
The operator
-
inline std::optional<numeric::scale_type> get_target_scale() const#
Get the optional target scale for a scale-aware operation.
- Returns:
Target scale for RESCALE, or
std::nulloptotherwise
- inline std::vector<std::reference_wrapper<expression const>> const &get_operands(
Get the operands.
- Returns:
Vector of operands
- virtual cudf::size_type accept(
- detail::expression_parser &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::reference_wrapper<expression const> accept(
- detail::expression_transformer &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual bool may_evaluate_null(
- table_view const &left,
- table_view const &right,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression
right – The right operand of the expression
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
-
class column_name_reference : public cudf::ast::expression#
- #include <cudf/ast/expressions.hpp>
A expression referring to data from a column in a table.
Public Functions
-
inline column_name_reference(std::string column_name)#
Construct a new column name reference object.
- Parameters:
column_name – Name of this column in the table metadata (provided when the expression is evaluated).
-
inline std::string get_column_name() const#
Get the column name.
- Returns:
The name of this column reference
- virtual cudf::size_type accept(
- detail::expression_parser &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- virtual std::reference_wrapper<expression const> accept(
- detail::expression_transformer &visitor
Accepts a visitor class.
- Parameters:
visitor – The
expression_parserparsing this expression tree- Returns:
Index of device data reference for this instance
- inline virtual bool may_evaluate_null(
- table_view const &left,
- table_view const &right,
- cuda::stream_ref stream
Returns true if the expression may evaluate to null.
- Parameters:
left – The left operand of the expression
right – The right operand of the expression
stream – CUDA stream used for device memory operations and kernel launches
- Returns:
trueif the expression may evaluate to null, otherwise false
-
inline column_name_reference(std::string column_name)#
-
class tree#
- #include <cudf/ast/expressions.hpp>
An AST expression tree. It owns and contains multiple dependent expressions. All the expressions are destroyed when the tree is destroyed.
Public Functions
-
tree() = default#
construct an empty ast tree
-
tree &operator=(tree&&) = default#
move-assigns the AST tree
- Returns:
a reference to the move-assigned tree
-
template<typename Expr, typename ...Args>
inline Expr const &emplace( - Args&&... args
Add an expression to the AST tree.
- Parameters:
args – Arguments to use to construct the ast expression
- Returns:
a reference to the added expression
-
template<typename Expr>
inline push(Expr expr)# Add an expression to the AST tree.
- Parameters:
expr – AST expression to be added
- Returns:
a reference to the added expression
-
inline expression const &front() const#
get the first expression in the tree
- Returns:
the first inserted expression into the tree
-
inline expression const &back() const#
get the last expression in the tree
- Returns:
the last inserted expression into the tree
-
inline size_t size() const#
get the number of expressions added to the tree
- Returns:
the number of expressions added to the tree
-
inline expression const &at(size_t index)#
get the expression at an index in the tree. Index is checked.
- Parameters:
index – index of expression in the ast tree
- Returns:
the expression at the specified index
-
inline expression const &operator[](size_t index) const#
get the expression at an index in the tree. Index is unchecked.
- Parameters:
index – index of expression in the ast tree
- Returns:
the expression at the specified index
-
tree() = default#
-
enum class ast_operator : int32_t#
-
enum class cudf::ast::jit::op : uint8_t#
JIT operation kinds for
cudf::ast::jit::operation.Values:
-
enumerator IDENTITY#
-
enumerator IS_NULL#
-
enumerator COALESCE#
-
enumerator PREDICATE#
-
enumerator ADD#
Arithmetic operators.
-
enumerator SUB#
-
enumerator MUL#
-
enumerator DIV#
-
enumerator NEG#
-
enumerator ABS#
-
enumerator MOD#
-
enumerator PYMOD#
-
enumerator TRUE_DIV#
-
enumerator FLOOR_DIV#
-
enumerator ADD_OVERFLOW#
Overflow-checking Arithmetic functions. raise errors on overflow, division by zero, etc.
-
enumerator SUB_OVERFLOW#
-
enumerator MUL_OVERFLOW#
-
enumerator DIV_OVERFLOW#
-
enumerator NEG_OVERFLOW#
-
enumerator ABS_OVERFLOW#
-
enumerator MOD_OVERFLOW#
-
enumerator CHECK_PRECISION#
-
enumerator BITWISE_AND#
Bitwise operators.
-
enumerator BITWISE_INVERT#
-
enumerator BITWISE_OR#
-
enumerator BITWISE_XOR#
-
enumerator BITWISE_SHIFT_LEFT#
-
enumerator BITWISE_SHIFT_RIGHT#
-
enumerator CAST_TO_BOOL8#
Type conversion/scaling operators.
-
enumerator CAST_TO_INT8#
-
enumerator CAST_TO_INT16#
-
enumerator CAST_TO_INT32#
-
enumerator CAST_TO_INT64#
-
enumerator CAST_TO_UINT8#
-
enumerator CAST_TO_UINT16#
-
enumerator CAST_TO_UINT32#
-
enumerator CAST_TO_UINT64#
-
enumerator CAST_TO_FLOAT32#
-
enumerator CAST_TO_FLOAT64#
-
enumerator CAST_TO_DECIMAL32#
-
enumerator CAST_TO_DECIMAL64#
-
enumerator CAST_TO_DECIMAL128#
-
enumerator RESCALE#
-
enumerator EQUAL#
Comparison & Logic operators.
-
enumerator NOT_EQUAL#
-
enumerator GREATER#
-
enumerator GREATER_EQUAL#
-
enumerator LESS#
-
enumerator LESS_EQUAL#
-
enumerator NULL_EQUAL#
-
enumerator NULL_LOGICAL_AND#
-
enumerator NULL_LOGICAL_OR#
-
enumerator LOGICAL_AND#
-
enumerator LOGICAL_OR#
-
enumerator LOGICAL_NOT#
-
enumerator IF_ELSE#
-
enumerator CBRT#
Mathematical operators.
-
enumerator CEIL#
-
enumerator FLOOR#
-
enumerator RINT#
-
enumerator SQRT#
-
enumerator POW#
-
enumerator EXP#
-
enumerator LOG#
-
enumerator ARCCOS#
Trigonometric operators.
-
enumerator ARCCOSH#
-
enumerator ARCSIN#
-
enumerator ARCSINH#
-
enumerator ARCTAN#
-
enumerator ARCTANH#
-
enumerator COS#
-
enumerator COSH#
-
enumerator SIN#
-
enumerator SINH#
-
enumerator TAN#
-
enumerator TANH#
-
enumerator IDENTITY#