[
https://issues.apache.org/jira/browse/AVRO-3955?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17823290#comment-17823290
]
ASF subversion and git services commented on AVRO-3955:
-------------------------------------------------------
Commit 3c11f89c3cb8754f0ca977c06368c21c81ce19a8 in avro's branch
refs/heads/main from Florentin DUBOIS
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=3c11f89c3 ]
AVRO-3955: [Rust] allow deserializer to decode enum string (#2785)
* See https://issues.apache.org/jira/browse/AVRO-3955
Signed-off-by: Florentin Dubois <[email protected]>
> [Rust] unable to decode string enum from avro encoded data
> ----------------------------------------------------------
>
> Key: AVRO-3955
> URL: https://issues.apache.org/jira/browse/AVRO-3955
> Project: Apache Avro
> Issue Type: Bug
> Components: rust
> Affects Versions: 1.11.3
> Reporter: Florentin
> Priority: Minor
> Labels: pull-request-available
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Following the below example, the Rust crate of apache-avro is unable to
> decode a previously encoded value that contains a string enum.
>
> ```rust
> #[derive(PartialEq, Eq, Serialize, Deserialize, Debug)]
> pub struct StringEnum {
> pub source: String,
> }
> #[test]
> fn avro_xxxx_decode_enum() {
> let schema_content = r#"
> {
> "name": "AccessLog",
> "namespace": "com.clevercloud.accesslogs.common.avro",
> "type": "record",
> "fields": [
> {
> "name": "source",
> "type": {
> "type": "enum",
> "name": "SourceType",
> "items": "string",
> "symbols": ["SOZU", "HAPROXY", "HAPROXY_TCP"]
> }
> }
> ]
> }
> "#;
> let schema = crate::Schema::parse_str(schema_content).unwrap();
> let data = StringEnum \{ source: "SOZU".to_string() };
> // encode into avro
> let value = crate::to_value(&data).unwrap();
> let mut buf = std::io::Cursor::new(crate::to_avro_datum(&schema,
> value).unwrap());
> // decode from avro
> let value = crate::from_avro_datum(&schema, &mut buf, None).unwrap();
> let decoded_data: StringEnum = crate::from_value(&value).unwrap();
> // :arrow_double_up: throw => Failed to deserialize Avro value into
> value: Expected a String|Bytes|Fixed|Uuid|Union, but got Enum(0, "SOZU")
> assert_eq!(decoded_data, data);
> }
> ```
--
This message was sent by Atlassian Jira
(v8.20.10#820010)