AVRO-4332: [java] Add support for enum default values in IDL serialization - #3822
AVRO-4332: [java] Add support for enum default values in IDL serialization#3822prygunov wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for emitting enum default values when serializing schemas to Avro IDL, with accompanying tests to validate the output.
Changes:
- Update IDL serialization to append
= <default>;after enum definitions when an enum default is present. - Add a unit test to verify enum defaults are (and are not) written to IDL output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lang/java/idl/src/main/java/org/apache/avro/idl/IdlUtils.java | Writes enum defaults into the generated IDL output when present on the schema. |
| lang/java/idl/src/test/java/org/apache/avro/idl/IdlUtilsTest.java | Adds coverage to assert enum default serialization behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@RyanSkraba can you take this to the next RC?) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lang/java/idl/src/test/java/org/apache/avro/idl/IdlUtilsTest.java:117
- The PR description says the test also verifies that an enum schema without a default value is unaffected (no "=") but the current test only covers the "with default" case. To avoid regressions (e.g., always emitting "= ..." or a stray "="), add a negative assertion (or a second test) for an enum created without a default, or update the PR description to match what is actually tested.
@Test
public void enumDefaultIsWrittenToIdl() throws IOException {
Schema withDefault = Schema.createEnum("Status", null, "naming", asList("ACTIVE", "INACTIVE"), "ACTIVE");
StringWriter withDefaultWriter = new StringWriter();
IdlUtils.writeIdlProtocol(withDefaultWriter, withDefault);
assertTrue(withDefaultWriter.toString().contains("} = ACTIVE;"),
"Enum with default should serialize default value");
}
|
Hi @prygunov, sorry for taking so long to review this — thanks for the fix and for your patience. The change is correct and a clear improvement. The writer was asymmetric with A couple of things before we can merge:
Thanks again! |
What is the purpose of the change
This pull request fixes a bug in IdlUtils.writeSchema where enum schemas with a default value would silently lose that default when serialized to IDL format. As a result, round-tripping a schema through IDL would drop the enum default.
Verifying this change
Added enumDefaultIsWrittenToIdl test in IdlUtilsTest that:
Documentation