28#include "iceberg/iceberg_export.h"
29#include "iceberg/result.h"
32#include "iceberg/util/macros.h"
73 virtual Result<std::shared_ptr<Expression>>
Negate()
const {
74 return NotSupported(
"Expression cannot be negated");
85 std::string
ToString()
const override {
return "Expression"; }
87 virtual bool is_unbound_predicate()
const {
return false; }
88 virtual bool is_bound_predicate()
const {
return false; }
89 virtual bool is_unbound_aggregate()
const {
return false; }
90 virtual bool is_bound_aggregate()
const {
return false; }
99 static const std::shared_ptr<True>& Instance();
103 std::string
ToString()
const override {
return "true"; }
105 Result<std::shared_ptr<Expression>> Negate()
const override;
108 return other.op() == Operation::kTrue;
112 constexpr True() =
default;
119 static const std::shared_ptr<False>& Instance();
123 std::string
ToString()
const override {
return "false"; }
125 Result<std::shared_ptr<Expression>> Negate()
const override;
128 return other.op() == Operation::kFalse;
132 constexpr False() =
default;
145 static Result<std::unique_ptr<And>> Make(std::shared_ptr<Expression> left,
146 std::shared_ptr<Expression> right);
157 template <
typename... Args>
158 static Result<std::shared_ptr<Expression>>
MakeFolded(std::shared_ptr<Expression> left,
159 std::shared_ptr<Expression> right,
161 requires std::conjunction_v<std::is_same<Args, std::shared_ptr<Expression>>...>
163 if constexpr (
sizeof...(args) == 0) {
164 if (left->op() == Expression::Operation::kFalse ||
165 right->op() == Expression::Operation::kFalse) {
166 return False::Instance();
169 if (left->op() == Expression::Operation::kTrue) {
173 if (right->op() == Expression::Operation::kTrue) {
177 return And::Make(std::move(left), std::move(right));
179 ICEBERG_ASSIGN_OR_THROW(
auto and_expr,
180 And::Make(std::move(left), std::move(right)));
182 return And::MakeFolded(std::move(and_expr), std::forward<Args>(args)...);
189 const std::shared_ptr<Expression>&
left()
const {
return left_; }
194 const std::shared_ptr<Expression>&
right()
const {
return right_; }
198 std::string ToString()
const override;
200 Result<std::shared_ptr<Expression>> Negate()
const override;
202 bool Equals(
const Expression& other)
const override;
205 And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right);
207 std::shared_ptr<Expression> left_;
208 std::shared_ptr<Expression> right_;
221 static Result<std::unique_ptr<Or>> Make(std::shared_ptr<Expression> left,
222 std::shared_ptr<Expression> right);
233 template <
typename... Args>
234 static Result<std::shared_ptr<Expression>>
MakeFolded(std::shared_ptr<Expression> left,
235 std::shared_ptr<Expression> right,
237 requires std::conjunction_v<std::is_same<Args, std::shared_ptr<Expression>>...>
239 if constexpr (
sizeof...(args) == 0) {
240 if (left->op() == Expression::Operation::kTrue ||
241 right->op() == Expression::Operation::kTrue) {
242 return True::Instance();
245 if (left->op() == Expression::Operation::kFalse) {
249 if (right->op() == Expression::Operation::kFalse) {
253 return Or::Make(std::move(left), std::move(right));
255 ICEBERG_ASSIGN_OR_THROW(
auto or_expr, Or::Make(std::move(left), std::move(right)));
257 return Or::MakeFolded(std::move(or_expr), std::forward<Args>(args)...);
264 const std::shared_ptr<Expression>&
left()
const {
return left_; }
269 const std::shared_ptr<Expression>&
right()
const {
return right_; }
273 std::string ToString()
const override;
275 Result<std::shared_ptr<Expression>> Negate()
const override;
277 bool Equals(
const Expression& other)
const override;
280 Or(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right);
282 std::shared_ptr<Expression> left_;
283 std::shared_ptr<Expression> right_;
295 static Result<std::unique_ptr<Not>> Make(std::shared_ptr<Expression> child);
304 static Result<std::shared_ptr<Expression>> MakeFolded(
305 std::shared_ptr<Expression> child);
310 const std::shared_ptr<Expression>&
child()
const {
return child_; }
314 std::string ToString()
const override;
316 Result<std::shared_ptr<Expression>> Negate()
const override;
318 bool Equals(
const Expression& other)
const override;
321 explicit Not(std::shared_ptr<Expression> child);
323 std::shared_ptr<Expression> child_;
346 virtual Result<std::shared_ptr<B>>
Bind(
const Schema& schema,
347 bool case_sensitive)
const = 0;
350 Result<std::shared_ptr<B>> Bind(
const Schema& schema)
const;
353 virtual std::shared_ptr<class NamedReference>
reference() = 0;
368 virtual std::shared_ptr<class BoundReference>
reference() = 0;
An Expression that represents a logical AND operation between two expressions.
Definition expression.h:139
static Result< std::shared_ptr< Expression > > MakeFolded(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Creates a folded And expression from two sub-expressions.
Definition expression.h:158
Operation op() const override
Returns the operation for an expression node.
Definition expression.h:196
const std::shared_ptr< Expression > & left() const
Returns the left operand of the AND expression.
Definition expression.h:189
const std::shared_ptr< Expression > & right() const
Returns the right operand of the AND expression.
Definition expression.h:194
Interface for bound expressions that can be evaluated.
Definition expression.h:360
virtual std::shared_ptr< class BoundReference > reference()=0
Returns the underlying bound reference for this term.
virtual Result< Literal > Evaluate(const StructLike &data) const =0
Evaluate this expression against a row-based data.
Represents a boolean expression tree.
Definition expression.h:37
std::string ToString() const override
Get a user-readable string representation.
Definition expression.h:85
Operation
Operation types for expressions.
Definition expression.h:40
virtual Operation op() const =0
Returns the operation for an expression node.
virtual bool Equals(const Expression &other) const
Returns whether this expression will accept the same values as another.
Definition expression.h:80
virtual Result< std::shared_ptr< Expression > > Negate() const
Returns the negation of this expression, equivalent to not(this).
Definition expression.h:73
An expression that is always false.
Definition expression.h:116
std::string ToString() const override
Get a user-readable string representation.
Definition expression.h:123
bool Equals(const Expression &other) const override
Returns whether this expression will accept the same values as another.
Definition expression.h:127
Operation op() const override
Returns the operation for an expression node.
Definition expression.h:121
An Expression that represents logical NOT operation.
Definition expression.h:289
const std::shared_ptr< Expression > & child() const
Returns the child expression.
Definition expression.h:310
Operation op() const override
Returns the operation for an expression node.
Definition expression.h:312
An Expression that represents a logical OR operation between two expressions.
Definition expression.h:215
static Result< std::shared_ptr< Expression > > MakeFolded(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Creates a folded Or expression from two sub-expressions.
Definition expression.h:234
const std::shared_ptr< Expression > & left() const
Returns the left operand of the OR expression.
Definition expression.h:264
const std::shared_ptr< Expression > & right() const
Returns the right operand of the OR expression.
Definition expression.h:269
Operation op() const override
Returns the operation for an expression node.
Definition expression.h:271
A schema for a Table.
Definition schema.h:49
An immutable struct-like wrapper.
Definition struct_like.h:62
An Expression that is always true.
Definition expression.h:96
bool Equals(const Expression &other) const override
Returns whether this expression will accept the same values as another.
Definition expression.h:107
Operation op() const override
Returns the operation for an expression node.
Definition expression.h:101
std::string ToString() const override
Get a user-readable string representation.
Definition expression.h:103
Interface for unbound expressions that need schema binding.
Definition expression.h:339
virtual Result< std::shared_ptr< B > > Bind(const Schema &schema, bool case_sensitive) const =0
Bind this expression to a concrete schema.
virtual std::shared_ptr< class NamedReference > reference()=0
Returns the underlying named reference for this unbound term.