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

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

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



##########
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!(

Review comment:
       Will do. And I believe we will want to do it for the encoding workflow 
as well. 




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


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

    Worklog Id:     (was: 741320)
    Time Spent: 1h 10m  (was: 1h)

> 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: 1h 10m
>  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