HeartLinked commented on code in PR #357: URL: https://github.com/apache/iceberg-cpp/pull/357#discussion_r2572105075
########## src/iceberg/test/inclusive_metrics_evaluator_test.cc: ########## @@ -0,0 +1,385 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "iceberg/expression/inclusive_metrics_evaluator.h" + +#include <gtest/gtest.h> + +#include "iceberg/expression/binder.h" +#include "iceberg/expression/expressions.h" +#include "iceberg/manifest_entry.h" +#include "iceberg/schema.h" +#include "iceberg/test/matchers.h" +#include "iceberg/type.h" + +namespace iceberg { + +namespace { +static const bool ROWS_MIGHT_MATCH = true; +static const bool ROWS_CANNOT_MATCH = false; +} // namespace +using TestVariant = std::variant<bool, int32_t, int64_t, double, std::string>; + +class InclusiveMetricsEvaluatorTest : public ::testing::Test { + protected: + void SetUp() override { + schema_ = std::make_shared<Schema>( + std::vector<SchemaField>{ + SchemaField::MakeRequired(1, "id", int64()), + SchemaField::MakeOptional(2, "name", string()), + SchemaField::MakeRequired(3, "age", int32()), + SchemaField::MakeOptional(4, "salary", float64()), + SchemaField::MakeRequired(5, "active", boolean()), + SchemaField::MakeRequired(6, "date", string()), + }, + /*schema_id=*/0); + } + + Result<std::shared_ptr<Expression>> Bind(const std::shared_ptr<Expression>& expr, + bool case_sensitive = true) { + return Binder::Bind(*schema_, expr, case_sensitive); + } + + std::shared_ptr<DataFile> PrepareDataFile( + const std::string& partition, int64_t record_count, int64_t file_size_in_bytes, + const std::map<std::string, TestVariant>& lower_bounds, + const std::map<std::string, TestVariant>& upper_bounds, + const std::map<int32_t, int64_t>& value_counts = {}, + const std::map<int32_t, int64_t>& null_counts = {}, + const std::map<int32_t, int64_t>& nan_counts = {}) { + auto parse_bound = [&](const std::map<std::string, TestVariant>& bounds, + std::map<int32_t, std::vector<uint8_t>>& bound_values) { + for (const auto& [key, value] : bounds) { + if (key == "id") { + bound_values[1] = Literal::Long(std::get<int64_t>(value)).Serialize().value(); + } else if (key == "name") { + bound_values[2] = + Literal::String(std::get<std::string>(value)).Serialize().value(); + } else if (key == "age") { + bound_values[3] = Literal::Int(std::get<int32_t>(value)).Serialize().value(); + } else if (key == "salary") { + bound_values[4] = Literal::Double(std::get<double>(value)).Serialize().value(); + } else if (key == "active") { + bound_values[5] = Literal::Boolean(std::get<bool>(value)).Serialize().value(); + } + } + }; + + auto data_file = std::make_shared<DataFile>(); Review Comment: You can use designated initializers here. -- 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]
