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());
}
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);
}
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");
}
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);
}
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;
}
Aggregations