Search in sources :

Example 16 with Order

use of com.google.apphosting.datastore.DatastoreV3Pb.Query.Order in project appengine-java-standard by GoogleCloudPlatform.

the class EntityComparatorTests method testMultiValuePropertySortWithInequality.

@Test
public void testMultiValuePropertySortWithInequality() {
    OnestoreEntity.EntityProto p1 = new OnestoreEntity.EntityProto();
    p1.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(1L));
    p1.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(4L));
    OnestoreEntity.EntityProto p2 = new OnestoreEntity.EntityProto();
    p2.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(2L));
    p2.addProperty().setMultiple(true).setName("a").setValue(new OnestoreEntity.PropertyValue().setInt64Value(3L));
    Filter filter = new Filter().setOp(Operator.GREATER_THAN);
    filter.addProperty().setName("a").getMutableValue().setInt64Value(2);
    Order desc = new Order().setProperty("a").setDirection(Direction.DESCENDING);
    EntityProtoComparator epc = new EntityProtoComparator(Collections.singletonList(desc), Collections.singletonList(filter));
    assertThat(epc.compare(p1, p2)).isEqualTo(-1);
    Order asc = new Order().setProperty("a").setDirection(Direction.ASCENDING);
    epc = new EntityProtoComparator(Collections.singletonList(asc), Collections.singletonList(filter));
    assertThat(epc.compare(p1, p2)).isEqualTo(1);
}
Also used : Order(com.google.apphosting.datastore.DatastoreV3Pb.Query.Order) EntityProtoComparator(com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator) Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) OnestoreEntity(com.google.storage.onestore.v3.OnestoreEntity) Test(org.junit.Test)

Example 17 with Order

use of com.google.apphosting.datastore.DatastoreV3Pb.Query.Order in project appengine-java-standard by GoogleCloudPlatform.

the class EntityComparatorTests method testDefaultSortWithInequality.

@Test
public void testDefaultSortWithInequality() {
    // if no sorts provided we end up with the default sort
    List<Order> orders = Lists.newArrayList();
    Filter filter = new Filter().setOp(Operator.GREATER_THAN);
    String ineq = "ineq";
    filter.addProperty().setName(ineq).getMutableValue().setInt64Value(0);
    List<Filter> filters = Arrays.asList(filter);
    // Should default to having the ineq prop first that key asc
    EntityProtoComparator epc = new EntityProtoComparator(orders, filters);
    assertThat(epc.orders).hasSize(2);
    assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
    assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.ASCENDING);
    assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
    // if a sort a non-key field is provided we add the default sort to the
    // end.
    orders.add(new Order().setProperty(ineq).setDirection(Direction.DESCENDING));
    epc = new EntityProtoComparator(orders, filters);
    assertThat(epc.orders).hasSize(2);
    assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
    assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.DESCENDING);
    assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
    // if we explicitly ad the default sort to the end we don't end up with
    // more than one default sort
    orders.add(KEY_ASC_ORDER);
    epc = new EntityProtoComparator(orders);
    assertThat(epc.orders).hasSize(2);
    assertThat(epc.orders.get(0).getProperty()).isEqualTo(ineq);
    assertThat(epc.orders.get(0).getDirectionEnum()).isEqualTo(Direction.DESCENDING);
    assertThat(epc.orders.get(1)).isEqualTo(KEY_ASC_ORDER);
}
Also used : Order(com.google.apphosting.datastore.DatastoreV3Pb.Query.Order) EntityProtoComparator(com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator) Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) Test(org.junit.Test)

Aggregations

Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)17 Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)10 EntityProtoComparator (com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator)5 Test (org.junit.Test)5 DatastoreV3Pb (com.google.apphosting.datastore.DatastoreV3Pb)3 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)3 ByteString (com.google.protobuf.ByteString)2 OnestoreEntity (com.google.storage.onestore.v3.OnestoreEntity)2 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)2 Index (com.google.storage.onestore.v3.OnestoreEntity.Index)2 Property (com.google.storage.onestore.v3.OnestoreEntity.Index.Property)2 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Key (com.google.appengine.api.datastore.Key)1 Utils.getLastElement (com.google.appengine.api.datastore.dev.Utils.getLastElement)1 CompiledQuery (com.google.apphosting.datastore.DatastoreV3Pb.CompiledQuery)1 GeoRegion (com.google.apphosting.datastore.DatastoreV3Pb.GeoRegion)1 Query (com.google.apphosting.datastore.DatastoreV3Pb.Query)1 Operator (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter.Operator)1