GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Datastore: expose serializedSize for Entity. by suraj-qlogic · Pull Request #6842 · googleapis/google-cloud-java Conversation
Contributor
Fixes #6389
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
elharo
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Returns the number of bytes in the serialized protobuf." Is this definitely a fixed and reproducible value for a given protobuf?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,Once build it would be fixed number.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this really throw exception?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No,This method does not throw exception.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the cost of calculating this for a large entity? Most of the time we don't need this value. Perhaps this could be done in demand and not stored or only lazily stored in the field?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cost could be varied it depends on user entered properties. Does this look fine? /** Returns the number of bytes in the serialized protobuf. */ public int getSerializedSize() { if (serializedSize == 0) { serializedSize = this.toPb().getSerializedSize(); } return serializedSize; } Here we are calculating entity size when demand.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@ ## master #6842 +/- ## ============================================= - Coverage 45.72% 45.28% -0.45% + Complexity 26528 6251 -20277 ============================================= Files 2615 453 -2162 Lines 282766 56282 -226484 Branches 32745 7229 -25516 ============================================= - Hits 129299 25486 -103813 + Misses 143350 29140 -114210 + Partials 10117 1656 -8461
Continue to review full report at Codecov.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've spent some time thinking about this and I feel like this is more of a utility method than a property of the entity. Entities are immutable, but in order to not incur a penalty of adding making size available serializedSize would need to be non-final which opens up other issues.
Instead of this being a field with a getter, can you add a new static method to com.google.cloud.datastore.Entity:
public static int calculateSerializedSize(BaseEntity<? extends IncompleteKey> e) { return e.toPb().getSerializedSize(); }
This way we don't impose a penalty to those users that don't need this operation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return new Builder().fill(entityPb).build(); | ||
| } | ||
|
|
||
| public static int calculateSerializedSize(BaseEntity<? extends IncompleteKey> e) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add a javadoc comment to explain the usage of this method (and to help people find it when they google for this type of thing).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /** | ||
| * Returns the serialized protobuf size of provided entity object. | ||
| * | ||
| * @param entity entity object to calculate serialize size. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
"object whose size is measured"
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| checkNotNull(e); | ||
| return e.toPb().getSerializedSize(); | ||
| /** | ||
| * Returns the serialized protobuf size of provided entity object. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
"Returns the size in bytes of the protobuf form of the provided entity."
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* determine entity size using api * organize individual import * updated code * update code for testcase * fix review changes * fix review changes * fix review changes
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
datastore: determine entity size using api
There was an error while loading. Please reload this page.