GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Datastore: expose serializedSize for Entity. by suraj-qlogic · Pull Request #6842 · googleapis/google-cloud-java

Conversation

@suraj-qlogic

@suraj-qlogic suraj-qlogic commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

Fixes #6389

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
suraj-qlogic added 4 commits November 20, 2019 13:04
@suraj-qlogic
determine entity size using api
19e4971
@suraj-qlogic
organize individual import
f1fc019
@suraj-qlogic
updated code
6371906
@suraj-qlogic
update code for testcase
9b5f0b7
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 20, 2019
@elharo elharo added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 20, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 20, 2019
elharo
elharo reviewed Nov 20, 2019
View reviewed changes
Comment thread ...loud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java Outdated
return properties;
}

/** Returns the entity size. */

@elharo elharo Nov 20, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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

@suraj-qlogic suraj-qlogic Nov 20, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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
Comment thread ...loud-clients/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityTest.java Outdated
}

@Test
public void testEntitySize() throws Exception {

@elharo elharo Nov 20, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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

@suraj-qlogic suraj-qlogic Nov 20, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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
Comment thread ...loud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java Outdated
BaseEntity(Builder<K, ?> builder) {
this.key = builder.key;
this.properties = ImmutableSortedMap.copyOf(builder.properties);
this.serializedSize = this.toPb().getSerializedSize();

@elharo elharo Nov 20, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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

@suraj-qlogic suraj-qlogic Nov 20, 2019

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The 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
@codecov

codecov Bot commented Nov 20, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #6842 into master will decrease coverage by 0.44%.
The diff coverage is 100%.

Impacted file tree graph

@@              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
Impacted Files Coverage Δ Complexity Δ
...c/main/java/com/google/cloud/datastore/Entity.java 76.92% <100%> (+1.92%) 7 <1> (+1) ⬆️
.../cloud/datastore/testing/LocalDatastoreHelper.java 80.59% <0%> (-4.48%) 17% <0%> (ø)
...main/java/com/google/cloud/storage/BucketInfo.java 81.04% <0%> (-1.96%) 84% <0%> (ø)
...gle/cloud/bigtable/data/v2/BigtableDataClient.java 89.58% <0%> (-1.91%) 32% <0%> (ø)
...eas/src/main/java/io/grafeas/v1/GrafeasClient.java 61.63% <0%> (-1.47%) 59% <0%> (+14%)
...anner/jdbc/ClientSideStatementValueConverters.java 92.22% <0%> (-1.04%) 0% <0%> (ø)
...ogle/cloud/spanner/jdbc/ReadOnlyStalenessUtil.java 70.27% <0%> (-0.97%) 25% <0%> (ø)
...le/cloud/storage/contrib/nio/CloudStoragePath.java 75.67% <0%> (-0.69%) 51% <0%> (ø)
...le/cloud/spanner/jdbc/JdbcSqlExceptionFactory.java 45.71% <0%> (-0.67%) 7% <0%> (ø)
...ery/datatransfer/v1/DataTransferServiceClient.java 65.35% <0%> (-0.51%) 55% <0%> (+13%)
... and 2320 more

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 5a2c0ae...2693e5f. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pmakani
pmakani requested a review from BenWhitehead November 21, 2019 05:14
BenWhitehead
BenWhitehead suggested changes Nov 21, 2019
View reviewed changes

@BenWhitehead BenWhitehead left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@suraj-qlogic
fix review changes
66aae6f
@pmakani pmakani added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 22, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 22, 2019
BenWhitehead
BenWhitehead suggested changes Nov 22, 2019
View reviewed changes
Comment thread ...le-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java Outdated
return new Builder().fill(entityPb).build();
}

public static int calculateSerializedSize(BaseEntity<? extends IncompleteKey> e) {

@BenWhitehead BenWhitehead Nov 22, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@suraj-qlogic
suraj-qlogic requested a review from elharo November 25, 2019 06:50
@suraj-qlogic
fix review changes
3117897
elharo
elharo reviewed Nov 25, 2019
View reviewed changes
Comment thread ...le-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java Outdated
/**
* Returns the serialized protobuf size of provided entity object.
*
* @param entity entity object to calculate serialize size.

@elharo elharo Nov 25, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...le-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java Outdated
checkNotNull(e);
return e.toPb().getSerializedSize();
/**
* Returns the serialized protobuf size of provided entity object.

@elharo elharo Nov 25, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@suraj-qlogic
fix review changes
2693e5f
@suraj-qlogic
suraj-qlogic requested review from BenWhitehead and elharo November 25, 2019 14:01
BenWhitehead
BenWhitehead approved these changes Nov 25, 2019
View reviewed changes
@BenWhitehead BenWhitehead added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 25, 2019
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 25, 2019
@BenWhitehead
BenWhitehead merged commit 88c48ef into googleapis:master Nov 25, 2019
This was referenced Dec 4, 2019
Release google-cloud-java v0.120.0 #6986
Closed
Release google-cloud-java v0.120.0 #6988
Merged
chingor13 pushed a commit that referenced this pull request Jan 22, 2026
@suraj-qlogic @BenWhitehead
Datastore: expose serializedSize for Entity. (#6842)
b758d91
* determine entity size using api

* organize individual import

* updated code

* update code for testcase

* fix review changes

* fix review changes

* fix review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@elharo elharo Awaiting requested review from elharo
1 more reviewer
@BenWhitehead BenWhitehead BenWhitehead approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

datastore: determine entity size using api

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@suraj-qlogic @elharo @BenWhitehead @googlebot @pmakani @yoshi-kokoro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.