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

ASF subversion and git services commented on AVRO-3674:
-------------------------------------------------------

Commit 81920d7b87f73fecd314bbc161a0fbcec18c9b80 in avro's branch 
refs/heads/dependabot/maven/lang/java/org.apache.thrift-libthrift-0.17.0 from 
Martin Grigorov
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=81920d7b8 ]

AVRO-3674: [Rust] Pass the correct enclosing namespace when validating and 
resolving (#1971)

* Add namespace resolution test-case

Added a test-case to reproduce failure to resolve enum definitions when
namespaces are used.

* AVRO-3674: Attempt to implement fix for schema validation

* AVRO-3674: Fix the build for Rust 1.54 (MSRV)

Add support for all named schema types

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

* AVRO-3674: Pass the correct enclosing namespace to validate and 
resolve_internal

Expose getters for Schema's name and namespace

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Co-authored-by: Rik Heijdens <[email protected]>

> Value::Record containing enums fail to validate when using namespaces in 
> Schema
> -------------------------------------------------------------------------------
>
>                 Key: AVRO-3674
>                 URL: https://issues.apache.org/jira/browse/AVRO-3674
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>            Reporter: Rik Heijdens
>            Assignee: Martin Tzvetanov Grigorov
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.12.0, 1.11.2
>
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> Consider the following schema:
> {noformat}
> {
>     "type": "record",
>     "name": "NamespacedMessage",
>     "namespace": "com.domain",
>     "fields": [
>         {
>             "type": "record",
>             "name": "field_a",
>             "fields": [
>                 {
>                     "name": "enum_a",
>                     "type": {
>                         "type": "enum",
>                         "name": "EnumType",
>                         "symbols": [
>                             "SYMBOL_1",
>                             "SYMBOL_2"
>                         ],
>                         "default": "SYMBOL_1"
>                     }
>                 },
>                 {
>                     "name": "enum_b",
>                     "type": "EnumType"
>                 }
>             ]
>         }
>     ]
> }{noformat}
> I might represent this in Rust using the following structs:
> {noformat}
> #[derive(Serialize)]
> enum EnumType {
>     #[serde(rename = "SYMBOL_1")]
>     Symbol1,
>     #[serde(rename = "SYMBOL_2")]
>     Symbol2,
> }
> #[derive(Serialize)]
> struct FieldA {
>     enum_a: EnumType,
>     enum_b: EnumType,
> }
> #[derive(Serialize)]
> struct NamespacedMessage {
>     field_a: FieldA,
> }
> let msg = NamespacedMessage {
>     field_a: FieldA {
>         enum_a: EnumType::Symbol2,
>         enum_b: EnumType::Symbol1,
>     },
> };
> {noformat}
> and then serialize this into a `Value` using the following logic:
> {noformat}
> let mut ser = Serializer::default();
> let test_value: Value = msg.serialize(&mut ser).unwrap();
> {noformat}
> After serializing into `test_value` I would expect that 
> `test_value.validate(&schema)` yields True. However this is not the case.
> I can work around it by removing the `namespace` definition from my schema 
> which allows the validation to proceed.
> I believe the cause of schema validation failure is [this lookup 
> failing](https://github.com/apache/avro/blob/release-1.11.1-rc1/lang/rust/avro/src/types.rs#L370)
>  when schemas are utilized as the `Value` will not have a namespace 
> associated with it.
> I believe this could be fixed by altering `validate_internal` to accept an 
> optional namespace that is derived from the provided schema to `validate`. 
> However, I'm not sure if this is an appropriate fix.



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

Reply via email to