From 54b6848ab5e1ca93931ab0ff0911c106b53a6db6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 16:43:52 +0000 Subject: [PATCH 1/4] Add getDataSize() to DocumentSnapshot This method calculates and returns the total size of the data stored in the DocumentSnapshot in bytes. - Iterates through the protobuf `Value` messages in the `fields` map. - Sums the `getSerializedSize()` of each `Value`. - Returns 0 if the document does not exist (fields is null). --- .../cloud/firestore/DocumentSnapshot.java | 17 +++++++++++++++++ .../com/google/cloud/firestore/QueryTest.java | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java index e1aab1cac..ac17b4520 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentSnapshot.java @@ -468,4 +468,21 @@ public String toString() { "%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}", getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime); } + + /** + * Returns the size of the data in this snapshot in bytes. + * + * @return The size of the data in bytes. + */ + public int getDataSize() { + if (fields == null) { + return 0; + } + + int totalSize = 0; + for (Value value : fields.values()) { + totalSize += value.getSerializedSize(); + } + return totalSize; + } } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index 78591cdda..eaedc3339 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -1521,4 +1521,23 @@ public void inequalityFiltersImplicitlyOrderedLexicographicallyWithExplicitOrder assertEquals(orderFields, query_.createImplicitOrderBy()); } + + @Test + public void documentSnapshotGetDataSize() { + // Test with an existing document + DocumentSnapshot snapshot = SINGLE_FIELD_SNAPSHOT; + int expectedSize = 0; + for (Value value : snapshot.getProtoFields().values()) { + expectedSize += value.getSerializedSize(); + } + assertEquals(expectedSize, snapshot.getDataSize()); + + // Test with a non-existent document + DocumentSnapshot missingSnapshot = + DocumentSnapshot.fromMissing( + firestoreMock, + firestoreMock.document("coll/doc"), + Timestamp.now()); + assertEquals(0, missingSnapshot.getDataSize()); + } } From 95b91d973959318b5e4974864638727642a35f21 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Tue, 1 Jul 2025 16:47:01 +0000 Subject: [PATCH 2/4] chore: generate libraries at Tue Jul 1 16:44:53 UTC 2025 --- README.md | 2 +- .../src/test/java/com/google/cloud/firestore/QueryTest.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58ad85428..c2d03a708 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies: com.google.cloud google-cloud-firestore - 3.31.6 + 3.31.7 ``` diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index eaedc3339..1ec54ffc6 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -1535,9 +1535,7 @@ public void documentSnapshotGetDataSize() { // Test with a non-existent document DocumentSnapshot missingSnapshot = DocumentSnapshot.fromMissing( - firestoreMock, - firestoreMock.document("coll/doc"), - Timestamp.now()); + firestoreMock, firestoreMock.document("coll/doc"), Timestamp.now()); assertEquals(0, missingSnapshot.getDataSize()); } } From 55956a6bcd59f35070849db84418e5594ad7d1ae Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 22:55:22 +0000 Subject: [PATCH 3/4] Add getDataSize to DocumentSnapshot This method calculates and returns the total size of the data stored in the DocumentSnapshot in bytes. - Iterates through the protobuf `Value` messages in the `fields` map. - Sums the `getSerializedSize()` of each `Value`. - Returns 0 if the document does not exist (fields is null). Split the test case for `getDataSize` into two separate tests for existing and non-existent documents as per review feedback. --- README.md | 2 +- .../java/com/google/cloud/firestore/QueryTest.java | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c2d03a708..58ad85428 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies: com.google.cloud google-cloud-firestore - 3.31.7 + 3.31.6 ``` diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index 1ec54ffc6..f40a4007e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -1523,19 +1523,22 @@ public void inequalityFiltersImplicitlyOrderedLexicographicallyWithExplicitOrder } @Test - public void documentSnapshotGetDataSize() { - // Test with an existing document + public void documentSnapshotGetDataSize_existingDocument() { DocumentSnapshot snapshot = SINGLE_FIELD_SNAPSHOT; int expectedSize = 0; for (Value value : snapshot.getProtoFields().values()) { expectedSize += value.getSerializedSize(); } assertEquals(expectedSize, snapshot.getDataSize()); + } - // Test with a non-existent document + @Test + public void documentSnapshotGetDataSize_nonExistentDocument() { DocumentSnapshot missingSnapshot = DocumentSnapshot.fromMissing( - firestoreMock, firestoreMock.document("coll/doc"), Timestamp.now()); + firestoreMock, + firestoreMock.document("coll/doc"), + Timestamp.now()); assertEquals(0, missingSnapshot.getDataSize()); } } From 327daafc19676ea343aacd9b6276a7870287bb59 Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Tue, 1 Jul 2025 22:58:53 +0000 Subject: [PATCH 4/4] chore: generate libraries at Tue Jul 1 22:55:47 UTC 2025 --- README.md | 2 +- .../src/test/java/com/google/cloud/firestore/QueryTest.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58ad85428..c2d03a708 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies: com.google.cloud google-cloud-firestore - 3.31.6 + 3.31.7 ``` diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index f40a4007e..e20a160d8 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -1536,9 +1536,7 @@ public void documentSnapshotGetDataSize_existingDocument() { public void documentSnapshotGetDataSize_nonExistentDocument() { DocumentSnapshot missingSnapshot = DocumentSnapshot.fromMissing( - firestoreMock, - firestoreMock.document("coll/doc"), - Timestamp.now()); + firestoreMock, firestoreMock.document("coll/doc"), Timestamp.now()); assertEquals(0, missingSnapshot.getDataSize()); } }