Skip to content

AVRO-3646: integration tests for (de)serializing of enum with mixed variants - #1949

Merged
martin-g merged 8 commits into
apache:avro-3646-serde-for-enum-mixed-variantsfrom
LucasJavaudin:mixed_enum
Nov 11, 2022
Merged

martin-g merged 8 commits into
apache:avro-3646-serde-for-enum-mixed-variantsfrom
LucasJavaudin:mixed_enum

Conversation

@LucasJavaudin

Copy link
Copy Markdown
Contributor

What is the purpose of the change

This pull request adds two integration tests to assess the changes of #1921:

  • (De)serialization of an enum with mixed variants (Null, new type, tuple and struct): serde_enum.
  • (De)serialization of an enum with mixed and duplicate variants: serde_enum_with_duplicates.

Verifying this change

The two integration tests do not pass for multiple reasons:

  • The serialized values do not validate the defined schema.
  • The type value for the tuple variant is serialized as an Array of Union instead as an Union of Array.
  • With duplicate variants, the index in the type union is not valid (because there is no duplicate in the union defined by the schema).

Documentation

  • Does this pull request introduce a new feature? no

@github-actions github-actions Bot added the build label Nov 11, 2022
Rename the test method to be different than the one in serde_enum.rs IT
tests.

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
enum TestEnum {
NullVariant1,
NullVariant2,

@martin-g martin-g Nov 11, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both NullVariant1 and NullVariant2 are serialized to Value::Null.
According to the Avro specification there could be one value of a given type in an union:

Unions may not contain more than one schema with the same type, except for the named types record, fixed and enum.

So, it is not possible to have two null variants, no matter whether they are an unit, a tuple, a newtype, a struct or a mix of them.

NullNewTypeVariant(()),
NullStructVariant {},
IntVariant1(i64),
IntVariant2(i64),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here - two Value::Long in a Union.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4f710dd removes the duplicates and fixes the Avro schema for the test. Now it passes!
But I think we should merge serde_enum.rs and serde_enum_with_duplicates.rs and remove one of the files.

A Union could have at most one item for a primitive type

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

Copy link
Copy Markdown
Member

I'm going to merge this PR and do the cleanup in #1921

@martin-g
martin-g merged commit 1cc4260 into apache:avro-3646-serde-for-enum-mixed-variants Nov 11, 2022
martin-g added a commit that referenced this pull request Feb 9, 2023
…ariants (#1949)

* AVRO-3646: Add a test that (de)serialize a enum with mixed variants

* AVRO-3646: Add a test that (de)serialize a enum w/ duplicates variants

* Enable PR checks for all PRs, not just the ones against master

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

* AVRO-3646: Fix a clippy error about enum variant being postfixed with 'Variant'

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

* AVRO-3646: Fix the serialization (X -> types::Value) for enum tuple variants

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

* AVRO-3646: Fix the name of the enum variants in the Avro schema

Rename the test method to be different than the one in serde_enum.rs IT
tests.

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

* AVRO-3646: Remove the duplicates to conform to Avro specification

A Union could have at most one item for a primitive type

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

* AVRO-3646: Remove dbg!() statement. Fix clippy errors

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

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Co-authored-by: LucasJavaudin <[email protected]>
Co-authored-by: Martin Tzvetanov Grigorov <[email protected]>
martin-g added a commit that referenced this pull request Feb 9, 2023
…ariants (#1949)

* AVRO-3646: Add a test that (de)serialize a enum with mixed variants

* AVRO-3646: Add a test that (de)serialize a enum w/ duplicates variants

* Enable PR checks for all PRs, not just the ones against master

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

* AVRO-3646: Fix a clippy error about enum variant being postfixed with 'Variant'

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

* AVRO-3646: Fix the serialization (X -> types::Value) for enum tuple variants

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

* AVRO-3646: Fix the name of the enum variants in the Avro schema

Rename the test method to be different than the one in serde_enum.rs IT
tests.

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

* AVRO-3646: Remove the duplicates to conform to Avro specification

A Union could have at most one item for a primitive type

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

* AVRO-3646: Remove dbg!() statement. Fix clippy errors

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

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Co-authored-by: LucasJavaudin <[email protected]>
Co-authored-by: Martin Tzvetanov Grigorov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants