Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.31.0')
implementation platform('com.google.cloud:libraries-bom:26.33.0')

implementation 'com.google.cloud:google-cloud-datastore'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-datastore:2.18.3'
implementation 'com.google.cloud:google-cloud-datastore:2.18.4'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.3"
libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.4"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -380,7 +380,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-datastore/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-datastore.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.3
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.4
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
import com.google.cloud.datastore.AggregationResult;
import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.Datastore.TransactionCallable;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Entity;
import com.google.cloud.datastore.EntityQuery;
import com.google.cloud.datastore.GqlQuery;
import com.google.cloud.datastore.Key;
import com.google.cloud.datastore.Query;
import com.google.cloud.datastore.QueryResults;
import com.google.cloud.datastore.Transaction;
import com.google.cloud.datastore.testing.RemoteDatastoreHelper;
import com.google.common.collect.ImmutableList;
import com.google.datastore.v1.TransactionOptions;
import com.google.datastore.v1.TransactionOptions.ReadOnly;
Expand All @@ -41,24 +43,18 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.AfterClass;
import org.junit.Test;

// TODO(jainsahab) Move all the aggregation related tests from ITDatastoreTest to this file
public class ITDatastoreAggregationsTest {

@ClassRule public static MultiDbRule multiDbRule = new MultiDbRule();

private static Datastore DATASTORE;
private static final RemoteDatastoreHelper HELPER = RemoteDatastoreHelper.create();
private static final DatastoreOptions OPTIONS = HELPER.getOptions();
private static final Datastore DATASTORE = OPTIONS.getService();

private static final String KIND = "Marks";

@BeforeClass
public static void beforeClass() throws Exception {
DATASTORE = multiDbRule.getDatastore();
}

@After
public void tearDown() {
EntityQuery allEntitiesQuery = Query.newEntityQueryBuilder().build();
Expand All @@ -68,6 +64,11 @@ public void tearDown() {
DATASTORE.delete(keysToDelete);
}

@AfterClass
public static void afterClass() throws Exception {
DATASTORE.close();
}

Key key1 = DATASTORE.newKeyFactory().setKind(KIND).newKey(1);
Key key2 = DATASTORE.newKeyFactory().setKind(KIND).newKey(2);
Key key3 = DATASTORE.newKeyFactory().setKind(KIND).newKey(3);
Expand All @@ -88,6 +89,7 @@ public void testSumAggregation() {
Query.newAggregationQueryBuilder()
.over(baseQuery)
.addAggregations(sum("marks").as("total_marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// sum of 2 entities
Expand All @@ -106,7 +108,11 @@ public void testSumAggregationWithAutoGeneratedAlias() {

EntityQuery baseQuery = Query.newEntityQueryBuilder().setKind(KIND).build();
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder().over(baseQuery).addAggregations(sum("marks")).build();
Query.newAggregationQueryBuilder()
.over(baseQuery)
.addAggregations(sum("marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// sum of 2 entities
assertThat(getOnlyElement(DATASTORE.runAggregation(aggregationQuery)).getLong("property_1"))
Expand All @@ -127,7 +133,11 @@ public void testSumAggregationInGqlQuery() {
"AGGREGATE SUM(marks) AS total_marks OVER (SELECT * FROM Marks)")
.build();

AggregationQuery aggregationQuery = Query.newAggregationQueryBuilder().over(gqlQuery).build();
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.over(gqlQuery)
.setNamespace(OPTIONS.getNamespace())
.build();

// sum of 2 entities
assertThat(getOnlyElement(DATASTORE.runAggregation(aggregationQuery)).getLong("total_marks"))
Expand All @@ -148,6 +158,7 @@ public void testSumAggregationWithResultOfDoubleType() {
Query.newAggregationQueryBuilder()
.over(baseQuery)
.addAggregations(sum("cgpa").as("total_cgpa"))
.setNamespace(OPTIONS.getNamespace())
.build();

// sum of 2 entities
Expand All @@ -169,6 +180,7 @@ public void testAvgAggregation() {
Query.newAggregationQueryBuilder()
.over(baseQuery)
.addAggregations(avg("marks").as("avg_marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// avg of 2 entities
Expand All @@ -187,7 +199,11 @@ public void testAvgAggregationWithAutoGeneratedAlias() {

EntityQuery baseQuery = Query.newEntityQueryBuilder().setKind(KIND).build();
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder().over(baseQuery).addAggregations(avg("marks")).build();
Query.newAggregationQueryBuilder()
.over(baseQuery)
.addAggregations(avg("marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// avg of 2 entities
assertThat(getOnlyElement(DATASTORE.runAggregation(aggregationQuery)).getDouble("property_1"))
Expand All @@ -207,7 +223,11 @@ public void testAvgAggregationInGqlQuery() {
Query.newGqlQueryBuilder("AGGREGATE AVG(marks) AS avg_marks OVER (SELECT * FROM Marks)")
.build();

AggregationQuery aggregationQuery = Query.newAggregationQueryBuilder().over(gqlQuery).build();
AggregationQuery aggregationQuery =
Query.newAggregationQueryBuilder()
.over(gqlQuery)
.setNamespace(OPTIONS.getNamespace())
.build();

// avg of 2 entities
assertThat(getOnlyElement(DATASTORE.runAggregation(aggregationQuery)).getDouble("avg_marks"))
Expand All @@ -229,6 +249,7 @@ public void testSumAndAvgAggregationTogether() {
.over(baseQuery)
.addAggregations(sum("marks").as("total_marks"))
.addAggregations(avg("marks").as("avg_marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// sum of 2 entities
Expand All @@ -250,6 +271,7 @@ public void testTransactionShouldReturnAConsistentSnapshot() {
.addAggregation(count().as("count"))
.addAggregations(sum("marks").as("total_marks"))
.addAggregations(avg("marks").as("avg_marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

// original entity count is 2
Expand Down Expand Up @@ -310,6 +332,7 @@ public void testReadOnlyTransactionShouldNotLockTheDocuments()
.addAggregation(count().as("count"))
.addAggregations(sum("marks").as("total_marks"))
.addAggregations(avg("marks").as("avg_marks"))
.setNamespace(OPTIONS.getNamespace())
.build();

TransactionOptions transactionOptions =
Expand Down
Loading