31#include "iceberg/expression/literal.h"
40 enum class Kind : uint8_t { kReference, kTransform, kExtract };
43 virtual Kind
kind()
const = 0;
69 virtual std::shared_ptr<Type>
type()
const = 0;
83 return lhs.Equals(rhs);
95 virtual std::string_view
name()
const = 0;
102 public std::enable_shared_from_this<NamedReference> {
107 static Result<std::unique_ptr<NamedReference>> Make(std::string field_name);
111 std::string_view
name()
const override {
return field_name_; }
113 Result<std::shared_ptr<BoundReference>> Bind(
const Schema& schema,
114 bool case_sensitive)
const override;
116 std::shared_ptr<const NamedReference>
reference()
const override {
117 return shared_from_this();
120 std::string ToString()
const override;
122 Kind
kind()
const override {
return Kind::kReference; }
127 std::string field_name_;
134 public std::enable_shared_from_this<BoundReference> {
139 static Result<std::unique_ptr<BoundReference>> Make(
140 SchemaField field, std::unique_ptr<StructLikeAccessor> accessor);
144 const SchemaField& field()
const {
return field_; }
146 std::string_view
name()
const override {
return field_.name(); }
148 std::string ToString()
const override;
150 Result<Literal> Evaluate(
const StructLike& data)
const override;
152 std::shared_ptr<BoundReference>
reference()
override {
return shared_from_this(); }
154 std::shared_ptr<Type>
type()
const override {
return field_.type(); }
156 int32_t field_id()
const {
return field_.field_id(); }
160 bool Equals(
const BoundTerm& other)
const override;
162 Kind
kind()
const override {
return Kind::kReference; }
167 BoundReference(SchemaField field, std::unique_ptr<StructLikeAccessor> accessor);
170 std::unique_ptr<StructLikeAccessor> accessor_;
180 static Result<std::unique_ptr<UnboundTransform>> Make(
181 std::shared_ptr<NamedReference> ref, std::shared_ptr<Transform> transform);
185 std::string ToString()
const override;
187 Result<std::shared_ptr<BoundTransform>> Bind(
const Schema& schema,
188 bool case_sensitive)
const override;
190 std::shared_ptr<const NamedReference>
reference()
const override {
return ref_; }
192 const std::shared_ptr<Transform>& transform()
const {
return transform_; }
194 Kind
kind()
const override {
return Kind::kTransform; }
198 std::shared_ptr<Transform> transform);
200 std::shared_ptr<NamedReference> ref_;
201 std::shared_ptr<Transform> transform_;
212 static Result<std::unique_ptr<BoundTransform>> Make(
213 std::shared_ptr<BoundReference> ref, std::shared_ptr<Transform> transform,
214 std::shared_ptr<TransformFunction> transform_func);
218 std::string ToString()
const override;
220 Result<Literal> Evaluate(
const StructLike& data)
const override;
222 std::shared_ptr<BoundReference>
reference()
override {
return ref_; }
224 std::shared_ptr<Type> type()
const override;
226 bool MayProduceNull()
const override;
228 bool Equals(
const BoundTerm& other)
const override;
230 const std::shared_ptr<Transform>& transform()
const {
return transform_; }
232 Kind
kind()
const override {
return Kind::kTransform; }
236 std::shared_ptr<Transform> transform,
237 std::shared_ptr<TransformFunction> transform_func);
239 std::shared_ptr<BoundReference> ref_;
240 std::shared_ptr<Transform> transform_;
241 std::shared_ptr<TransformFunction> transform_func_;
A reference to a bound field.
Definition term.h:134
std::string_view name() const override
Returns the name of the referenced field.
Definition term.h:146
bool MayProduceNull() const override
Returns whether this term may produce null values.
Definition term.h:158
std::shared_ptr< BoundReference > reference() override
Returns the underlying bound reference for this term.
Definition term.h:152
Kind kind() const override
Returns the kind of this term.
Definition term.h:162
std::shared_ptr< Type > type() const override
Returns the type produced by this term.
Definition term.h:154
Base class for bound terms.
Definition term.h:64
virtual std::shared_ptr< Type > type() const =0
Returns the type produced by this term.
bool is_unbound() const override
Returns whether this term is unbound.
Definition term.h:86
virtual bool Equals(const BoundTerm &other) const =0
Returns whether this term is equivalent to another.
virtual bool MayProduceNull() const =0
Returns whether this term may produce null values.
Interface for bound expressions that can be evaluated.
Definition expression.h:360
A reference to an unbound named field.
Definition term.h:102
std::string_view name() const override
Returns the name of the referenced field.
Definition term.h:111
std::shared_ptr< const NamedReference > reference() const override
Returns the underlying named reference for this unbound term.
Definition term.h:116
Kind kind() const override
Returns the kind of this term.
Definition term.h:122
A reference represents a named field in an expression.
Definition term.h:90
virtual std::string_view name() const =0
Returns the name of the referenced field.
A type combined with a name.
Definition schema_field.h:39
A schema for a Table.
Definition schema.h:51
An accessor for a struct-like object.
Definition struct_like.h:105
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
virtual bool is_unbound() const =0
Returns whether this term is unbound.
virtual Kind kind() const =0
Returns the kind of this term.
Base class for unbound terms.
Definition term.h:56
bool is_unbound() const override
Returns whether this term is unbound.
Definition term.h:60
Interface for unbound expressions that need schema binding.
Definition expression.h:339