|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include <gtest/gtest.h> |
| 21 | +#include <parquet/schema.h> |
| 22 | +#include <parquet/types.h> |
| 23 | + |
| 24 | +#include "iceberg/parquet/parquet_schema_util_internal.h" |
| 25 | + |
| 26 | +namespace iceberg::parquet { |
| 27 | + |
| 28 | +namespace { |
| 29 | + |
| 30 | +::parquet::schema::NodePtr MakeInt32Node(const std::string& name, int field_id = -1) { |
| 31 | + return ::parquet::schema::PrimitiveNode::Make( |
| 32 | + name, ::parquet::Repetition::REQUIRED, ::parquet::LogicalType::None(), |
| 33 | + ::parquet::Type::INT32, /*primitive_length=*/-1, field_id); |
| 34 | +} |
| 35 | + |
| 36 | +::parquet::schema::NodePtr MakeGroupNode(const std::string& name, |
| 37 | + const ::parquet::schema::NodeVector& fields, |
| 38 | + int field_id = -1) { |
| 39 | + return ::parquet::schema::GroupNode::Make(name, ::parquet::Repetition::REQUIRED, fields, |
| 40 | + /*logical_type=*/nullptr, field_id); |
| 41 | +} |
| 42 | + |
| 43 | +} // namespace |
| 44 | + |
| 45 | +TEST(HasFieldIds, PrimitiveNode) { |
| 46 | + EXPECT_FALSE(HasFieldIds(MakeInt32Node("test_field"))); |
| 47 | + EXPECT_TRUE(HasFieldIds(MakeInt32Node("test_field", /*field_id=*/1))); |
| 48 | +} |
| 49 | + |
| 50 | +TEST(HasFieldIds, GroupNode) { |
| 51 | + auto group_node_without_field_id = |
| 52 | + MakeGroupNode("test_group", {MakeInt32Node("c1"), MakeInt32Node("c2")}); |
| 53 | + EXPECT_FALSE(HasFieldIds(group_node_without_field_id)); |
| 54 | + |
| 55 | + auto group_node_with_full_field_id = MakeGroupNode( |
| 56 | + "test_group", |
| 57 | + {MakeInt32Node("c1", /*field_id=*/2), MakeInt32Node("c2", /*field_id=*/3)}, |
| 58 | + /*field_id=*/1); |
| 59 | + EXPECT_TRUE(HasFieldIds(group_node_with_full_field_id)); |
| 60 | + |
| 61 | + auto group_node_with_partial_field_id = MakeGroupNode( |
| 62 | + "test_group", {MakeInt32Node("c1", /*field_id=*/1), MakeInt32Node("c2")}); |
| 63 | + EXPECT_TRUE(HasFieldIds(group_node_with_partial_field_id)); |
| 64 | +} |
| 65 | + |
| 66 | +} // namespace iceberg::parquet |
0 commit comments