N1ql query return incorrect result and inconsistent results

@zizou, Have a look at @simonbasle’s response in this post: Async (reactive) N1QL.

The errors are emitted by the AsyncN1qlQueryResult.errors() observable. You need to handle those errors in some fashion and emit an exception so your subscriber’s onError() will be invoked. In some situations you may be satisfied with partial results and can do as you did and just map to the AsyncN1qlQueryResult.rows() observable.

I have used code like this to throw an exception for one of the emitted errors:

bucket.async()
    .query(query)
    .flatMap(asyncN1qlQueryResult ->
        asyncN1qlQueryResult.errors()
            .flatMap(error -> 
                 Observable.<AsyncN1qlQueryRow>error(
                     new RuntimeException("Error while performing query: " 
                         + error)))
            .switchIfEmpty(asyncN1qlQueryResult.rows()))
    .map(asyncN1qlQueryRow -> asyncN1qlQueryRow.value())
    ...
1 Like