Search in sources :

Example 6 with Filter

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

the class QueryTranslatorTest method testGeoFilter_Rectangle.

@Test
public void testGeoFilter_Rectangle() {
    Query query = new Query("foo");
    GeoPt point1 = new GeoPt(1, 2);
    GeoPt point2 = new GeoPt(3, 4);
    query.setFilter(new Query.StContainsFilter("location", new Query.GeoRegion.Rectangle(point1, point2)));
    DatastoreV3Pb.Query proto = QueryTranslator.convertToPb(query, withDefaults());
    assertThat(proto.filterSize()).isEqualTo(1);
    Filter filter1 = proto.getFilter(0);
    assertThat(filter1.getProperty(0).getName()).isEqualTo("location");
    assertThat(filter1.getOpEnum()).isEqualTo(Operator.CONTAINED_IN_REGION);
    DatastoreV3Pb.GeoRegion geoRegion = filter1.getGeoRegion();
    assertThat(geoRegion.hasRectangle()).isTrue();
    assertThat(geoRegion.hasCircle()).isFalse();
    assertThat((float) geoRegion.getRectangle().getSouthwest().getLatitude()).isEqualTo(point1.getLatitude());
    assertThat((float) geoRegion.getRectangle().getSouthwest().getLongitude()).isEqualTo(point1.getLongitude());
    assertThat((float) geoRegion.getRectangle().getNortheast().getLatitude()).isEqualTo(point2.getLatitude());
    assertThat((float) geoRegion.getRectangle().getNortheast().getLongitude()).isEqualTo(point2.getLongitude());
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 7 with Filter

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

the class QueryTranslatorTest method testGeoFilter_Circle.

@Test
public void testGeoFilter_Circle() {
    Query query = new Query("foo");
    float lat = 1;
    float lng = 2;
    GeoPt point = new GeoPt(lat, lng);
    double radius = 1609.34;
    query.setFilter(new Query.StContainsFilter("location", new Query.GeoRegion.Circle(point, radius)));
    DatastoreV3Pb.Query proto = QueryTranslator.convertToPb(query, withDefaults());
    assertThat(proto.filterSize()).isEqualTo(1);
    Filter filter1 = proto.getFilter(0);
    assertThat(filter1.getProperty(0).getName()).isEqualTo("location");
    assertThat(filter1.getOpEnum()).isEqualTo(Operator.CONTAINED_IN_REGION);
    // it "has a value" only because "value" is a required field.  But the value has
    // nothing in it: i.e., no point_value (nor any other kind either).
    assertThat(filter1.getProperty(0).getValue().hasPointValue()).isFalse();
    assertThat(filter1.hasGeoRegion()).isTrue();
    DatastoreV3Pb.GeoRegion geoRegion = filter1.getGeoRegion();
    assertThat(geoRegion.hasCircle()).isTrue();
    assertThat(geoRegion.hasRectangle()).isFalse();
    assertThat(geoRegion.getCircle().getRadiusMeters()).isEqualTo(radius);
    assertThat((float) geoRegion.getCircle().getCenter().getLatitude()).isEqualTo(lat);
    assertThat((float) geoRegion.getCircle().getCenter().getLongitude()).isEqualTo(lng);
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 8 with Filter

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

the class QueryTranslatorTest method testGeoFilter_nestedTree.

/**
 * Ensures that we can handle nested composite filters. There's no real need for these (they don't
 * provide any more flexibility than just a single level of composite); but they're easy to
 * support, and would be more trouble than worth to prohibit.
 */
@Test
public void testGeoFilter_nestedTree() {
    Query query = new Query("foo");
    float lat = 1;
    float lng = 2;
    GeoPt point = new GeoPt(lat, lng);
    double radius = 1609.34;
    String rating = "3-stars";
    String bar = "quux";
    query.setFilter(new Query.CompositeFilter(Query.CompositeFilterOperator.AND, Arrays.asList(new Query.CompositeFilter(Query.CompositeFilterOperator.AND, Arrays.asList(new Query.StContainsFilter("location", new Query.GeoRegion.Circle(point, radius)), Query.FilterOperator.EQUAL.of("rating", rating))), Query.FilterOperator.EQUAL.of("bar", bar))));
    DatastoreV3Pb.Query proto = QueryTranslator.convertToPb(query, withDefaults());
    assertThat(proto.filterSize()).isEqualTo(3);
    Filter filter1 = proto.getFilter(0);
    assertThat(filter1.getProperty(0).getName()).isEqualTo("location");
    assertThat(filter1.getOpEnum()).isEqualTo(Operator.CONTAINED_IN_REGION);
    Filter filter2 = proto.getFilter(1);
    assertThat(filter2.getProperty(0).getName()).isEqualTo("rating");
    Filter filter3 = proto.getFilter(2);
    assertThat(filter3.getProperty(0).getName()).isEqualTo("bar");
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 9 with Filter

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

the class QueryTranslatorTest method testFilter.

@SuppressWarnings("deprecation")
@Test
public void testFilter() {
    Query query = new Query("foo");
    query.addFilter("stringProp", Query.FilterOperator.EQUAL, "stringValue");
    query.addFilter("doubleProp", Query.FilterOperator.GREATER_THAN, 42.0);
    query.addFilter("nullProp", Query.FilterOperator.EQUAL, null);
    query.addFilter("multiValuedProp1", Query.FilterOperator.IN, Lists.newArrayList(31));
    query.addFilter("multiValuedProp2", Query.FilterOperator.IN, Lists.newArrayList(31, 32));
    DatastoreV3Pb.Query proto = QueryTranslator.convertToPb(query, withDefaults());
    assertThat(proto.filterSize()).isEqualTo(5);
    Filter filter1 = proto.getFilter(0);
    assertThat(filter1.getProperty(0).getName()).isEqualTo("stringProp");
    assertThat(filter1.getProperty(0).getValue().getStringValue()).isEqualTo("stringValue");
    assertThat(filter1.getOpEnum()).isEqualTo(Operator.EQUAL);
    Filter filter2 = proto.getFilter(1);
    assertThat(filter2.getProperty(0).getName()).isEqualTo("doubleProp");
    assertThat(filter2.getProperty(0).getValue().getDoubleValue()).isWithin(0.00001).of(42.0);
    assertThat(filter2.getOpEnum()).isEqualTo(Operator.GREATER_THAN);
    Filter filter3 = proto.getFilter(2);
    assertThat(filter3.getProperty(0).getName()).isEqualTo("nullProp");
    assertThat(filter3.getProperty(0).getValue()).isEqualTo(new PropertyValue());
    assertThat(filter3.getOpEnum()).isEqualTo(Operator.EQUAL);
    Filter filter4 = proto.getFilter(3);
    assertThat(filter4.getProperty(0).getName()).isEqualTo("multiValuedProp1");
    assertThat(filter4.getProperty(0).getValue().getInt64Value()).isEqualTo(31L);
    assertThat(filter4.getOpEnum()).isEqualTo(Operator.IN);
    Filter filter5 = proto.getFilter(4);
    assertThat(filter5.getProperty(0).getName()).isEqualTo("multiValuedProp2");
    assertThat(filter5.getProperty(0).getValue().getInt64Value()).isEqualTo(31L);
    assertThat(filter5.getProperty(1).getValue().getInt64Value()).isEqualTo(32L);
    assertThat(filter5.getOpEnum()).isEqualTo(Operator.IN);
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) DatastoreV3Pb(com.google.apphosting.datastore.DatastoreV3Pb) Test(org.junit.Test)

Example 10 with Filter

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

the class FilterMatcherTest method geoFilter.

private Filter geoFilter(GeoRegion region) {
    Filter result = new Filter();
    result.setOp(Operator.CONTAINED_IN_REGION);
    result.addProperty().setName("noname");
    result.setGeoRegion(region);
    return result;
}
Also used : Filter(com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)

Aggregations

Filter (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter)20 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)10 Test (org.junit.Test)8 DatastoreV3Pb (com.google.apphosting.datastore.DatastoreV3Pb)7 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)4 EntityProtoComparator (com.google.appengine.api.datastore.EntityProtoComparators.EntityProtoComparator)2 Property (com.google.storage.onestore.v3.OnestoreEntity.Index.Property)2 Property (com.google.storage.onestore.v3.OnestoreEntity.Property)2 Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)2 HashSet (java.util.HashSet)2 Key (com.google.appengine.api.datastore.Key)1 GeoRegion (com.google.apphosting.datastore.DatastoreV3Pb.GeoRegion)1 Operator (com.google.apphosting.datastore.DatastoreV3Pb.Query.Filter.Operator)1 OnestoreEntity (com.google.storage.onestore.v3.OnestoreEntity)1 Index (com.google.storage.onestore.v3.OnestoreEntity.Index)1 ReferenceValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue.ReferenceValue)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1