8000 Added specific record tests for primitive arrays. by FelixGV · Pull Request #81 · linkedin/avro-util · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added specific record tests for primitive arrays. #81

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

Merged
merged 2 commits into from
Jul 23, 2020

Conversation

FelixGV
Copy link
Collaborator
@FelixGV FelixGV commented Jul 22, 2020

Addressed bugs related to missing constructors in the PrimitiveArrayList
and its child classes. Also refactored those classes slightly to reduce
boilerplate.

Altered the meta code:

  • List construction does not rely on Collections.emptyList() since that
    is incompatible with the primitive list classes.
  • Added a missing getShouldRead() check in cases where schema evolution
    gets rid of a list field. This would previously cause a NPE during
    code gen.

FelixGV added a commit to FelixGV/avro-util that referenced this pull request Jul 22, 2020
@codecov-commenter
Copy link
codecov-commenter commented Jul 22, 2020

Codecov Report

Merging #81 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #81   +/-   ##
=========================================
  Coverage     53.52%   53.52%           
  Complexity      275      275           
=========================================
  Files            39       39           
  Lines          1659     1659           
  Branches        206      206           
=========================================
  Hits            888      888           
  Misses          689      689           
  Partials         82       82           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce0f422...22efffc. Read the comment docs.

@@ -87,7 +87,7 @@ public StringableRecord_SpecificDeserializer_6174384286732341990_617438428673234
chunkLen0 = (decoder.arrayNext());
} while (chunkLen0 > 0);
} else {
urlArray0 = Collections.emptyList();
urlArray0 = new ArrayList<Utf8>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - initial size 1?

Copy link
Collaborator

Choose a reason for hiding this comment

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

why not 0 since it's always an empty ArrayList? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't really like the structure of that generated code, and I was meaning to tweak it anyway at some point... so might as well do it now.

@@ -144,6 +146,9 @@
} catch (JClassAlreadyExistsException e) {
throw new FastDeserializerGeneratorException("Class: " + className + " already exists");
} catch (Exception e) {
LOGGER.error("Failed to generate a deserializer.");
Copy link
Contributor

Choose a reason for hiding this comment

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

better to have this as a single line (maybe with \n) because in a busy system other prints can get injected in the middle on the log file

Copy link
Contributor

Choose a reason for hiding this comment

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

also - use {} and dont call toString() (less important for error, but still)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We do not need to log here since the FastDeserializerGeneratorException would be catched in upper layer buildGeneric/SpecificDeserializer and schemas would be logged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm... I think the thing is that we have test code that invokes this function directly, and therefore does not benefit from the upstream logging that happens in the main code. I will remove those extra logs then.

@@ -662,10 +667,8 @@ private void processArray(JVar arraySchemaVar, final String name, final Schema a
}
doLoop.body().assign(chunkLen, JExpr.direct(DECODER + ".arrayNext()"));
}, else1 -> {
if (useGenericTypes) {
if (finalAction.getShouldRead()) {
else1.assign(arrayVar, finalNewArrayExp);
Copy link
Contributor

Choose a reason for hiding this comment

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

this generates an arraylist of size 10, i think it should make it smaller (since its always empty here)

Copy link
Collaborator
@volauvent volauvent left a comment

Choose a reason for hiding this comment

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

LGTM. Several minor suggestions.

@@ -87,7 +87,7 @@ public StringableRecord_SpecificDeserializer_6174384286732341990_617438428673234
chunkLen0 = (decoder.arrayNext());
} while (chunkLen0 > 0);
} else {
urlArray0 = Collections.emptyList();
urlArray0 = new ArrayList<Utf8>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not 0 since it's always an empty ArrayList? :)

@@ -144,6 +146,9 @@
} catch (JClassAlreadyExistsException e) {
throw new FastDeserializerGeneratorException("Class: " + className + " already exists");
} catch (Exception e) {
LOGGER.error("Failed to generate a deserializer.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

We do not need to log here since the FastDeserializerGeneratorException would be catched in upper layer buildGeneric/SpecificDeserializer and schemas would be logged?

@@ -350,6 +350,54 @@
}
},
"default": {"test": [null]}
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

No code-gen results for these new fields in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, we currently don't add this to the codegen directory. Only some of the tests are put in there. Perhaps those should be added...

FelixGV added 2 commits July 23, 2020 14:26
Addressed bugs related to missing constructors in the PrimitiveArrayList
and its child classes. Also refactored those classes slightly to reduce
boilerplate.

Altered the meta code:

- List construction does not rely on Collections.emptyList() since that
  is incompatible with the primitive list classes.
- Fixed a case where list instantiation wasn't guarded by getShouldRead(),
  when schema evolution gets rid of a list field. This would previously
  cause a NPE during code gen.
- Refactored the list handling code so that list instance reuse occurs
  even though the particular payload being deserialized has zero elements.
@FelixGV FelixGV force-pushed the specific_record_array_tests branch from 79ff2d5 to 22efffc Compare July 23, 2020 21:32

ifCodeGen(parentBody, chunkLengthGreaterThanZero, then1 -> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: this looks like a big change but it's mostly just a move and an indentation change. The list instantiation (and potential reuse) now happens first, and the if chunk length > 0 check as well as its else block is now removed. Then most of the remaining code is just an indentation change...

@FelixGV FelixGV merged commit 5469e25 into linkedin:master Jul 23, 2020
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.

4 participants
0