You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2022/10/07 17:06:06 UTC

[GitHub] [avro] woile opened a new pull request, #1901: AVRO-3632: [Rust] Handle defaults in unions according to the spec

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

   <!--
   
   *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/master/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
   
   Check the first element of the union matches the default value provided according to the [union spec](https://avro.apache.org/docs/1.11.1/specification/#unions)
   
   ## Verifying this change
   
   This change added tests and can be verified as follows: `cargo test`
   
   ## Documentation
   
   - Does this pull request introduce a new feature? NO
   


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


[GitHub] [avro] martin-g commented on a diff in pull request #1901: AVRO-3632: [Rust] Handle defaults in unions according to the spec

Posted by GitBox <gi...@apache.org>.
martin-g commented on code in PR #1901:
URL: https://github.com/apache/avro/pull/1901#discussion_r991152897


##########
lang/rust/avro/src/schema.rs:
##########
@@ -1373,12 +1376,35 @@ impl Parser {
         &mut self,
         items: &[Value],
         enclosing_namespace: &Namespace,
+        default: Option<&Value>
     ) -> AvroResult<Schema> {
         items
             .iter()
             .map(|v| self.parse(v, enclosing_namespace))
             .collect::<Result<Vec<_>, _>>()
+            .and_then(|schemas| {
+                if let Some(default_value) = default {
+                    let avro_value = types::Value::from(default_value.clone());
+                    let first_schema = schemas.first().cloned();
+                    if let Some(schema) = first_schema {
+                        // Try to resolve the schema
+                        let resolved_value = avro_value.clone().resolve(&schema);
+                        let schema_kind = SchemaKind::from(schema);
+                        let value_kind = types::ValueKind::from(avro_value);

Review Comment:
   nit: The last two lines should be moved to line 1397.



##########
lang/rust/avro/src/error.rs:
##########
@@ -229,6 +229,9 @@ pub enum Error {
     #[error("Unions cannot contain duplicate types")]
     GetUnionDuplicate,
 
+    #[error("Unions first type {0:?} must match default value type {1:?}")]

Review Comment:
   ```suggestion
       #[error("Union's first type {0:?} must match the `default`'s value type {1:?}")]
   ```



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


[GitHub] [avro] woile commented on pull request #1901: AVRO-3632: [Rust] Handle defaults in unions according to the spec

Posted by GitBox <gi...@apache.org>.
woile commented on PR #1901:
URL: https://github.com/apache/avro/pull/1901#issuecomment-1273225187

   Thanks for the feedback, I'll update the PR ASAP.


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


[GitHub] [avro] martin-g commented on pull request #1901: AVRO-3632: [Rust] Handle defaults in unions according to the spec

Posted by GitBox <gi...@apache.org>.
martin-g commented on PR #1901:
URL: https://github.com/apache/avro/pull/1901#issuecomment-1273762510

   Thank you for the contribution, @woile !


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


[GitHub] [avro] martin-g merged pull request #1901: AVRO-3632: [Rust] Handle defaults in unions according to the spec

Posted by GitBox <gi...@apache.org>.
martin-g merged PR #1901:
URL: https://github.com/apache/avro/pull/1901


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