Skip to content

Commit ec76e8e

Browse files
format code
1 parent c0fdd63 commit ec76e8e

6 files changed

Lines changed: 107 additions & 89 deletions

File tree

src/iceberg/avro/avro_reader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class AvroBatchReader::Impl {
103103
if (options.name_mapping) {
104104
MappedField mapped_field;
105105
// Convert NameMapping to MappedFields for nested mapping
106-
mapped_field.nested_mapping = std::make_shared<MappedFields>(options.name_mapping->AsMappedFields());
106+
mapped_field.nested_mapping =
107+
std::make_shared<MappedFields>(options.name_mapping->AsMappedFields());
107108
ICEBERG_ASSIGN_OR_RAISE(
108109
auto new_root_node,
109110
CreateAvroNodeWithFieldIds(file_schema.root(), mapped_field));

src/iceberg/avro/avro_schema_util.cc

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,15 @@ Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& orig
793793
new_record_node->setName(original_node->name());
794794

795795
if (original_node->leaves() > original_node->names()) {
796-
return InvalidSchema("Node has {} leaves but only {} names", original_node->leaves(), original_node->names());
796+
return InvalidSchema("Node has {} leaves but only {} names", original_node->leaves(),
797+
original_node->names());
797798
}
798799

799800
for (size_t i = 0; i < original_node->leaves(); ++i) {
800801
const std::string& field_name = original_node->nameAt(i);
801802
::avro::NodePtr field_node = original_node->leafAt(i);
802803

803-
// TODO(liuxiaoyu): Add support for case sensitivity in name matching.
804+
// TODO(liuxiaoyu): Add support for case sensitivity in name matching.
804805
// Try to find nested field by name
805806
const MappedField* nested_field = nullptr;
806807
if (field.nested_mapping) {
@@ -816,7 +817,8 @@ Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& orig
816817
if (nested_field) {
817818
// Check if field_id is present
818819
if (!nested_field->field_id.has_value()) {
819-
return InvalidSchema("Field ID is missing for field '{}' in nested mapping", field_name);
820+
return InvalidSchema("Field ID is missing for field '{}' in nested mapping",
821+
field_name);
820822
}
821823

822824
// Preserve existing custom attributes for this field
@@ -832,15 +834,15 @@ Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& orig
832834

833835
// Add field ID attribute to the new node (preserving existing attributes)
834836
attributes.addAttribute(std::string(kFieldIdProp),
835-
std::to_string(nested_field->field_id.value()), false);
837+
std::to_string(nested_field->field_id.value()), false);
836838

837839
if (!attributes.attributes().empty()) {
838840
new_record_node->addCustomAttributesForField(attributes);
839841
}
840842

841843
// Recursively apply field IDs to nested fields
842844
ICEBERG_ASSIGN_OR_RAISE(auto new_nested_node,
843-
CreateAvroNodeWithFieldIds(field_node, *nested_field));
845+
CreateAvroNodeWithFieldIds(field_node, *nested_field));
844846
new_record_node->addName(field_name);
845847
new_record_node->addLeaf(new_nested_node);
846848
} else {
@@ -859,12 +861,11 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
859861
}
860862

861863
auto new_array_node = std::make_shared<::avro::NodeArray>();
862-
864+
863865
// Check if this is a map represented as array
864866
if (HasMapLogicalType(original_node)) {
865-
ICEBERG_ASSIGN_OR_RAISE(
866-
auto new_element_node,
867-
CreateAvroNodeWithFieldIds(original_node->leafAt(0), field));
867+
ICEBERG_ASSIGN_OR_RAISE(auto new_element_node,
868+
CreateAvroNodeWithFieldIds(original_node->leafAt(0), field));
868869
new_array_node->addLeaf(new_element_node);
869870
return new_array_node;
870871
}
@@ -886,7 +887,7 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
886887
if (!element_field->field_id.has_value()) {
887888
return InvalidSchema("Field ID is missing for element field in array");
888889
}
889-
890+
890891
ICEBERG_ASSIGN_OR_RAISE(
891892
auto new_element_node,
892893
CreateAvroNodeWithFieldIds(original_node->leafAt(0), *element_field));
@@ -895,7 +896,7 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
895896
// If no element field found, this is an error
896897
return InvalidSchema("Element field not found in nested mapping for array");
897898
}
898-
899+
899900
return new_array_node;
900901
}
901902

