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


##########
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:
   My point was that we should do it lazily:
    - first check in the local ones
    - if not resolved then look in the known ones
    - if again not resolved then return an Error
   
   There is no need to look in the known ones if it could be resolved in the 
local ones.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to