25#include <unordered_set>
28#include "iceberg/expression/literal.h"
30#include "iceberg/iceberg_export.h"
45 const std::shared_ptr<T>&
term()
const {
return term_; }
55 std::shared_ptr<T> term_;
68 std::shared_ptr<const NamedReference>
reference()
const override = 0;
71 Result<std::shared_ptr<Expression>>
Bind(
const Schema& schema,
72 bool case_sensitive)
const override = 0;
75 Result<std::shared_ptr<Expression>>
Negate()
const override = 0;
77 bool is_unbound_predicate()
const override {
return true; }
83 virtual std::span<const Literal>
literals()
const = 0;
96 using BASE = Predicate<UnboundTerm<B>>;
104 static Result<std::unique_ptr<UnboundPredicateImpl<B>>> Make(
113 static Result<std::unique_ptr<UnboundPredicateImpl<B>>> Make(
122 static Result<std::unique_ptr<UnboundPredicateImpl<B>>> Make(
124 std::vector<Literal> values);
128 std::shared_ptr<const NamedReference>
reference()
const override {
129 return BASE::term()->reference();
132 std::string ToString()
const override;
134 bool Equals(
const Expression& other)
const override;
136 Result<std::shared_ptr<Expression>> Bind(
const Schema& schema,
137 bool case_sensitive)
const override;
139 Result<std::shared_ptr<Expression>> Negate()
const override;
143 std::span<const Literal>
literals()
const override {
return values_; }
150 std::vector<Literal> values);
152 Result<std::shared_ptr<Expression>> BindUnaryOperation(
153 std::shared_ptr<B> bound_term)
const;
154 Result<std::shared_ptr<Expression>> BindLiteralOperation(
155 std::shared_ptr<B> bound_term)
const;
156 Result<std::shared_ptr<Expression>> BindInOperation(
157 std::shared_ptr<B> bound_term)
const;
160 std::vector<Literal> values_;
172 std::shared_ptr<BoundReference>
reference()
override {
return term_->reference(); }
174 Result<Literal> Evaluate(
const StructLike& data)
const override;
176 bool is_bound_predicate()
const override {
return true; }
184 enum class Kind : int8_t {
208 static Result<std::unique_ptr<BoundUnaryPredicate>> Make(
213 Result<bool> Test(
const Literal& value)
const override;
215 Kind
kind()
const override {
return Kind::kUnary; }
217 std::string ToString()
const override;
219 Result<std::shared_ptr<Expression>> Negate()
const override;
221 bool Equals(
const Expression& other)
const override;
236 static Result<std::unique_ptr<BoundLiteralPredicate>> Make(
244 Result<bool> Test(
const Literal& value)
const override;
246 Kind
kind()
const override {
return Kind::kLiteral; }
248 std::string ToString()
const override;
250 Result<std::shared_ptr<Expression>> Negate()
const override;
252 bool Equals(
const Expression& other)
const override;
264 using LiteralSet = std::unordered_set<Literal, LiteralHash>;
272 static Result<std::unique_ptr<BoundSetPredicate>> Make(
274 std::span<const Literal> literals);
283 std::shared_ptr<BoundTerm> term,
284 LiteralSet value_set);
291 Result<bool> Test(
const Literal& value)
const override;
293 Kind
kind()
const override {
return Kind::kSet; }
295 std::string ToString()
const override;
297 Result<std::shared_ptr<Expression>> Negate()
const override;
299 bool Equals(
const Expression& other)
const override;
303 std::span<const Literal> literals);
306 LiteralSet value_set);
308 LiteralSet value_set_;
Bound literal predicate (comparison against a single value).
Definition predicate.h:228
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:246
const Literal & literal() const
Returns the literal being compared against.
Definition predicate.h:242
Bound predicates contain bound terms and can be evaluated.
Definition predicate.h:164
virtual Kind kind() const =0
Returns the kind of this bound predicate.
virtual Result< bool > Test(const Literal &value) const =0
Test a value against this predicate.
std::shared_ptr< BoundReference > reference() override
Returns the underlying bound reference for this term.
Definition predicate.h:172
Bound set predicate (membership testing against a set of values).
Definition predicate.h:262
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:293
const LiteralSet & literal_set() const
Returns the set of literals to test against.
Definition predicate.h:289
Base class for bound terms.
Definition term.h:64
Bound unary predicate (null, not-null, etc.).
Definition predicate.h:201
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:215
Interface for bound expressions that can be evaluated.
Definition expression.h:360
Represents a boolean expression tree.
Definition expression.h:37
Operation
Operation types for expressions.
Definition expression.h:40
Literal is a literal value that is associated with a primitive type.
Definition literal.h:39
A predicate is a boolean expression that tests a term against some criteria.
Definition predicate.h:38
Expression::Operation op() const override
Returns the operation for an expression node.
Definition predicate.h:42
const std::shared_ptr< T > & term() const
Returns the term this predicate tests.
Definition predicate.h:45
A schema for a Table.
Definition schema.h:51
An immutable struct-like wrapper.
Definition struct_like.h:62
A term is an expression node that produces a typed value when evaluated.
Definition term.h:38
Unbound predicates contain unbound terms and must be bound to a concrete schema before they can be ev...
Definition predicate.h:95
const Term & unbound_term() const override
Returns the term of this predicate as a base Term reference.
Definition predicate.h:141
std::shared_ptr< const NamedReference > reference() const override
Returns the reference of this UnboundPredicate.
Definition predicate.h:128
std::span< const Literal > literals() const override
Returns the literals of this predicate.
Definition predicate.h:143
Non-template base class for all UnboundPredicate instances.
Definition predicate.h:63
Result< std::shared_ptr< Expression > > Bind(const Schema &schema, bool case_sensitive) const override=0
Bind this UnboundPredicate.
Result< std::shared_ptr< Expression > > Negate() const override=0
Negate this UnboundPredicate.
std::shared_ptr< const NamedReference > reference() const override=0
Returns the reference of this UnboundPredicate.
virtual std::span< const Literal > literals() const =0
Returns the literals of this predicate.
virtual const Term & unbound_term() const =0
Returns the term of this predicate as a base Term reference.
Interface for unbound expressions that need schema binding.
Definition expression.h:339