You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "martin-g (via GitHub)" <gi...@apache.org> on 2023/06/06 10:58:19 UTC

[GitHub] [avro] martin-g commented on a diff in pull request #2266: Avro-3767 [Rust] fix complex Ref resolving in Union

martin-g commented on code in PR #2266:
URL: https://github.com/apache/avro/pull/2266#discussion_r1219419592


##########
lang/rust/avro/src/schema.rs:
##########
@@ -434,21 +455,28 @@ impl<'s> ResolvedSchema<'s> {
                 }
                 Schema::Record(RecordSchema { name, fields, .. }) => {
                     let fully_qualified_name = name.fully_qualified_name(enclosing_namespace);
-                    if names_ref
+                    if self
+                        .names_ref
                         .insert(fully_qualified_name.clone(), schema)
                         .is_some()
                     {
                         return Err(Error::AmbiguousSchemaDefinition(fully_qualified_name));
                     } else {
                         let record_namespace = fully_qualified_name.namespace;
                         for field in fields {
-                            Self::from_internal(vec![&field.schema], names_ref, &record_namespace)?
+                            self.resolve(vec![&field.schema], &record_namespace, known_schemas)?
                         }
                     }
                 }
                 Schema::Ref { name } => {
                     let fully_qualified_name = name.fully_qualified_name(enclosing_namespace);
-                    if names_ref.get(&fully_qualified_name).is_none() {
+                    // first search for reference in current schema, then look into external references.
+                    let is_resolved_locally = self.names_ref.get(&fully_qualified_name).is_some();
+                    let is_resolved_with_known_schemas = known_schemas
+                        .as_ref()
+                        .map(|schemas| schemas.get(&fully_qualified_name).is_some())
+                        .unwrap_or(false);
+                    if !is_resolved_locally && !is_resolved_with_known_schemas {

Review Comment:
   I have the feeling this is not what you wanted.
   IMO it should be:
   ```
   if !is_resolved_locally {
         let is_resolved_with_known_schemas = known_schemas
              .as_ref()
              .map(|schemas| schemas.get(&fully_qualified_name).is_some())
              .unwrap_or(false);
         if !is_resolved_with_known_schemas {
             return Err(Error::SchemaResolutionError(fully_qualified_name));
         }
   }
   ```
   
   I am already doing some improvements to the PR, so please just comment here, don't push changes,



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org