45 const std::shared_ptr<T>& term()
const {
return term_; }
51 : operation_(op), term_(
std::move(term)) {}
54 return op == Expression::Operation::kCount ||
55 op == Expression::Operation::kCountNull ||
56 op == Expression::Operation::kCountStar || op == Expression::Operation::kMax ||
57 op == Expression::Operation::kMin;
60 Expression::Operation operation_;
61 std::shared_ptr<T> term_;
70 bool is_unbound_aggregate()
const override {
return true; }
83 std::shared_ptr<const NamedReference>
reference()
const override {
84 return BASE::term() ? BASE::term()->reference() :
nullptr;
88 bool case_sensitive)
const override;
93 ICEBERG_DCHECK(BASE::IsSupportedOp(op),
"Unexpected aggregate operation");
94 ICEBERG_DCHECK(op == Expression::Operation::kCountStar || BASE::term() !=
nullptr,
95 "Aggregate term cannot be null except for COUNT(*)");
110 virtual Status Update(
const StructLike& data) = 0;
112 virtual Status Update(
const DataFile& file) = 0;
125 ICEBERG_DCHECK(term() !=
nullptr || op() == Expression::Operation::kCountStar,
126 "Bound aggregate term should not be null except for COUNT(*)");
127 return term() ? term()->reference() :
nullptr;
137 bool is_bound_aggregate()
const override {
return true; }
170 std::shared_ptr<BoundTerm> term);
184 std::shared_ptr<BoundTerm> term);
245 std::shared_ptr<BoundAggregate> aggregate);
251 std::vector<std::shared_ptr<BoundAggregate>> aggregates);
Evaluates bound aggregates over StructLike data.
Definition aggregate.h:238
virtual Status Update(const DataFile &file)=0
Update aggregates using data file metrics.
static Result< std::unique_ptr< AggregateEvaluator > > Make(std::vector< std::shared_ptr< BoundAggregate > > aggregates)
Create an evaluator for multiple bound aggregates.
static Result< std::unique_ptr< AggregateEvaluator > > Make(std::shared_ptr< BoundAggregate > aggregate)
Create an evaluator for a single bound aggregate.
virtual Result< Literal > GetResult() const =0
Convenience accessor when only one aggregate is evaluated.
virtual Status Update(const StructLike &data)=0
Update aggregates with a row.
virtual Result< std::span< const Literal > > GetResults() const =0
Final aggregated value.
virtual bool AllAggregatorsValid() const =0
Whether all aggregators are still valid (metrics present).
Base aggregate holding an operation and a term.
Definition aggregate.h:39
Expression::Operation op() const override
Returns the operation for an expression node.
Definition aggregate.h:43
std::string ToString() const override
Get a user-readable string representation.
Base class for aggregators.
Definition aggregate.h:106
virtual bool IsValid() const =0
Whether the aggregator is still valid.
virtual Literal GetResult() const =0
Get the result of the aggregation.
Base class for bound aggregates.
Definition aggregate.h:100
virtual std::unique_ptr< Aggregator > NewAggregator() const =0
Create a new aggregator for this aggregate.
virtual bool HasValue(const DataFile &file) const =0
Whether metrics in the data file are sufficient to evaluate.
std::shared_ptr< BoundReference > reference() override
Returns the underlying bound reference for this term.
Definition aggregate.h:124
Result< Literal > Evaluate(const StructLike &data) const override=0
Evaluate this expression against a row-based data.
Base class for bound terms.
Definition term.h:64
Interface for bound expressions that can be evaluated.
Definition expression.h:360
Base class for COUNT aggregates.
Definition aggregate.h:149
virtual Result< int64_t > CountFor(const StructLike &data) const =0
Count for a single row. Subclasses implement this.
Result< Literal > Evaluate(const StructLike &data) const override
Evaluate this expression against a row-based data.
virtual Result< int64_t > CountFor(const DataFile &file) const =0
Count using metrics from a data file.
std::unique_ptr< Aggregator > NewAggregator() const override
Create a new aggregator for this aggregate.
COUNT(term) aggregate.
Definition aggregate.h:167
Result< int64_t > CountFor(const DataFile &file) const override
Count using metrics from a data file.
Result< int64_t > CountFor(const StructLike &data) const override
Count for a single row. Subclasses implement this.
bool HasValue(const DataFile &file) const override
Whether metrics in the data file are sufficient to evaluate.
COUNT_NULL(term) aggregate.
Definition aggregate.h:181
Result< int64_t > CountFor(const DataFile &file) const override
Count using metrics from a data file.
bool HasValue(const DataFile &file) const override
Whether metrics in the data file are sufficient to evaluate.
Result< int64_t > CountFor(const StructLike &data) const override
Count for a single row. Subclasses implement this.
COUNT(*) aggregate.
Definition aggregate.h:195
Result< int64_t > CountFor(const StructLike &data) const override
Count for a single row. Subclasses implement this.
Result< int64_t > CountFor(const DataFile &file) const override
Count using metrics from a data file.
bool HasValue(const DataFile &file) const override
Whether metrics in the data file are sufficient to evaluate.
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:42
Bound MAX aggregate.
Definition aggregate.h:208
bool HasValue(const DataFile &file) const override
Whether metrics in the data file are sufficient to evaluate.
std::unique_ptr< Aggregator > NewAggregator() const override
Create a new aggregator for this aggregate.
Result< Literal > Evaluate(const StructLike &data) const override
Evaluate this expression against a row-based data.
Bound MIN aggregate.
Definition aggregate.h:223
std::unique_ptr< Aggregator > NewAggregator() const override
Create a new aggregator for this aggregate.
bool HasValue(const DataFile &file) const override
Whether metrics in the data file are sufficient to evaluate.
Result< Literal > Evaluate(const StructLike &data) const override
Evaluate this expression against a row-based data.
A schema for a Table.
Definition schema.h:51
An immutable struct-like wrapper.
Definition struct_like.h:62
Template for unbound aggregates that carry a term and operation.
Definition aggregate.h:76
Result< std::shared_ptr< Expression > > Bind(const Schema &schema, bool case_sensitive) const override
Bind this expression to a concrete schema.
std::shared_ptr< const NamedReference > reference() const override
Returns the underlying named reference for this unbound term.
Definition aggregate.h:83
Base class for unbound aggregates.
Definition aggregate.h:66
Base class for unbound terms.
Definition term.h:56
Interface for unbound expressions that need schema binding.
Definition expression.h:339
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:62