Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix complex default conversion - handle list #522

Merged
merged 6 commits into from
Nov 5, 2023

Conversation

dg-builder
Copy link
Collaborator

@dg-builder dg-builder commented Nov 3, 2023

FieldBuilder19, FieldBuilder110, FieldBuilder111 handle conversion of default values into "acceptable" default values. However, this conversion wasn't handling default values that were non-empty lists.

Added UTs to test this case.

More details on this method in the java doc:

  /**
   * we want to be very generous with what we let users provide for default values.
   * sadly, (modern) avro can only handle specific classes/collections/primitive-wrappers
   * (see org.apache.avro.util.internal.JacksonUtils.toJson(Object, JsonGenerator) in 1.9+)
   * @param mightNotBeFriendly a proposed field default value that might originate from
   *                           a call like AvroCompatibilityHelper.getGenericDefaultValue()
   * @return a representation of the input that avro likes for use as a field default value
   */

@dg-builder dg-builder changed the title Dg/fix complex defaults fix complex default conversion - handle list/map Nov 3, 2023
@dg-builder dg-builder changed the title fix complex default conversion - handle list/map fix complex default conversion - handle list Nov 3, 2023
@dg-builder dg-builder marked this pull request as ready for review November 3, 2023 20:05
@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cd17a70) 45.78% compared to head (0e048de) 45.81%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #522      +/-   ##
============================================
+ Coverage     45.78%   45.81%   +0.02%     
- Complexity     4444     4445       +1     
============================================
  Files           403      403              
  Lines         28070    28091      +21     
  Branches       4622     4628       +6     
============================================
+ Hits          12853    12871      +18     
+ Misses        13664    13663       -1     
- Partials       1553     1557       +4     
Files Coverage Δ
...routil1/compatibility/avro110/FieldBuilder110.java 83.33% <100.00%> (+1.51%) ⬆️
...routil1/compatibility/avro111/FieldBuilder111.java 77.38% <100.00%> (+2.05%) ⬆️
...avroutil1/compatibility/avro19/FieldBuilder19.java 83.33% <100.00%> (+1.51%) ⬆️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

FieldBuilder builder = AvroCompatibilityHelper.newField(field);
builder.setDefault(defaultValue);
Schema.Field resField = builder.build();
Assert.assertNotNull(resField.defaultVal());
Copy link
Member

Choose a reason for hiding this comment

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

Add an assertEquals test as well

Copy link
Collaborator Author

@dg-builder dg-builder Nov 5, 2023

Choose a reason for hiding this comment

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

The assert isn't the essential part of the test. The essential part is that .build() doesn't fail. Added a comment in the code

@dg-builder dg-builder merged commit b08911b into master Nov 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants