You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Christophe Le Saec (Jira)" <ji...@apache.org> on 2022/12/12 15:47:00 UTC

[jira] [Comment Edited] (AVRO-3687) Rust enum missing default

    [ https://issues.apache.org/jira/browse/AVRO-3687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17646178#comment-17646178 ] 

Christophe Le Saec edited comment on AVRO-3687 at 12/12/22 3:46 PM:
--------------------------------------------------------------------

Default value is on a [Record field|https://github.com/apache/avro/blob/master/lang/rust/avro/src/schema.rs#L572], not on the type itself.
So, you could have :
{code:json}
{"type":"record", "namespace":"foo","name":"Person",
  "fields":[
    {"name":"shape",
     "type":  {"name":"Shapes","type":"enum","symbols":["SQUARE","TRIANGLE","CIRCLE","OVAL"]}, 
     "default": "TRIANGLE"}
   ]
}
{code}
This is better for union type, because if a field is defined as an union of 2 Enums, each with its own default value, what would be the default value of the field ;-) 



was (Author: JIRAUSER289541):
Default value is on a [Record field|https://github.com/apache/avro/blob/master/lang/rust/avro/src/schema.rs#L572], not on the type as Enum is.
So, you could have :
{code:json}
{"type":"record", "namespace":"foo","name":"Person",
  "fields":[
    {"name":"shape",
     "type":  {"name":"Shapes","type":"enum","symbols":["SQUARE","TRIANGLE","CIRCLE","OVAL"]}, 
     "default": "TRIANGLE"}
   ]
}
{code}
This is better for union type, because if a field is defined as an union of 2 Enums, each with its own default value, what would be the default value of the field ;-) 


> Rust enum missing default
> -------------------------
>
>                 Key: AVRO-3687
>                 URL: https://issues.apache.org/jira/browse/AVRO-3687
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>    Affects Versions: 1.11.1
>            Reporter: Santiago Fraire Willemoes
>            Priority: Major
>              Labels: enum, rust
>
> I cannot seem to find the enum's default attribute as documented [in the spec|https://avro.apache.org/docs/1.11.1/specification/#enums:~:text=for%20names).-,default,-%3A%20A%20default%20value]
> I'm trying to create an avdl parser and this is a blocker for me. I was wondering if there's a reason for this. Otherwise I can submit a PR, please let me know, thanks.
> Code sample:
> {code}
> let schema_str = r#"{"name":"Shapes","type":"enum","symbols":["SQUARE","TRIANGLE","CIRCLE","OVAL"], "default": "SQUARE"}"#;
> let r = Schema::parse_str(schema_str).unwrap();
> let can = r.canonical_form();
> println!("{r:?}");
> println!("{can}");
> {code}
> Observe the enum in its canonical form is missing the default.
> Looking at the Enum's code, we cannot see a default field:
> https://github.com/apache/avro/blob/master/lang/rust/avro/src/schema.rs#L113-L119
> I apologize if this is somehow wrong



--
This message was sent by Atlassian Jira
(v8.20.10#820010)