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<NamedReference>
reference()
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);
129 return BASE::term()->reference();
132 std::string ToString()
const override;
134 Result<std::shared_ptr<Expression>> Bind(
const Schema& schema,
135 bool case_sensitive)
const override;
137 Result<std::shared_ptr<Expression>> Negate()
const override;
141 std::span<const Literal>
literals()
const override {
return values_; }
148 std::vector<Literal> values);
150 Result<std::shared_ptr<Expression>> BindUnaryOperation(
151 std::shared_ptr<B> bound_term)
const;
152 Result<std::shared_ptr<Expression>> BindLiteralOperation(
153 std::shared_ptr<B> bound_term)
const;
154 Result<std::shared_ptr<Expression>> BindInOperation(
155 std::shared_ptr<B> bound_term)
const;
158 std::vector<Literal> values_;
170 std::shared_ptr<BoundReference>
reference()
override {
return term_->reference(); }
172 Result<Literal> Evaluate(
const StructLike& data)
const override;
174 bool is_bound_predicate()
const override {
return true; }
182 enum class Kind : int8_t {
206 static Result<std::unique_ptr<BoundUnaryPredicate>> Make(
211 Result<bool> Test(
const Literal& value)
const override;
213 Kind
kind()
const override {
return Kind::kUnary; }
215 std::string ToString()
const override;
217 Result<std::shared_ptr<Expression>> Negate()
const override;
219 bool Equals(
const Expression& other)
const override;
234 static Result<std::unique_ptr<BoundLiteralPredicate>> Make(
242 Result<bool> Test(
const Literal& value)
const override;
244 Kind
kind()
const override {
return Kind::kLiteral; }
246 std::string ToString()
const override;
248 Result<std::shared_ptr<Expression>> Negate()
const override;
250 bool Equals(
const Expression& other)
const override;
262 using LiteralSet = std::unordered_set<Literal, LiteralHash>;
270 static Result<std::unique_ptr<BoundSetPredicate>> Make(
272 std::span<const Literal> literals);
281 std::shared_ptr<BoundTerm> term,
282 LiteralSet value_set);
289 Result<bool> Test(
const Literal& value)
const override;
291 Kind
kind()
const override {
return Kind::kSet; }
293 std::string ToString()
const override;
295 Result<std::shared_ptr<Expression>> Negate()
const override;
297 bool Equals(
const Expression& other)
const override;
301 std::span<const Literal> literals);
304 LiteralSet value_set);
306 LiteralSet value_set_;
Bound literal predicate (comparison against a single value).
Definition predicate.h:226
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:244
const Literal & literal() const
Returns the literal being compared against.
Definition predicate.h:240
Bound predicates contain bound terms and can be evaluated.
Definition predicate.h:162
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:170
Bound set predicate (membership testing against a set of values).
Definition predicate.h:260
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:291
const LiteralSet & literal_set() const
Returns the set of literals to test against.
Definition predicate.h:287
Base class for bound terms.
Definition term.h:64
Bound unary predicate (null, not-null, etc.).
Definition predicate.h:199
Kind kind() const override
Returns the kind of this bound predicate.
Definition predicate.h:213
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:49
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:139
std::span< const Literal > literals() const override
Returns the literals of this predicate.
Definition predicate.h:141
std::shared_ptr< NamedReference > reference() override
Returns the reference of this UnboundPredicate.
Definition predicate.h:128
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.
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.
std::shared_ptr< NamedReference > reference() override=0
Returns the reference of this UnboundPredicate.
Interface for unbound expressions that need schema binding.
Definition expression.h:339