@@ -555,24 +555,25 @@ Status ValidateAvroSchemaEvolution(const Type& expected_type,
555555 ToString (avro_node));
556556}
557557
558- // XXX: Result<::avro::NodePtr> leads to unresolved external symbol error on Windows.
559- Result<std::shared_ptr<::avro::Node>> UnwrapUnion (const ::avro::NodePtr& node) {
558+ Status UnwrapUnion (const ::avro::NodePtr& node, ::avro::NodePtr* result) {
560559 if (node->type () != ::avro::AVRO_UNION) {
561- return node;
560+ *result = node;
561+ return {};
562562 }
563563 if (node->leaves () != 2 ) {
564564 return InvalidSchema (" Union type must have exactly two branches" );
565565 }
566566 auto branch_0 = node->leafAt (0 );
567567 auto branch_1 = node->leafAt (1 );
568568 if (branch_0->type () == ::avro::AVRO_NULL) {
569- return branch_1;
570- }
571- if (branch_1->type () == ::avro::AVRO_NULL) {
572- return branch_0;
569+ *result = branch_1;
570+ } else if (branch_1->type () == ::avro::AVRO_NULL) {
571+ *result = branch_0;
572+ } else {
573+ return InvalidSchema (" Union type must have exactly one null branch, got {}" ,
574+ ToString (node));
573575 }
574- return InvalidSchema (" Union type must have exactly one null branch, got {}" ,
575- ToString (node));
576+ return {};
576577}
577578
578579// Forward declaration
@@ -615,7 +616,8 @@ Result<FieldProjection> ProjectStruct(const StructType& struct_type,
615616 FieldProjection child_projection;
616617
617618 if (auto iter = node_info_map.find (field_id); iter != node_info_map.cend ()) {
618- ICEBERG_ASSIGN_OR_RAISE (auto field_node, UnwrapUnion (iter->second .field_node ));
619+ ::avro::NodePtr field_node;
620+ ICEBERG_RETURN_UNEXPECTED (UnwrapUnion (iter->second .field_node , &field_node));
619621 if (expected_field.type ()->is_nested ()) {
620622 ICEBERG_ASSIGN_OR_RAISE (
621623 child_projection,
@@ -662,7 +664,8 @@ Result<FieldProjection> ProjectList(const ListType& list_type,
662664 }
663665
664666 FieldProjection element_projection;
665- ICEBERG_ASSIGN_OR_RAISE (auto element_node, UnwrapUnion (avro_node->leafAt (0 )));
667+ ::avro::NodePtr element_node;
668+ ICEBERG_RETURN_UNEXPECTED (UnwrapUnion (avro_node->leafAt (0 ), &element_node));
666669 if (expected_element_field.type ()->is_nested ()) {
667670 ICEBERG_ASSIGN_OR_RAISE (
668671 element_projection,
@@ -725,7 +728,8 @@ Result<FieldProjection> ProjectMap(const MapType& map_type,
725728
726729 for (size_t i = 0 ; i < map_node->leaves (); ++i) {
727730 FieldProjection sub_projection;
728- ICEBERG_ASSIGN_OR_RAISE (auto sub_node, UnwrapUnion (map_node->leafAt (i)));
731+ ::avro::NodePtr sub_node;
732+ ICEBERG_RETURN_UNEXPECTED (UnwrapUnion (map_node->leafAt (i), &sub_node));
729733 const auto & expected_sub_field = map_type.fields ()[i];
730734 if (expected_sub_field.type ()->is_nested ()) {
731735 ICEBERG_ASSIGN_OR_RAISE (sub_projection, ProjectNested (*expected_sub_field.type (),
0 commit comments