@@ -855,8 +855,12 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
855855
856856 // Check and add custom attributes
857857 if (original_node->customAttributes () > 0 ) {
858- for (auto & attr : original_node->customAttributesMap ()) {
859- new_array_node->addCustomAttribute (attr.first , attr.second );
858+ const auto & original_attrs = original_node->customAttributesAt (0 );
859+ const auto & existing_attrs = original_attrs.attributes ();
860+ for (const auto & attr_pair : existing_attrs) {
861+ ::avro::CustomAttributes attributes;
862+ attributes.addAttribute (attr_pair.first , attr_pair.second , /* addQuote=*/ false );
863+ new_array_node->addCustomAttributesForField (attributes);
860864 }
861865 }
862866
@@ -881,8 +885,12 @@ Result<::avro::NodePtr> CreateArrayNodeWithFieldIds(const ::avro::NodePtr& origi
881885
882886 // Check and add custom attributes from original node
883887 if (original_node->customAttributes () > 0 ) {
884- for (auto & attr : original_node->customAttributesMap ()) {
885- new_array_node->addCustomAttribute (attr.first , attr.second );
888+ const auto & original_attrs = original_node->customAttributesAt (0 );
889+ const auto & existing_attrs = original_attrs.attributes ();
890+ for (const auto & attr_pair : existing_attrs) {
891+ ::avro::CustomAttributes attributes;
892+ attributes.addAttribute (attr_pair.first , attr_pair.second , /* addQuote=*/ false );
893+ new_array_node->addCustomAttributesForField (attributes);
886894 }
887895 }
888896
@@ -947,7 +955,7 @@ Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& origina
947955 // Merge custom attributes from original node if they exist
948956 if (original_node->customAttributes () > 0 ) {
949957 // Merge attributes for key (index 0)
950- if (original_node->hasCustomAttributesForField ( 0 ) ) {
958+ if (original_node->customAttributes () > 0 ) {
951959 const auto & original_key_attrs = original_node->customAttributesAt (0 );
952960 const auto & existing_key_attrs = original_key_attrs.attributes ();
953961 for (const auto & attr_pair : existing_key_attrs) {
@@ -960,7 +968,7 @@ Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& origina
960968 }
961969
962970 // Merge attributes for value (index 1)
963- if (original_node->hasCustomAttributesForField ( 1 ) ) {
971+ if (original_node->customAttributes () > 1 ) {
964972 const auto & original_value_attrs = original_node->customAttributesAt (1 );
965973 const auto & existing_value_attrs = original_value_attrs.attributes ();
966974 for (const auto & attr_pair : existing_value_attrs) {
@@ -972,9 +980,23 @@ Result<::avro::NodePtr> CreateMapNodeWithFieldIds(const ::avro::NodePtr& origina
972980 }
973981 }
974982
975- // Merge node-level attributes if any
976- for (auto & attr : original_node->customAttributesMap ()) {
977- new_map_node->addCustomAttribute (attr.first , attr.second );
983+ // Copy node-level custom attributes if any
984+ // We already handled field-specific attributes above, now add any remaining attributes
985+ // to preserve all metadata
986+ ::avro::CustomAttributes node_attributes;
987+ for (size_t i = 0 ; i < original_node->customAttributes (); i++) {
988+ const auto & original_attrs = original_node->customAttributesAt (i);
989+ const auto & existing_attrs = original_attrs.attributes ();
990+ for (const auto & attr_pair : existing_attrs) {
991+ // Skip field ID attributes we've already handled
992+ if (attr_pair.first != kKeyIdProp && attr_pair.first != kValueIdProp ) {
993+ node_attributes.addAttribute (attr_pair.first , attr_pair.second , /* addQuote=*/ false );
994+ }
995+ }
996+ }
997+ // Add node attributes if we found any
998+ if (node_attributes.attributes ().size () > 0 ) {
999+ new_map_node->addCustomAttributesForField (node_attributes);
9781000 }
9791001 }
9801002
0 commit comments