use of com.google.firestore.v1.StructuredQuery.Filter in project beam by apache.
the class FirestoreTestingHelper method listDocumentIds.
Stream<String> listDocumentIds(String collectionPath) {
int index = collectionPath.lastIndexOf('/');
String parent = collectionPath.substring(0, index);
String collectionId = collectionPath.substring(index + 1);
ListDocumentsRequest ldr = ListDocumentsRequest.newBuilder().setParent(parent).setCollectionId(collectionId).setShowMissing(true).build();
// LOGGER.debug("ldr = {}", ldr);
ListDocumentsPagedResponse response = rpc.listDocumentsPagedCallable().call(ldr);
return StreamSupport.stream(response.iteratePages().spliterator(), false).flatMap(page -> page.getResponse().getDocumentsList().stream()).map(Document::getName).filter(s -> !s.isEmpty());
}
use of com.google.firestore.v1.StructuredQuery.Filter in project beam by apache.
the class FirestoreTestingHelper method listDocumentsViaQuery.
Stream<String> listDocumentsViaQuery(String collectionPath) {
int index = collectionPath.lastIndexOf('/');
String parent = collectionPath.substring(0, index);
String collectionId = collectionPath.substring(index + 1);
FieldReference nameField = FieldReference.newBuilder().setFieldPath("__name__").build();
RunQueryRequest rqr = RunQueryRequest.newBuilder().setParent(parent).setStructuredQuery(StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId(collectionId)).addOrderBy(Order.newBuilder().setField(nameField).setDirection(Direction.ASCENDING).build()).setSelect(Projection.newBuilder().addFields(nameField).build())).build();
return StreamSupport.stream(rpc.runQueryCallable().call(rqr).spliterator(), false).filter(RunQueryResponse::hasDocument).map(RunQueryResponse::getDocument).map(Document::getName);
}
use of com.google.firestore.v1.StructuredQuery.Filter in project spring-cloud-gcp by spring-cloud.
the class PartTreeFirestoreQuery method createBuilderWithFilter.
private StructuredQuery.Builder createBuilderWithFilter(Object[] parameters) {
StructuredQuery.Builder builder = StructuredQuery.newBuilder();
Iterator it = Arrays.asList(parameters).iterator();
StructuredQuery.CompositeFilter.Builder compositeFilter = StructuredQuery.CompositeFilter.newBuilder();
compositeFilter.setOp(StructuredQuery.CompositeFilter.Operator.AND);
this.tree.getParts().forEach(part -> {
StructuredQuery.FieldReference fieldReference = StructuredQuery.FieldReference.newBuilder().setFieldPath(buildName(part)).build();
StructuredQuery.Filter.Builder filter = StructuredQuery.Filter.newBuilder();
if (part.getType() == Part.Type.IS_NULL) {
filter.getUnaryFilterBuilder().setField(fieldReference).setOp(StructuredQuery.UnaryFilter.Operator.IS_NULL);
} else {
if (!it.hasNext()) {
throw new FirestoreDataException("Too few parameters are provided for query method: " + getQueryMethod().getName());
}
Object value = it.next();
filter.getFieldFilterBuilder().setField(fieldReference).setOp(getOperator(part, value)).setValue(this.classMapper.toFirestoreValue(value));
}
compositeFilter.addFilters(filter.build());
});
builder.setWhere(StructuredQuery.Filter.newBuilder().setCompositeFilter(compositeFilter.build()));
return builder;
}
use of com.google.firestore.v1.StructuredQuery.Filter in project spring-cloud-gcp by spring-cloud.
the class PartTreeFirestoreQuery method validate.
private void validate() {
List parts = this.tree.get().collect(Collectors.toList());
if (parts.size() > 1 && parts.get(0) instanceof PartTree.OrPart) {
throw new FirestoreDataException("Cloud Firestore doesn't support 'OR' (method name: " + this.getQueryMethod().getName() + ")");
}
List<String> unsupportedParts = this.tree.getParts().stream().filter(part -> !isSupportedPart(part.getType())).map(part -> part.getType().toString()).collect(Collectors.toList());
if (!unsupportedParts.isEmpty()) {
throw new FirestoreDataException("Unsupported predicate keywords: " + unsupportedParts + " in " + this.getQueryMethod().getName());
}
}
Aggregations