Skip to content

Commit 8cbda38

Browse files
code format
1 parent 5d7c4f5 commit 8cbda38

3 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/iceberg/avro/avro_reader.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ class AvroBatchReader::Impl {
101101
if (has_id_visitor.HasNoIds()) {
102102
// Apply field IDs based on name mapping if available
103103
if (options.name_mapping) {
104-
ICEBERG_ASSIGN_OR_RAISE(auto new_root_node,
105-
CreateAvroNodeWithFieldIds(file_schema.root(), *options.name_mapping));
104+
ICEBERG_ASSIGN_OR_RAISE(
105+
auto new_root_node,
106+
CreateAvroNodeWithFieldIds(file_schema.root(), *options.name_mapping));
106107

107108
// Create a new schema with the updated root node
108109
auto new_schema = ::avro::ValidSchema(new_root_node);
@@ -111,8 +112,10 @@ class AvroBatchReader::Impl {
111112
HasIdVisitor verify_visitor;
112113
ICEBERG_RETURN_UNEXPECTED(verify_visitor.Visit(new_schema));
113114
if (!verify_visitor.AllHaveIds()) {
114-
// TODO(liuxiaoyu): Print detailed error message with missing field IDs information in future
115-
return InvalidSchema("Not all fields have field IDs after applying name mapping.");
115+
// TODO(liuxiaoyu): Print detailed error message with missing field IDs
116+
// information in future
117+
return InvalidSchema(
118+
"Not all fields have field IDs after applying name mapping.");
116119
}
117120

118121
// Update the file schema to use the new schema with field IDs

src/iceberg/avro/avro_schema_util.cc

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ Result<SchemaProjection> Project(const Schema& expected_schema,
787787

788788
// Helper function to create a new Avro node with field IDs from name mapping
789789
Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& original_node,
790-
const NameMapping& name_mapping) {
790+
const NameMapping& name_mapping) {
791791
switch (original_node->type()) {
792792
case ::avro::AVRO_RECORD:
793793
return CreateRecordNodeWithFieldIds(original_node, name_mapping);
@@ -816,7 +816,7 @@ Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& origin
816816
}
817817

818818
Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& original_node,
819-
const NameMapping& name_mapping) {
819+
const NameMapping& name_mapping) {
820820
auto new_record_node = std::make_shared<::avro::NodeRecord>();
821821
new_record_node->setName(original_node->name());
822822

@@ -830,21 +830,20 @@ Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& orig
830830
// Add field ID attribute to the new node
831831
::avro::CustomAttributes attributes;
832832
attributes.addAttribute(std::string(kFieldIdProp),
833-
std::to_string(field_ref->get().field_id.value()),
834-
false);
833+
std::to_string(field_ref->get().field_id.value()), false);
835834
new_record_node->addCustomAttributesForField(attributes);
836835
}
837836

838837
// Recursively apply field IDs to nested fields if they exist
839-
if (field_ref->get().nested_mapping &&
840-
field_node->type() == ::avro::AVRO_RECORD) {
838+
if (field_ref->get().nested_mapping && field_node->type() == ::avro::AVRO_RECORD) {
841839
const auto& nested_mapping = field_ref->get().nested_mapping;
842840
auto fields_span = nested_mapping->fields();
843841
std::vector<MappedField> fields_vector(fields_span.begin(), fields_span.end());
844842
auto nested_name_mapping = NameMapping::Make(std::move(fields_vector));
845843

846-
ICEBERG_ASSIGN_OR_RAISE(auto new_nested_node,
847-
CreateAvroNodeWithFieldIds(field_node, *nested_name_mapping));
844+
ICEBERG_ASSIGN_OR_RAISE(
845+
auto new_nested_node,
846+
CreateAvroNodeWithFieldIds(field_node, *nested_name_mapping));
848847
new_record_node->addName(field_name);
849848
new_record_node->addLeaf(new_nested_node);
850849
} else {
@@ -867,7 +866,7 @@ Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& orig
867866
}
868867

869868
Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& original_node,
870-
const NameMapping& name_mapping) {
869+
const NameMapping& name_mapping) {
871870
if (original_node->leaves() != 1) {
872871
return InvalidSchema("Array type must have exactly one leaf");
873872
}
@@ -880,8 +879,9 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
880879
if (original_node->logicalType().type() == ::avro::LogicalType::CUSTOM &&
881880
original_node->logicalType().customLogicalType() != nullptr &&
882881
original_node->logicalType().customLogicalType()->name() == kMapLogicalType) {
883-
ICEBERG_ASSIGN_OR_RAISE(auto new_element_node,
884-
CreateAvroNodeWithFieldIds(original_node->leafAt(0), name_mapping));
882+
ICEBERG_ASSIGN_OR_RAISE(
883+
auto new_element_node,
884+
CreateAvroNodeWithFieldIds(original_node->leafAt(0), name_mapping));
885885
new_array_node->addLeaf(new_element_node);
886886
return new_array_node;
887887
}
@@ -897,14 +897,15 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
897897
}
898898
}
899899

900-
ICEBERG_ASSIGN_OR_RAISE(auto new_element_node,
901-
CreateAvroNodeWithFieldIds(original_node->leafAt(0), name_mapping));
900+
ICEBERG_ASSIGN_OR_RAISE(
901+
auto new_element_node,
902+
CreateAvroNodeWithFieldIds(original_node->leafAt(0), name_mapping));
902903
new_array_node->addLeaf(new_element_node);
903904
return new_array_node;
904905
}
905906

906907
Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& original_node,
907-
const NameMapping& name_mapping) {
908+
const NameMapping& name_mapping) {
908909
if (original_node->leaves() != 2) {
909910
return InvalidSchema("Map type must have exactly two leaves");
910911
}
@@ -927,25 +928,25 @@ Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& origina
927928
if (value_field->get().field_id.has_value()) {
928929
::avro::CustomAttributes attributes;
929930
attributes.addAttribute(std::string(kValueIdProp),
930-
std::to_string(value_field->get().field_id.value()),
931-
false);
931+
std::to_string(value_field->get().field_id.value()), false);
932932
new_map_node->addCustomAttributesForField(attributes);
933933
}
934934
}
935935

