[ 
https://issues.apache.org/jira/browse/AVRO-3448?focusedWorklogId=741328&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-741328
 ]

ASF GitHub Bot logged work on AVRO-3448:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Mar/22 23:05
            Start Date: 14/Mar/22 23:05
    Worklog Time Spent: 10m 
      Work Description: jklamer commented on a change in pull request #1602:
URL: https://github.com/apache/avro/pull/1602#discussion_r826449145



##########
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;
+                for field in fields {
+                    Self::from_internal(&field.schema, idx, 
&enclosing_namespace)
+                }
+            }
+            Schema::Ref { name } => {
+                let fully_qualified_name = 
name.fully_qualified_name(enclosing_namespace);
+                if !idx.contains_key(&fully_qualified_name) {
+                    panic!("Invalid schema: Unable to find schema for 
reference {}. Make sure to use inherited namespace as needed.", 
fully_qualified_name.fullname(None))

Review comment:
       yeah Im not sure. I can wrap it for clarity and see if rust fmt will let 
it stand. 




-- 
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-unsubscr...@avro.apache.org

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 741328)
    Time Spent: 1.5h  (was: 1h 20m)

> Rust: Encoding Panic with valid schema and input 
> -------------------------------------------------
>
>                 Key: AVRO-3448
>                 URL: https://issues.apache.org/jira/browse/AVRO-3448
>             Project: Apache Avro
>          Issue Type: Bug
>            Reporter: Jack Klamer
>            Assignee: Jack Klamer
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> After a recent bug regarding Rust Avro's schema ref was fixed to help 
> preserve the parsing form of schema 
> (https://issues.apache.org/jira/browse/AVRO-3433). This exposed an issue 
> where named schemas defined with the rules of the spec (depth first, left to 
> right), are not available to the encoding workflow because it indexes schemas 
> as it traverses the data. This is a problem for the common use case of 
> defining a record within an optional field and it being encoded as Null, and 
> not having that type then available during encoding for the next field. 
>  
> This was patched for level + 1 schema definitions but was not solved within 
> the fullness of the spec 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to