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<NamedReference>
reference()
override {
return shared_from_this(); }
118 std::string ToString()
const override;
120 Kind
kind()
const override {
return Kind::kReference; }
125 std::string field_name_;
132 public std::enable_shared_from_this<BoundReference> {
137 static Result<std::unique_ptr<BoundReference>> Make(
138 SchemaField field, std::unique_ptr<StructLikeAccessor> accessor);
142 const SchemaField& field()
const {
return field_; }
144 std::string_view
name()
const override {
return field_.name(); }
146 std::string ToString()
const override;
148 Result<Literal> Evaluate(
const StructLike& data)
const override;
150 std::shared_ptr<BoundReference>
reference()
override {
return shared_from_this(); }
152 std::shared_ptr<Type>
type()
const override {
return field_.type(); }
154 int32_t field_id()
const {
return field_.field_id(); }
158 bool Equals(
const BoundTerm& other)
const override;
160 Kind
kind()
const override {
return Kind::kReference; }
165 BoundReference(SchemaField field, std::unique_ptr<StructLikeAccessor> accessor);
168 std::unique_ptr<StructLikeAccessor> accessor_;
178 static Result<std::unique_ptr<UnboundTransform>> Make(
179 std::shared_ptr<NamedReference> ref, std::shared_ptr<Transform> transform);
183 std::string ToString()
const override;
185 Result<std::shared_ptr<BoundTransform>> Bind(
const Schema& schema,
186 bool case_sensitive)
const override;
188 std::shared_ptr<NamedReference>
reference()
override {
return ref_; }
190 const std::shared_ptr<Transform>& transform()
const {
return transform_; }
192 Kind
kind()
const override {
return Kind::kTransform; }
196 std::shared_ptr<Transform> transform);
198 std::shared_ptr<NamedReference> ref_;
199 std::shared_ptr<Transform> transform_;
210 static Result<std::unique_ptr<BoundTransform>> Make(
211 std::shared_ptr<BoundReference> ref, std::shared_ptr<Transform> transform,
212 std::shared_ptr<TransformFunction> transform_func);
216 std::string ToString()
const override;
218 Result<Literal> Evaluate(
const StructLike& data)
const override;
220 std::shared_ptr<BoundReference>
reference()
override {
return ref_; }
222 std::shared_ptr<Type> type()
const override;
224 bool MayProduceNull()
const override;
226 bool Equals(
const BoundTerm& other)
const override;
228 const std::shared_ptr<Transform>& transform()
const {
return transform_; }
230 Kind
kind()
const override {
return Kind::kTransform; }
234 std::shared_ptr<Transform> transform,
235 std::shared_ptr<TransformFunction> transform_func);
237 std::shared_ptr<BoundReference> ref_;
238 std::shared_ptr<Transform> transform_;
239 std::shared_ptr<TransformFunction> transform_func_;
A reference to a bound field.
Definition term.h:132
std::string_view name() const override
Returns the name of the referenced field.
Definition term.h:144
bool MayProduceNull() const override
Returns whether this term may produce null values.
Definition term.h:156
std::shared_ptr< BoundReference > reference() override
Returns the underlying bound reference for this term.
Definition term.h:150
Kind kind() const override
Returns the kind of this term.
Definition term.h:160
std::shared_ptr< Type > type() const override
Returns the type produced by this term.
Definition term.h:152
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< NamedReference > reference() 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:120
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:49
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