Search in sources :

Example 11 with IteratorId

use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.

the class GrpcServerTest method whenExecutingQueryWithoutInferenceSet_InferenceIsNotSet.

@Test
public void whenExecutingQueryWithoutInferenceSet_InferenceIsNotSet() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.send(execQueryRequest(QUERY, null));
        IteratorId iterator = tx.receive().ok().getIteratorId();
        tx.send(nextRequest(iterator));
        tx.send(stopRequest(iterator));
    }
    verify(tx.graql(), times(0)).infer(anyBoolean());
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 12 with IteratorId

use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.

the class GrpcIterators method add.

/**
 * Register a new iterator and return the ID of the iterator
 */
public IteratorId add(Iterator<TxResponse> iterator) {
    IteratorId iteratorId = IteratorId.newBuilder().setId(iteratorIdCounter.getAndIncrement()).build();
    iterators.put(iteratorId, iterator);
    return iteratorId;
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId)

Example 13 with IteratorId

use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.

the class TxObserver method getAttributesByValue.

private void getAttributesByValue(AttributeValue attributeValue) {
    Collection<Attribute<Object>> attributes = tx().getAttributesByValue(GrpcUtil.convert(attributeValue));
    Iterator<TxResponse> iterator = attributes.stream().map(GrpcUtil::conceptResponse).iterator();
    IteratorId iteratorId = grpcIterators.add(iterator);
    responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) Attribute(ai.grakn.concept.Attribute) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 14 with IteratorId

use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.

the class TxObserver method execQuery.

private void execQuery(ExecQuery request) {
    String queryString = request.getQuery().getValue();
    QueryBuilder graql = tx().graql();
    if (request.hasInfer()) {
        graql = graql.infer(request.getInfer().getValue());
    }
    Stream<QueryResult> queryResultStream = graql.parse(queryString).results(GrpcConverter.get());
    Stream<TxResponse> txResponseStream = queryResultStream.map(queryResult -> TxResponse.newBuilder().setQueryResult(queryResult).build());
    Iterator<TxResponse> iterator = txResponseStream.iterator();
    IteratorId iteratorId = grpcIterators.add(iterator);
    responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
Also used : QueryResult(ai.grakn.rpc.generated.GrpcGrakn.QueryResult) IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) QueryBuilder(ai.grakn.graql.QueryBuilder) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 15 with IteratorId

use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.

the class TxObserver method stop.

private void stop(Stop stop) {
    IteratorId iteratorId = stop.getIteratorId();
    grpcIterators.stop(iteratorId);
    responseObserver.onNext(GrpcUtil.doneResponse());
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId)

Aggregations

IteratorId (ai.grakn.rpc.generated.GrpcIterator.IteratorId)15 TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)8 TxGrpcCommunicator (ai.grakn.grpc.TxGrpcCommunicator)7 Test (org.junit.Test)7 Concept (ai.grakn.concept.Concept)3 Answer (ai.grakn.graql.admin.Answer)2 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)2 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)2 QueryResult (ai.grakn.rpc.generated.GrpcGrakn.QueryResult)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 Attribute (ai.grakn.concept.Attribute)1 QueryBuilder (ai.grakn.graql.QueryBuilder)1