Skip to content

Commit dd5874b

Browse files
committed
Follow Reviews
1 parent 6378ce5 commit dd5874b

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/iceberg/expression/aggregate.cc

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "iceberg/expression/aggregate.h"
2121

22+
#include <algorithm>
2223
#include <format>
2324
#include <map>
2425
#include <optional>
@@ -231,14 +232,6 @@ class MinAggregator : public BoundAggregate::Aggregator {
231232
bool valid_ = true;
232233
};
233234

234-
bool HasMapKey(const std::map<int32_t, int64_t>& map, int32_t key) {
235-
return map.contains(key);
236-
}
237-
238-
bool HasMapKey(const std::map<int32_t, std::vector<uint8_t>>& map, int32_t key) {
239-
return map.contains(key);
240-
}
241-
242235
template <typename T>
243236
std::optional<T> GetMapValue(const std::map<int32_t, T>& map, int32_t key) {
244237
auto iter = map.find(key);
@@ -282,12 +275,11 @@ std::string Aggregate<T>::ToString() const {
282275
// -------------------- CountAggregate --------------------
283276

284277
Result<Literal> CountAggregate::Evaluate(const StructLike& data) const {
285-
return CountFor(data).transform([](int64_t count) { return Literal::Long(count); });
278+
return CountFor(data).transform(Literal::Long);
286279
}
287280

288281
Result<Literal> CountAggregate::Evaluate(const DataFile& file) const {
289-
ICEBERG_ASSIGN_OR_RAISE(auto count, CountFor(file));
290-
return Literal::Long(count);
282+
return CountFor(file).transform(Literal::Long);
291283
}
292284

293285
std::unique_ptr<BoundAggregate::Aggregator> CountAggregate::NewAggregator() const {
@@ -323,8 +315,8 @@ Result<int64_t> CountNonNullAggregate::CountFor(const DataFile& file) const {
323315

324316
bool CountNonNullAggregate::HasValue(const DataFile& file) const {
325317
auto field_id = GetFieldId(term());
326-
return HasMapKey(file.value_counts, field_id) &&
327-
HasMapKey(file.null_value_counts, field_id);
318+
return file.value_counts.contains(field_id) &&
319+
file.null_value_counts.contains(field_id);
328320
}
329321

330322
CountNullAggregate::CountNullAggregate(std::shared_ptr<BoundTerm> term)
@@ -352,7 +344,7 @@ Result<int64_t> CountNullAggregate::CountFor(const DataFile& file) const {
352344
}
353345

354346
bool CountNullAggregate::HasValue(const DataFile& file) const {
355-
return HasMapKey(file.null_value_counts, GetFieldId(term()));
347+
return file.null_value_counts.contains(GetFieldId(term()));
356348
}
357349

358350
CountStarAggregate::CountStarAggregate()
@@ -400,7 +392,7 @@ std::unique_ptr<BoundAggregate::Aggregator> MaxAggregate::NewAggregator() const
400392

401393
bool MaxAggregate::HasValue(const DataFile& file) const {
402394
auto field_id = GetFieldId(term());
403-
bool has_bound = HasMapKey(file.upper_bounds, field_id);
395+
bool has_bound = file.upper_bounds.contains(field_id);
404396
auto value_count = GetMapValue(file.value_counts, field_id);
405397
auto null_count = GetMapValue(file.null_value_counts, field_id);
406398
bool all_null = value_count.has_value() && *value_count > 0 && null_count.has_value() &&
@@ -431,7 +423,7 @@ std::unique_ptr<BoundAggregate::Aggregator> MinAggregate::NewAggregator() const
431423

432424
bool MinAggregate::HasValue(const DataFile& file) const {
433425
auto field_id = GetFieldId(term());
434-
bool has_bound = HasMapKey(file.lower_bounds, field_id);
426+
bool has_bound = file.lower_bounds.contains(field_id);
435427
auto value_count = GetMapValue(file.value_counts, field_id);
436428
auto null_count = GetMapValue(file.null_value_counts, field_id);
437429
bool all_null = value_count.has_value() && *value_count > 0 && null_count.has_value() &&
@@ -534,12 +526,7 @@ class AggregateEvaluatorImpl : public AggregateEvaluator {
534526
}
535527

536528
bool AllAggregatorsValid() const override {
537-
for (const auto& aggregator : aggregators_) {
538-
if (!aggregator->IsValid()) {
539-
return false;
540-
}
541-
}
542-
return true;
529+
return std::ranges::all_of(aggregators_, &BoundAggregate::Aggregator::IsValid);
543530
}
544531

545532
private:

src/iceberg/expression/aggregate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class ICEBERG_EXPORT MaxAggregate : public BoundAggregate {
213213
static std::shared_ptr<MaxAggregate> Make(std::shared_ptr<BoundTerm> term);
214214

215215
Result<Literal> Evaluate(const StructLike& data) const override;
216-
Result<Literal> Evaluate(const DataFile& file) const override;
216+
Result<Literal> Evaluate(const DataFile& file) const final;
217217

218218
std::unique_ptr<Aggregator> NewAggregator() const override;
219219

@@ -229,7 +229,7 @@ class ICEBERG_EXPORT MinAggregate : public BoundAggregate {
229229
static std::shared_ptr<MinAggregate> Make(std::shared_ptr<BoundTerm> term);
230230

231231
Result<Literal> Evaluate(const StructLike& data) const override;
232-
Result<Literal> Evaluate(const DataFile& file) const override;
232+
Result<Literal> Evaluate(const DataFile& file) const final;
233233

234234
std::unique_ptr<Aggregator> NewAggregator() const override;
235235

0 commit comments

Comments
 (0)