8 #include <cudf/column/scalar_column_view.hpp>
16 #include <cuda/stream>
20 #include <initializer_list>
30 namespace CUDF_EXPORT
cudf {
62 class expression_parser;
63 class expression_transformer;
87 virtual std::reference_wrapper<expression const>
accept(
88 detail::expression_transformer& visitor)
const = 0;
96 [[nodiscard]]
virtual std::unique_ptr<cudf::detail::row_ir::node>
accept(
97 cudf::detail::row_ir::ast_converter& visitor)
const = 0;
108 return may_evaluate_null(left, left, stream);
121 cuda::stream_ref stream)
const = 0;
148 template <
typename T>
149 __device__ T
const value() const noexcept
151 if constexpr (std::is_same_v<T, cudf::string_view>) {
152 return string_view(
static_cast<char const*
>(_data), _size);
154 if constexpr (cudf::is_fixed_point<T>()) {
155 using rep_type =
typename T::rep;
156 auto const rep = *
static_cast<rep_type const*
>(_data);
160 return *
static_cast<T const*
>(_data);
167 template <
typename T>
177 template <
typename T>
187 template <
typename T>
206 template <
typename T>
225 :
cudf::detail::scalar_device_view_base(type,
is_valid), _data(data)
238 :
cudf::detail::scalar_device_view_base(type,
is_valid), _data(data), _size(size)
254 template <
typename T>
266 template <
typename T>
278 template <
typename T>
299 template <
typename T>
320 [](
auto const& value) {
321 if constexpr (std::is_same_v<std::decay_t<decltype(value)>, ast_scalar>) {
322 return value.value.type();
337 return std::holds_alternative<scalar_column_view>(
scalar);
357 return std::get<ast_scalar>(
scalar).scalar.get();
367 return std::get<scalar_column_view>(
scalar);
378 std::reference_wrapper<expression const>
accept(
379 detail::expression_transformer& visitor)
const override;
384 [[nodiscard]] std::unique_ptr<cudf::detail::row_ir::node>
accept(
385 cudf::detail::row_ir::ast_converter& visitor)
const override;
389 cuda::stream_ref stream)
const override
400 [[nodiscard]]
bool is_valid(cuda::stream_ref stream)
const
402 if (
auto* s = std::get_if<ast_scalar>(&
scalar)) {
403 return s->scalar.get().is_valid(stream);
405 auto& c = std::get<scalar_column_view>(
scalar);
406 return c.null_count() == 0;
412 std::reference_wrapper<cudf::scalar const>
scalar;
416 std::variant<ast_scalar, scalar_column_view>
scalar;
433 : column_index(column_index), table_source(table_source)
477 std::reference_wrapper<expression const>
accept(
478 detail::expression_transformer& visitor)
const override;
482 cuda::stream_ref stream)
const override
484 return (table_source == table_reference::LEFT ? left : right).column(column_index).has_nulls();
490 [[nodiscard]] std::unique_ptr<cudf::detail::row_ir::node>
accept(
491 cudf::detail::row_ir::ast_converter& visitor)
const override;
539 [[nodiscard]] std::vector<std::reference_wrapper<expression const>>
const&
get_operands()
const
552 std::reference_wrapper<expression const>
accept(
553 detail::expression_transformer& visitor)
const override;
557 cuda::stream_ref stream)
const override;
562 [[nodiscard]] std::unique_ptr<cudf::detail::row_ir::node>
accept(
563 cudf::detail::row_ir::ast_converter& visitor)
const override;
567 std::vector<std::reference_wrapper<expression const>> operands;
592 std::reference_wrapper<expression const>
accept(
593 detail::expression_transformer& visitor)
const override;
597 cuda::stream_ref stream)
const override;
602 [[nodiscard]] std::unique_ptr<cudf::detail::row_ir::node>
accept(
603 cudf::detail::row_ir::ast_converter& visitor)
const override;
612 std::reference_wrapper<expression const> source_;
645 std::reference_wrapper<expression const>
accept(
646 detail::expression_transformer& visitor)
const override;
650 cuda::stream_ref stream)
const override
658 [[nodiscard]] std::unique_ptr<cudf::detail::row_ir::node>
accept(
659 cudf::detail::row_ir::ast_converter& visitor)
const override;
662 std::string column_name;
691 tree& operator=(
tree const&) =
delete;
698 template <
typename Expr,
typename... Args>
699 std::enable_if_t<std::is_base_of_v<expression, Expr>, Expr
const&>
emplace(Args&&... args)
701 auto expr = std::make_unique<Expr>(std::forward<Args>(args)...);
702 Expr
const& expr_ref = *expr;
703 expressions.emplace_back(std::move(expr));
712 template <
typename Expr>
713 decltype(
auto) push(Expr expr)
715 return emplace<Expr>(std::move(expr));
734 [[nodiscard]]
size_t size()
const {
return expressions.size(); }
753 std::vector<std::unique_ptr<expression>> expressions;
761 enum class op : uint8_t {
870 std::vector<std::reference_wrapper<expression const>>
const& args,
872 std::optional<int32_t> target_scale = std::nullopt);
886 std::initializer_list<std::reference_wrapper<expression const>> args,
888 std::optional<int32_t> target_scale = std::nullopt);
Enum defining the supported AST operators.
A expression referring to data from a column in a table.
bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const override
Returns true if the expression may evaluate to null.
cudf::size_type accept(detail::expression_parser &visitor) const override
Accepts a visitor class.
std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const override
Accepts a visitor class.
std::string get_column_name() const
Get the column name.
std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const override
Accepts a visitor class.
column_name_reference(std::string column_name)
Construct a new column name reference object.
A expression referring to data from a column in a table.
cudf::data_type get_data_type(table_view const &left_table, table_view const &right_table) const
Get the data type.
std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const override
Accepts a visitor class.
cudf::size_type accept(detail::expression_parser &visitor) const override
Accepts a visitor class.
cudf::data_type get_data_type(table_view const &table) const
Get the data type.
bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const override
Returns true if the expression may evaluate to null.
std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const override
Accepts a visitor class.
table_reference get_table_source() const
Get the table source.
column_reference(cudf::size_type column_index, table_reference table_source=table_reference::LEFT)
Construct a new column reference object.
cudf::size_type get_column_index() const
Get the column index.
An expression that represents a predicate.
std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const override
Accepts a visitor class.
bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const override
Returns true if the expression may evaluate to null.
predicate(expression const &source)
Construct a new filter predicate object.
expression const & get_operand() const
Get the operand expression.
std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const override
Accepts a visitor class.
cudf::size_type accept(detail::expression_parser &visitor) const override
Accepts a visitor class.
A type-erased scalar_device_view where the value is a fixed width type or a string.
generic_scalar_device_view(duration_scalar< T > &s)
Construct a new generic scalar device view object from a duration scalar.
generic_scalar_device_view(cudf::fixed_point_scalar< T > &s)
Construct a new generic scalar device view object from a fixed-point scalar.
generic_scalar_device_view(data_type type, void const *data, bool *is_valid)
Construct a new fixed width scalar device view object.
generic_scalar_device_view(string_scalar &s)
Construct a new generic scalar device view object from a string scalar.
generic_scalar_device_view(timestamp_scalar< T > &s)
Construct a new generic scalar device view object from a timestamp scalar.
generic_scalar_device_view(data_type type, void const *data, bool *is_valid, size_type size)
Construct a new string scalar device view object.
T const value() const noexcept
Returns the stored value.
generic_scalar_device_view(numeric_scalar< T > &s)
Construct a new generic scalar device view object from a numeric scalar.
A literal value used in an abstract syntax tree.
literal(cudf::numeric_scalar< T > &value)
Construct a new literal object.
std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const override
Accepts a visitor class.
cudf::size_type accept(detail::expression_parser &visitor) const override
Accepts a visitor class.
bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const override
Returns true if the expression may evaluate to null.
generic_scalar_device_view get_value() const
Get the value object.
bool is_scalar_column_view() const noexcept
Check whether the literal is backed by a scalar column view.
cudf::data_type get_data_type() const
Get the data type.
literal(cudf::string_scalar &value)
Construct a new literal object.
cudf::scalar const & get_scalar() const
Get the scalar.
literal(cudf::duration_scalar< T > &value)
Construct a new literal object.
scalar_column_view const & get_scalar_column_view() const
Get scalar column view.
bool is_valid(cuda::stream_ref stream) const
Check if the underlying scalar is valid.
std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const override
Accepts a visitor class.
literal(scalar_column_view value)
Construct a new literal object.
literal(cudf::fixed_point_scalar< T > &value)
Construct a new literal object.
literal(cudf::timestamp_scalar< T > &value)
Construct a new literal object.
An operation expression holds an operator and zero or more operands.
std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const override
Accepts a visitor class.
std::vector< std::reference_wrapper< expression const > > const & get_operands() const
Get the operands.
ast_operator get_operator() const
Get the operator.
operation(ast_operator op, expression const &left, expression const &right)
Construct a new binary operation object.
bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const override
Returns true if the expression may evaluate to null.
std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const override
Accepts a visitor class.
operation(ast_operator op, expression const &input)
Construct a new unary operation object.
cudf::size_type accept(detail::expression_parser &visitor) const override
Accepts a visitor class.
An AST expression tree. It owns and contains multiple dependent expressions. All the expressions are ...
tree(tree &&)=default
Moves the ast tree.
tree & operator=(tree &&)=default
move-assigns the AST tree
size_t size() const
get the number of expressions added to the tree
std::enable_if_t< std::is_base_of_v< expression, Expr >, Expr const & > emplace(Args &&... args)
Add an expression to the AST tree.
tree()=default
construct an empty ast tree
expression const & front() const
get the first expression in the tree
expression const & at(size_t index)
get the expression at an index in the tree. Index is checked.
expression const & back() const
get the last expression in the tree
expression const & operator[](size_t index) const
get the expression at an index in the tree. Index is unchecked.
Indicator for the logical data type of an element in a column.
A non-owning view of scalar from device that is trivially copyable and usable in CUDA device code.
An owning class to represent a duration value in device memory.
An owning class to represent a fixed_point number in device memory.
An owning class to represent a numerical value in device memory.
An owning class to represent a singular value.
An owning class to represent a string in device memory.
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
A set of cudf::column_view's of the same size.
A set of cudf::column's of the same size.
An owning class to represent a timestamp value in device memory.
Exception types and error-checking macros used throughout libcudf.
op
JIT operation kinds for cudf::ast::jit::operation.
@ ADD_OVERFLOW
Overflow-checking Arithmetic functions. raise errors on overflow, division by zero,...
@ CAST_TO_BOOL8
Type conversion/scaling operators.
Class definition for fixed point data type.
table_reference
Enum of table references.
ast_operator
Enum of supported operators.
@ RIGHT
Column index in the right table.
@ OUTPUT
Column index in the output table.
@ LEFT
Column index in the left table.
@ TANH
Hyperbolic tangent.
@ DIV
operator / using common type of lhs and rhs
@ CBRT
Cube-root (x^(1.0/3))
@ ARCSINH
Hyperbolic sine inverse.
@ SQRT
Square-root (x^0.5)
@ PYMOD
operator % using Python's sign rules for negatives
@ LOG
Natural Logarithm (base e)
@ FLOOR
largest integer value not greater than arg
@ ARCTAN
Trigonometric tangent inverse.
@ CEIL
Smallest integer value not less than arg.
@ ARCSIN
Trigonometric sine inverse.
@ RINT
Rounds the floating-point argument arg to an integer value.
@ TAN
Trigonometric tangent.
@ ARCCOS
Trigonometric cosine inverse.
@ ARCTANH
Hyperbolic tangent inverse.
@ GREATER_EQUAL
operator >=
@ EXP
Exponential (base e, Euler number)
@ CAST_TO_FLOAT64
Cast value to double.
@ TRUE_DIV
operator / after promoting type to floating point
@ CAST_TO_UINT64
Cast value to uint64_t.
@ ARCCOSH
Hyperbolic cosine inverse.
@ IDENTITY
Identity function.
@ IS_NULL
Check if operand is null.
@ CAST_TO_INT64
Cast value to int64_t.
@ COS
Trigonometric cosine.
scale_type
The scale type for fixed_point.
int32_t size_type
Row index type for columns and tables.
error_policy
Indicates whether a function nullifies its output on error.
@ PROPAGATE
The function propagates errors.
Class definitions for cudf::scalar.
Scalar device view class definitions.
A generic expression that can be evaluated to return a value.
virtual std::unique_ptr< cudf::detail::row_ir::node > accept(cudf::detail::row_ir::ast_converter &visitor) const =0
Accepts an row_ir::ast_converter class.
virtual cudf::size_type accept(detail::expression_parser &visitor) const =0
Accepts a visitor class.
bool may_evaluate_null(table_view const &left, cuda::stream_ref stream) const
Returns true if the expression may evaluate to null.
virtual std::reference_wrapper< expression const > accept(detail::expression_transformer &visitor) const =0
Accepts a visitor class.
virtual bool may_evaluate_null(table_view const &left, table_view const &right, cuda::stream_ref stream) const =0
Returns true if the expression may evaluate to null.
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Helper struct for constructing fixed_point when value is already shifted.
Class definitions for (mutable)_table_view
Type declarations for libcudf.