jklamer commented on a change in pull request #1602:
URL: https://github.com/apache/avro/pull/1602#discussion_r826443994



##########
File path: lang/rust/avro/src/schema.rs
##########
@@ -317,17 +328,73 @@ impl From<&str> for Name {
     }
 }
 
-impl Hash for Name {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.fullname(None).hash(state);
+pub struct ResolvedSchema<'s> {
+    names: HashMap<Name, &'s Schema>,
+    schema: &'s Schema,
+}
+
+impl<'s> From<&'s Schema> for ResolvedSchema<'s> {
+    fn from(schema: &'s Schema) -> Self {
+        let names = HashMap::new();
+        let mut rs = ResolvedSchema { names, schema };
+        Self::from_internal(rs.schema, &mut rs.names, &None);
+        rs
     }
 }
 
-impl Eq for Name {}
+impl<'s> ResolvedSchema<'s> {
+    pub fn get_names(&self) -> &HashMap<Name, &'s Schema> {
+        &self.names
+    }
 
-impl PartialEq for Name {
-    fn eq(&self, other: &Name) -> bool {
-        self.fullname(None).eq(&other.fullname(None))
+    pub fn get_schema(&self) -> &Schema {
+        self.schema
+    }
+
+    fn from_internal(
+        schema: &'s Schema,
+        idx: &mut HashMap<Name, &'s Schema>,
+        enclosing_namespace: &Namespace,
+    ) {
+        match schema {
+            Schema::Array(schema) | Schema::Map(schema) => {
+                Self::from_internal(schema, idx, enclosing_namespace)
+            }
+            Schema::Union(UnionSchema { schemas, .. }) => {
+                for schema in schemas {
+                    Self::from_internal(schema, idx, enclosing_namespace)
+                }
+            }
+            Schema::Enum { name, .. } | Schema::Fixed { name, .. } => {
+                let fully_qualified_name = 
name.fully_qualified_name(enclosing_namespace);
+                if idx.insert(fully_qualified_name.clone(), schema).is_some() {
+                    panic!(
+                        "Invalid Schema: Two schemas found with identical 
fullname: {}.",
+                        fully_qualified_name.fullname(None)
+                    );
+                }
+            }
+            Schema::Record { name, fields, .. } => {
+                let fully_qualified_name = 
name.fully_qualified_name(enclosing_namespace);
+                if idx.insert(fully_qualified_name.clone(), schema).is_some() {
+                    panic!(
+                        "Invalid Schema: Two schemas found with identical 
fullname: {}.",
+                        fully_qualified_name.fullname(None)
+                    );
+                }
+                let enclosing_namespace = 
name.fully_qualified_name(enclosing_namespace).namespace;

Review comment:
       right now fully_qualified_name is a method that needs the `name` 
instance so that it can override the enclosing namespace. Is there another 
setup you'd prefer? 




-- 
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