You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Martin Tzvetanov Grigorov (Jira)" <ji...@apache.org> on 2023/01/03 12:33:00 UTC
[jira] [Comment Edited] (AVRO-3695) [Rust] Can't validate schema with value when Nullable union has multiple types.
[ https://issues.apache.org/jira/browse/AVRO-3695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17653979#comment-17653979 ]
Martin Tzvetanov Grigorov edited comment on AVRO-3695 at 1/3/23 12:32 PM:
--------------------------------------------------------------------------
Yes, this issue and AVRO-3646 are related.
I don't consider myself as an authority but the serde(json) crates are pain in the ass :/ I will try to find a workaround for the enum related issues in AVRO-3646 but the behavior of its maintainer is highly demotivating!
was (Author: mgrigorov):
Yes, this issue and AVRO-3646 are related.
I don't consider myself as an authority but the serde(-json) crates are pain in the ass :-/ I will try to find a workaround for the enum related issues in AVRO-3646 but the behavior of its maintainer is highly demotivating!
> [Rust] Can't validate schema with value when Nullable union has multiple types.
> -------------------------------------------------------------------------------
>
> Key: AVRO-3695
> URL: https://issues.apache.org/jira/browse/AVRO-3695
> Project: Apache Avro
> Issue Type: Bug
> Components: rust
> Reporter: Mark Farnan
> Priority: Blocker
> Labels: pull-request-available, rust
> Time Spent: 10m
> Remaining Estimate: 0h
>
> If a union has more than one 'type' (other than null), to_avro_datum is unable to validate the schema with the value type, and throws a validation error.
>
> Schema:
>
> {code:java}
> { "type": "record", "namespace": "datatypes", "name": "nullunion", "fields": [ {"name": "item", "type": [ "null", "long", "double" ] } ] } {code}
>
> Struct: (This was generated by rsgen-avro)
> {code:java}
> /// Auto-generated type for unnamed Avro union variants.
> #[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize)]
> pub enum UnionLongDouble { Long(i64), Double(f64),}
> #[derive(Debug, PartialEq, Clone, serde::Deserialize, serde::Serialize)]
> pub struct NullUnion { pub item: Option<UnionLongDouble>,}{code}
>
> {code:java}
> #[test]
> fn test_multivalue_union_tovalue() {
> let nuschema = r#"
> {
> "type": "record",
> "namespace": "datatypes",
> "name": "nullunion",
> "fields":
> [
> {"name": "item",
> "type": [
> "null",
> "long",
> "double"
> ]
> }
> ]
> }
> "#;
> let nullunion = NullUnion {
> item: Some(UnionLongDouble::Long(34)),
> }; let schema = Schema::parse_str(nuschema).unwrap();
> let nu_value = to_value(nullunion).unwrap();
> let nu_encoded = to_avro_datum(&schema, nu_value).unwrap();
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)