@@ -109,14 +109,15 @@ class ICEBERG_EXPORT BoundAggregate : public Aggregate<BoundTerm>, public Bound
109109
110110 virtual Status Update (const StructLike& data) = 0;
111111
112- virtual Status Update (const DataFile& file) {
113- return NotImplemented (" Update(DataFile) not implemented" );
114- }
112+ virtual Status Update (const DataFile& file) = 0;
113+
114+ // / \brief Whether the aggregator is still valid.
115+ virtual bool IsValid () const = 0;
115116
116117 // / \brief Get the result of the aggregation.
117118 // / \return The result of the aggregation.
118119 // / \note It is an undefined behavior to call this method if any previous Update call
119- // / has returned an error.
120+ // / has returned an error or if IsValid() returns false .
120121 virtual Literal GetResult () const = 0;
121122 };
122123
@@ -128,6 +129,11 @@ class ICEBERG_EXPORT BoundAggregate : public Aggregate<BoundTerm>, public Bound
128129
129130 Result<Literal> Evaluate (const StructLike& data) const override = 0;
130131
132+ virtual Result<Literal> Evaluate (const DataFile& file) const = 0;
133+
134+ // / \brief Whether metrics in the data file are sufficient to evaluate.
135+ virtual bool HasValue (const DataFile& file) const = 0;
136+
131137 bool is_bound_aggregate () const override { return true ; }
132138
133139 // / \brief Create a new aggregator for this aggregate.
@@ -142,12 +148,15 @@ class ICEBERG_EXPORT BoundAggregate : public Aggregate<BoundTerm>, public Bound
142148// / \brief Base class for COUNT aggregates.
143149class ICEBERG_EXPORT CountAggregate : public BoundAggregate {
144150 public:
145- Result<Literal> Evaluate (const StructLike& data) const final ;
151+ Result<Literal> Evaluate (const StructLike& data) const override ;
152+ Result<Literal> Evaluate (const DataFile& file) const override ;
146153
147154 std::unique_ptr<Aggregator> NewAggregator () const override ;
148155
149156 // / \brief Count for a single row. Subclasses implement this.
150157 virtual Result<int64_t > CountFor (const StructLike& data) const = 0;
158+ // / \brief Count using metrics from a data file.
159+ virtual Result<int64_t > CountFor (const DataFile& file) const = 0;
151160
152161 protected:
153162 CountAggregate (Expression::Operation op, std::shared_ptr<BoundTerm> term)
@@ -161,6 +170,8 @@ class ICEBERG_EXPORT CountNonNullAggregate : public CountAggregate {
161170 std::shared_ptr<BoundTerm> term);
162171
163172 Result<int64_t > CountFor (const StructLike& data) const override ;
173+ Result<int64_t > CountFor (const DataFile& file) const override ;
174+ bool HasValue (const DataFile& file) const override ;
164175
165176 private:
166177 explicit CountNonNullAggregate (std::shared_ptr<BoundTerm> term);
@@ -173,6 +184,8 @@ class ICEBERG_EXPORT CountNullAggregate : public CountAggregate {
173184 std::shared_ptr<BoundTerm> term);
174185
175186 Result<int64_t > CountFor (const StructLike& data) const override ;
187+ Result<int64_t > CountFor (const DataFile& file) const override ;
188+ bool HasValue (const DataFile& file) const override ;
176189
177190 private:
178191 explicit CountNullAggregate (std::shared_ptr<BoundTerm> term);
@@ -184,6 +197,8 @@ class ICEBERG_EXPORT CountStarAggregate : public CountAggregate {
184197 static Result<std::unique_ptr<CountStarAggregate>> Make ();
185198
186199 Result<int64_t > CountFor (const StructLike& data) const override ;
200+ Result<int64_t > CountFor (const DataFile& file) const override ;
201+ bool HasValue (const DataFile& file) const override ;
187202
188203 private:
189204 CountStarAggregate ();
@@ -192,9 +207,11 @@ class ICEBERG_EXPORT CountStarAggregate : public CountAggregate {
192207// / \brief Bound MAX aggregate.
193208class ICEBERG_EXPORT MaxAggregate : public BoundAggregate {
194209 public:
195- static std::shared_ptr <MaxAggregate> Make (std::shared_ptr<BoundTerm> term);
210+ static Result< std::unique_ptr <MaxAggregate> > Make (std::shared_ptr<BoundTerm> term);
196211
197212 Result<Literal> Evaluate (const StructLike& data) const override ;
213+ Result<Literal> Evaluate (const DataFile& file) const override ;
214+ bool HasValue (const DataFile& file) const override ;
198215
199216 std::unique_ptr<Aggregator> NewAggregator () const override ;
200217
@@ -205,9 +222,11 @@ class ICEBERG_EXPORT MaxAggregate : public BoundAggregate {
205222// / \brief Bound MIN aggregate.
206223class ICEBERG_EXPORT MinAggregate : public BoundAggregate {
207224 public:
208- static std::shared_ptr <MinAggregate> Make (std::shared_ptr<BoundTerm> term);
225+ static Result< std::unique_ptr <MinAggregate> > Make (std::shared_ptr<BoundTerm> term);
209226
210227 Result<Literal> Evaluate (const StructLike& data) const override ;
228+ Result<Literal> Evaluate (const DataFile& file) const override ;
229+ bool HasValue (const DataFile& file) const override ;
211230
212231 std::unique_ptr<Aggregator> NewAggregator () const override ;
213232
@@ -234,11 +253,17 @@ class ICEBERG_EXPORT AggregateEvaluator {
234253 // / \brief Update aggregates with a row.
235254 virtual Status Update (const StructLike& data) = 0;
236255
256+ // / \brief Update aggregates using data file metrics.
257+ virtual Status Update (const DataFile& file) = 0;
258+
237259 // / \brief Final aggregated value.
238260 virtual Result<std::span<const Literal>> GetResults () const = 0;
239261
240262 // / \brief Convenience accessor when only one aggregate is evaluated.
241263 virtual Result<Literal> GetResult () const = 0;
264+
265+ // / \brief Whether all aggregators are still valid (metrics present).
266+ virtual bool AllAggregatorsValid () const = 0;
242267};
243268
244269} // namespace iceberg
0 commit comments