936936
// Add key and value nodes
937-
ICEBERG_ASSIGN_OR_RAISE(auto new_key_node,
938-
CreateAvroNodeWithFieldIds(original_node->leafAt(0), name_mapping));
939-
ICEBERG_ASSIGN_OR_RAISE(auto new_value_node,
940-
CreateAvroNodeWithFieldIds(original_node->leafAt(1), name_mapping));
937+
ICEBERG_ASSIGN_OR_RAISE(auto new_key_node, CreateAvroNodeWithFieldIds(
938+
original_node->leafAt(0), name_mapping));
939+
ICEBERG_ASSIGN_OR_RAISE(
940+
auto new_value_node,
941+
CreateAvroNodeWithFieldIds(original_node->leafAt(1), name_mapping));
941942
new_map_node->addLeaf(new_key_node);
942943
new_map_node->addLeaf(new_value_node);
943944

944945
return new_map_node;
945946
}
946947

947948
Result<::avro::NodePtr> CreateUnionNodeWithFieldIds(const ::avro::NodePtr& original_node,
948-
const NameMapping& name_mapping) {
949+
const NameMapping& name_mapping) {
949950
if (original_node->leaves() != 2) {
950951
return InvalidSchema("Union type must have exactly two branches");
951952
}

src/iceberg/avro/avro_schema_util_internal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,34 +150,34 @@ bool HasMapLogicalType(const ::avro::NodePtr& node);
150150
/// \param name_mapping The name mapping to apply field IDs from.
151151
/// \return A new Avro node with field IDs applied, or an error.
152152
Result<::avro::NodePtr> CreateAvroNodeWithFieldIds(const ::avro::NodePtr& original_node,
153-
const NameMapping& name_mapping);
153+
const NameMapping& name_mapping);
154154

155155
/// \brief Create a new Avro record node with field IDs from name mapping.
156156
/// \param original_node The original Avro record node to copy.
157157
/// \param name_mapping The name mapping to apply field IDs from.
158158
/// \return A new Avro record node with field IDs applied, or an error.
159159
Result<::avro::NodePtr> CreateRecordNodeWithFieldIds(const ::avro::NodePtr& original_node,
160-
const NameMapping& name_mapping);
160+
const NameMapping& name_mapping);
161161

162162
/// \brief Create a new Avro array node with field IDs from name mapping.
163163
/// \param original_node The original Avro array node to copy.
164164
/// \param name_mapping The name mapping to apply field IDs from.
165165
/// \return A new Avro array node with field IDs applied, or an error.
166166
Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& original_node,
167-
const NameMapping& name_mapping);
167+
const NameMapping& name_mapping);
168168

169169
/// \brief Create a new Avro map node with field IDs from name mapping.
170170
/// \param original_node The original Avro map node to copy.
171171
/// \param name_mapping The name mapping to apply field IDs from.
172172
/// \return A new Avro map node with field IDs applied, or an error.
173173
Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& original_node,
174-
const NameMapping& name_mapping);
174+
const NameMapping& name_mapping);
175175

176176
/// \brief Create a new Avro union node with field IDs from name mapping.
177177
/// \param original_node The original Avro union node to copy.
178178
/// \param name_mapping The name mapping to apply field IDs from.
179179
/// \return A new Avro union node with field IDs applied, or an error.
180180
Result<::avro::NodePtr> CreateUnionNodeWithFieldIds(const ::avro::NodePtr& original_node,
181-
const NameMapping& name_mapping);
181+
const NameMapping& name_mapping);
182182

183183
} // namespace iceberg::avro

0 commit comments

Comments
 (0)