You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "marcosschroh (via GitHub)" <gi...@apache.org> on 2023/12/11 13:05:24 UTC

[PR] AVRO-3917: [Rust] take field aliases into account when calculating sc… [avro]

marcosschroh opened a new pull request, #2633:
URL: https://github.com/apache/avro/pull/2633

   …hema compatibilities
   
   <!--
   
   *Thank you very much for contributing to Apache Avro - we are happy that you want to help us improve Avro. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Avro a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/AVRO/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "AVRO-XXXX: [component] Title of the pull request", where *AVRO-XXXX* should be replaced by the actual issue number. 
       The *component* is optional, but can help identify the correct reviewers faster: either the language ("java", "python") or subsystem such as "build" or "doc" are good candidates.  
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests. You can [build the entire project](https://github.com/apache/avro/blob/main/BUILD.md) or just the [language-specific SDK](https://avro.apache.org/project/how-to-contribute/#unit-tests).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Every commit message references Jira issues in their subject lines. In addition, commits follow the guidelines from [How to write a good git commit message](https://chris.beams.io/posts/git-commit/)
       1. Subject is separated from body by a blank line
       1. Subject is limited to 50 characters (not including Jira issue reference)
       1. Subject does not end with a period
       1. Subject uses the imperative mood ("add", not "adding")
       1. Body wraps at 72 characters
       1. Body explains "what" and "why", not "how"
   
   -->
   
   ## What is the purpose of the change
   
   *(For example: This pull request improves file read performance by buffering data, fixing AVRO-XXXX.)*
   
   
   ## Verifying this change
   
   *(Please pick one of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
   - *Extended interop tests to verify consistent valid schema names between SDKs*
   - *Added test that validates that Java throws an AvroRuntimeException on invalid binary data*
   - *Manually verified the change by building the website and checking the new redirect*
   
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes / no)
   - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: dev-unsubscribe@avro.apache.org

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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "woile (via GitHub)" <gi...@apache.org>.
woile commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1425109408


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![&field.name];
+                    if let Some(ref aliases) = field.aliases {
+                        for alias in aliases {
+                            fields_names.push(alias);
+                        }
+                    }
+
+                    // Check whether any of the possible fields names are in the writer schema.
+                    // If the field was found, then it must have the exact same name with the writer field,
+                    // otherwise we would have a false positive with the writers aliases
+                    let mut position = None;

Review Comment:
   you can avoid this `let mut` with a find:
   ```rs
   let position = fields_names.iter().find_map(|field_name| {
       if let Some(pos) = w_lookup.get(field_name) {
           if &w_fields[*pos].name == field_name {
               return Some(pos);
           }
       }
       return None
   })
   ```



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating sc… [avro]

Posted by "marcosschroh (via GitHub)" <gi...@apache.org>.
marcosschroh commented on PR #2633:
URL: https://github.com/apache/avro/pull/2633#issuecomment-1850239151

   @martin-g I am seeing that the CI is failing because some packages can not be installed as they `required rustc 1.70.0 or newer`, for example `clap builder` and `anstyle`. Shall we update the `rust` version to ` 1.70.0`?


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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "woile (via GitHub)" <gi...@apache.org>.
woile commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1425109408


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![&field.name];
+                    if let Some(ref aliases) = field.aliases {
+                        for alias in aliases {
+                            fields_names.push(alias);
+                        }
+                    }
+
+                    // Check whether any of the possible fields names are in the writer schema.
+                    // If the field was found, then it must have the exact same name with the writer field,
+                    // otherwise we would have a false positive with the writers aliases
+                    let mut position = None;

Review Comment:
   you can avoid this `let mut` with a find:
   ```rs
   let position = fields_names.iter().find(|field_name| {
       if let Some(pos) = w_lookup.get(field_name) {
           if &w_fields[*pos].name == field_name {
               return Some(pos);
           }
       }
       return None
   })
   ```



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "woile (via GitHub)" <gi...@apache.org>.
woile commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1425109408


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![&field.name];
+                    if let Some(ref aliases) = field.aliases {
+                        for alias in aliases {
+                            fields_names.push(alias);
+                        }
+                    }
+
+                    // Check whether any of the possible fields names are in the writer schema.
+                    // If the field was found, then it must have the exact same name with the writer field,
+                    // otherwise we would have a false positive with the writers aliases
+                    let mut position = None;

Review Comment:
   you can avoid this `let mut` with a find:
   ```rs
   let position = fields_names.iter().find(|field_name| {
       if let Some(pos) = w_lookup.get(field_name) {
           return &w_fields[*pos].name == field_name
       }
       return false
   })
   ```



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "woile (via GitHub)" <gi...@apache.org>.
woile commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1425109408


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![&field.name];
+                    if let Some(ref aliases) = field.aliases {
+                        for alias in aliases {
+                            fields_names.push(alias);
+                        }
+                    }
+
+                    // Check whether any of the possible fields names are in the writer schema.
+                    // If the field was found, then it must have the exact same name with the writer field,
+                    // otherwise we would have a false positive with the writers aliases
+                    let mut position = None;

Review Comment:
   you can avoid this `let mut` with a find:
   ```rs
   let position = fields_names.iter().find(|field_name| {
       let position = fields_names.iter().find_map(|field_name| {
       if let Some(pos) = w_lookup.get(field_name) {
           return &w_fields[*pos].name == field_name
       }
       return false
   })
   })
   ```



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating sc… [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1422521191


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![field.name.clone()];

Review Comment:
   I think you can use a `Vec<&str>` instead, and avoid the clones.



##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -1183,23 +1213,38 @@ mod tests {
                 {"type": "string", "name": "name"},
                 {"type": "long", "name": "date", "aliases" : [ "time" ]}
             ]
-        }"#;
+        }"#,
+        )?;
 
-        #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
-        pub struct Conference {
-            pub name: String,
-            pub date: i64,
-        }
-        #[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
-        pub struct ConferenceV2 {
-            pub name: String,
-            pub time: i64,
-        }
+        let schema_v3 = Schema::parse_str(

Review Comment:
   Please create new test methods instead of extending existing ones.
   It is hard to follow what exactly is being tested when the test tests more than one use case.



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating sc… [avro]

Posted by "marcosschroh (via GitHub)" <gi...@apache.org>.
marcosschroh commented on code in PR #2633:
URL: https://github.com/apache/avro/pull/2633#discussion_r1422569111


##########
lang/rust/avro/src/schema_compatibility.rs:
##########
@@ -158,17 +158,45 @@ impl Checker {
             }) = readers_schema
             {
                 for field in r_fields.iter() {
-                    if let Some(pos) = w_lookup.get(&field.name) {
-                        if let Err(err) =
-                            self.full_match_schemas(&w_fields[*pos].schema, &field.schema)
-                        {
-                            return Err(CompatibilityError::FieldTypeMismatch(
-                                field.name.clone(),
-                                Box::new(err),
-                            ));
+                    // get all field names in a vector (field.name + aliases)
+                    let mut fields_names = vec![field.name.clone()];

Review Comment:
   Cool!! Thanks



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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on PR #2633:
URL: https://github.com/apache/avro/pull/2633#issuecomment-1851746194

   Thank you, @marcosschroh !


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


Re: [PR] AVRO-3917: [Rust] take field aliases into account when calculating schema compatibilities [avro]

Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g merged PR #2633:
URL: https://github.com/apache/avro/pull/2633


-- 
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: dev-unsubscribe@avro.apache.org

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