Search in sources :

Example 1 with FieldReference

use of com.google.firestore.v1.StructuredQuery.FieldReference 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);
}
Also used : FieldReference(com.google.firestore.v1.StructuredQuery.FieldReference) RunQueryResponse(com.google.firestore.v1.RunQueryResponse) RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Document(com.google.firestore.v1.Document)

Aggregations

Document (com.google.firestore.v1.Document)1 RunQueryRequest (com.google.firestore.v1.RunQueryRequest)1 RunQueryResponse (com.google.firestore.v1.RunQueryResponse)1 FieldReference (com.google.firestore.v1.StructuredQuery.FieldReference)1