@@ -938,10 +939,11 @@ Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& origina
938939
}
939940

940941
// Add key and value nodes
941-
ICEBERG_ASSIGN_OR_RAISE(auto new_key_node,
942-
CreateAvroNodeWithFieldIds(original_node->leafAt(0), *key_field));
943-
ICEBERG_ASSIGN_OR_RAISE(auto new_value_node,
944-
CreateAvroNodeWithFieldIds(original_node->leafAt(1), *value_field));
942+
ICEBERG_ASSIGN_OR_RAISE(auto new_key_node, CreateAvroNodeWithFieldIds(
943+
original_node->leafAt(0), *key_field));
944+
ICEBERG_ASSIGN_OR_RAISE(
945+
auto new_value_node,
946+
CreateAvroNodeWithFieldIds(original_node->leafAt(1), *value_field));
945947
new_map_node->addLeaf(new_key_node);
946948
new_map_node->addLeaf(new_value_node);
947949

@@ -963,15 +965,15 @@ Result<::avro::NodePtr> CreateUnionNodeWithFieldIds(const ::avro::NodePtr& origi
963965
if (branch_0_is_null && !branch_1_is_null) {
964966
// branch_0 is null, branch_1 is not null
965967
ICEBERG_ASSIGN_OR_RAISE(auto new_branch_1,
966-
CreateAvroNodeWithFieldIds(branch_1, field));
968+
CreateAvroNodeWithFieldIds(branch_1, field));
967969
auto new_union_node = std::make_shared<::avro::NodeUnion>();
968970
new_union_node->addLeaf(branch_0); // null branch
969971
new_union_node->addLeaf(new_branch_1);
970972
return new_union_node;
971973
} else if (!branch_0_is_null && branch_1_is_null) {
972974
// branch_0 is not null, branch_1 is null
973975
ICEBERG_ASSIGN_OR_RAISE(auto new_branch_0,
974-
CreateAvroNodeWithFieldIds(branch_0, field));
976+
CreateAvroNodeWithFieldIds(branch_0, field));
975977
auto new_union_node = std::make_shared<::avro::NodeUnion>();
976978
new_union_node->addLeaf(new_branch_0);
977979
new_union_node->addLeaf(branch_1); // null branch
@@ -989,7 +991,6 @@ Result<::avro::NodePtr> CreateUnionNodeWithFieldIds(const ::avro::NodePtr& origi
989991

990992
Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& original_node,
991993
const MappedField& mapped_field) {
992-
993994
switch (original_node->type()) {
994995
case ::avro::AVRO_RECORD:
995996
return CreateRecordNodeWithFieldIds(original_node, mapped_field);
@@ -1013,8 +1014,8 @@ Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& origin
10131014
case ::avro::AVRO_ENUM:
10141015
default:
10151016
return InvalidSchema("Unsupported Avro type for field ID application: {}",
1016-
ToString(original_node));
1017+
ToString(original_node));
10171018
}
10181019
}
10191020

1020-
} // namespace iceberg::avro
1021+
} // namespace iceberg::avro

src/iceberg/avro/avro_schema_util_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,4 @@ bool HasMapLogicalType(const ::avro::NodePtr& node);
152152
Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& original_node,
153153
const MappedField& mapped_field);
154154

155-
156-
157155
} // namespace iceberg::avro

test/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ add_test(NAME util_test COMMAND util_test)
7777

7878
if(ICEBERG_BUILD_BUNDLE)
7979
add_executable(avro_test)
80-
target_sources(avro_test PRIVATE avro_data_test.cc avro_test.cc avro_schema_test.cc
81-
avro_stream_test.cc name_mapping_test.cc)
80+
target_sources(avro_test
81+
PRIVATE avro_data_test.cc
82+
avro_test.cc
83+
avro_schema_test.cc
84+
avro_stream_test.cc
85+
name_mapping_test.cc)
8286
target_link_libraries(avro_test PRIVATE iceberg_bundle_static GTest::gtest_main
8387
GTest::gmock)
8488
add_test(NAME avro_test COMMAND avro_test)

test/avro_schema_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,4 +1074,3 @@ TEST(AvroSchemaProjectionTest, ProjectDecimalIncompatible) {
10741074
ASSERT_THAT(projection_result, HasErrorMessage("Cannot read"));
10751075
}
10761076
} // namespace iceberg::avro
1077-

0 commit comments

Comments
 (0)