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

codegen: Getters for collection fields no longer return unmodifiable collection #526

Merged
merged 14 commits into from
Feb 20, 2024

Conversation

li-ukumar
Copy link
Member

What

Constructs and returns List and Map views for simple collections, i.e. List and Map<String, String>

Why

The codegen utilizes List and Map Transformers which return Unmodifiable collections as the field in object are of type Utf8 and return types from getter can be String.
Users might want to modify the object instance directly and make sure it reflects in the original object instance.

Test

Added Unit tests

@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2024

Codecov Report

Attention: 122 lines in your changes are missing coverage. Please review.

Comparison is base (e2849e7) 46.13% compared to head (eac5326) 46.15%.
Report is 4 commits behind head on master.

Files Patch % Lines
...tibility/collectiontransformer/MapTransformer.java 40.42% 24 Missing and 4 partials ⚠️
...ibility/collectiontransformer/ListTransformer.java 51.02% 22 Missing and 2 partials ⚠️
...ity/collectiontransformer/CharSequenceMapView.java 61.76% 10 Missing and 3 partials ⚠️
...atibility/collectiontransformer/StringMapView.java 61.76% 10 Missing and 3 partials ⚠️
...avroutil1/codegen/SpecificRecordGeneratorUtil.java 42.85% 7 Missing and 5 partials ⚠️
...ty/collectiontransformer/CharSequenceListView.java 38.88% 11 Missing ⚠️
...tibility/collectiontransformer/StringListView.java 38.88% 11 Missing ⚠️
...patibility/collectiontransformer/Utf8ListView.java 53.84% 6 Missing ⚠️
...llectiontransformer/CollectionTransformerUtil.java 60.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #526      +/-   ##
============================================
+ Coverage     46.13%   46.15%   +0.02%     
- Complexity     4544     4613      +69     
============================================
  Files           407      412       +5     
  Lines         28426    28681     +255     
  Branches       4639     4685      +46     
============================================
+ Hits          13114    13238     +124     
- Misses        13740    13861     +121     
- Partials       1572     1582      +10     

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

Comment on lines +263 to +266
return ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().isPrimitive()
|| ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().isPrimitive();
Copy link
Collaborator

@dg-builder dg-builder Feb 16, 2024

Choose a reason for hiding this comment

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

Looks like the order of operations is OK here, but better to make it clearer IMO https://stackoverflow.com/a/2263692

Suggested change
return ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().isPrimitive()
|| ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().isPrimitive();
bool isUnionOfNullAndPrimitive = ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().isPrimitive();
bool isUnionOfPrimitiveAndNull = ((AvroUnionSchema) schema).getTypes().get(1).getSchema().type().equals(AvroType.NULL)
&& ((AvroUnionSchema) schema).getTypes().get(0).getSchema().type().isPrimitive();
return isUnionOfNullAndPrimitive || isUnionOfPrimitiveAndNull;

@li-ukumar li-ukumar marked this pull request as ready for review February 16, 2024 00:35
@li-ukumar li-ukumar merged commit 2fd93ac into master Feb 20, 2024
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.

5 participants