SuKi2cn commented on code in PR #373:
URL: https://github.com/apache/iceberg-cpp/pull/373#discussion_r2587598524
##########
src/iceberg/test/aggregate_test.cc:
##########
@@ -236,4 +237,239 @@ TEST(AggregateTest, MultipleAggregatesInEvaluator) {
EXPECT_EQ(std::get<int64_t>(results[4].value()), 4); // count_star
}
+TEST(AggregateTest, AggregatesFromDataFileMetrics) {
+ Schema schema({SchemaField::MakeOptional(1, "id", int32()),
+ SchemaField::MakeOptional(2, "value", int32())});
+
+ auto count_bound = BindAggregate(schema, Expressions::Count("id"));
+ auto count_null_bound = BindAggregate(schema, Expressions::CountNull("id"));
+ auto count_star_bound = BindAggregate(schema, Expressions::CountStar());
+ auto max_bound = BindAggregate(schema, Expressions::Max("value"));
+ auto min_bound = BindAggregate(schema, Expressions::Min("value"));
+
+ std::vector<std::shared_ptr<BoundAggregate>> aggregates{
+ count_bound, count_null_bound, count_star_bound, max_bound, min_bound};
+ ICEBERG_UNWRAP_OR_FAIL(auto evaluator, AggregateEvaluator::Make(aggregates));
+
+ DataFile file;
+ file.record_count = 10;
+ file.value_counts.emplace(1, 10);
+ file.null_value_counts.emplace(1, 2);
+ file.value_counts.emplace(2, 10);
+ file.null_value_counts.emplace(2, 0);
+ ICEBERG_UNWRAP_OR_FAIL(auto lower, Literal::Int(5).Serialize());
+ ICEBERG_UNWRAP_OR_FAIL(auto upper, Literal::Int(50).Serialize());
+ file.lower_bounds.emplace(2, lower);
+ file.upper_bounds.emplace(2, upper);
+
+ ASSERT_TRUE(evaluator->Update(file).has_value());
+
+ ICEBERG_UNWRAP_OR_FAIL(auto results, evaluator->GetResults());
+ ASSERT_EQ(results.size(), aggregates.size());
+ EXPECT_EQ(std::get<int64_t>(results[0].value()), 8); // count(id) = 10 - 2
+ EXPECT_EQ(std::get<int64_t>(results[1].value()), 2); // count_null(id)
+ EXPECT_EQ(std::get<int64_t>(results[2].value()), 10); // count_star
+ EXPECT_EQ(std::get<int32_t>(results[3].value()), 50); // max(value)
+ EXPECT_EQ(std::get<int32_t>(results[4].value()), 5); // min(value)
+}
+
+TEST(AggregateTest, AggregatesFromDataFileMissingMetricsReturnNull) {
+ Schema schema({SchemaField::MakeOptional(1, "id", int32()),
+ SchemaField::MakeOptional(2, "value", int32())});
+
+ auto count_bound = BindAggregate(schema, Expressions::Count("id"));
+ auto count_null_bound = BindAggregate(schema, Expressions::CountNull("id"));
+ auto count_star_bound = BindAggregate(schema, Expressions::CountStar());
+ auto max_bound = BindAggregate(schema, Expressions::Max("value"));
+ auto min_bound = BindAggregate(schema, Expressions::Min("value"));
+
+ std::vector<std::shared_ptr<BoundAggregate>> aggregates{
+ count_bound, count_null_bound, count_star_bound, max_bound, min_bound};
+ ICEBERG_UNWRAP_OR_FAIL(auto evaluator, AggregateEvaluator::Make(aggregates));
+
+ DataFile file;
+ file.record_count = -1; // missing/invalid
+
+ ASSERT_TRUE(evaluator->Update(file).has_value());
+
+ ICEBERG_UNWRAP_OR_FAIL(auto results, evaluator->GetResults());
+ ASSERT_EQ(results.size(), aggregates.size());
+ for (const auto& literal : results) {
+ EXPECT_TRUE(literal.IsNull());
+ }
+}
+
+TEST(AggregateTest, AggregatesFromDataFileWithTransform) {
+ Schema schema({SchemaField::MakeOptional(1, "id", int32())});
+
+ auto truncate_id = Expressions::Truncate("id", 10);
+ auto max_bound = BindAggregate(schema, Expressions::Max(truncate_id));
+ auto min_bound = BindAggregate(schema, Expressions::Min(truncate_id));
+
+ std::vector<std::shared_ptr<BoundAggregate>> aggregates{max_bound,
min_bound};
+ ICEBERG_UNWRAP_OR_FAIL(auto evaluator, AggregateEvaluator::Make(aggregates));
+
+ DataFile file;
+ file.record_count = 5;
+ file.value_counts.emplace(1, 5);
+ file.null_value_counts.emplace(1, 0);
+ ICEBERG_UNWRAP_OR_FAIL(auto lower, Literal::Int(5).Serialize());
+ ICEBERG_UNWRAP_OR_FAIL(auto upper, Literal::Int(23).Serialize());
+ file.lower_bounds.emplace(1, lower);
+ file.upper_bounds.emplace(1, upper);
+
+ ASSERT_TRUE(evaluator->Update(file).has_value());
+
+ ICEBERG_UNWRAP_OR_FAIL(auto results, evaluator->GetResults());
+ ASSERT_EQ(results.size(), aggregates.size());
+ // Truncate width 10: max(truncate(23)) -> 20, min(truncate(5)) -> 0
+ EXPECT_EQ(std::get<int32_t>(results[0].value()), 20);
+ EXPECT_EQ(std::get<int32_t>(results[1].value()), 0);
+ EXPECT_TRUE(evaluator->AllAggregatorsValid());
+}
+
+TEST(AggregateTest, DataFileAggregatorParityWithJava) {
Review Comment:
> modify this?
Yep. It's way better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]