Search in sources :

Example 1 with ViewResult

use of org.ektorp.ViewResult in project apex-malhar by apache.

the class AbstractCouchDBInputOperator method emitTuples.

@Override
public void emitTuples() {
    ViewQuery viewQuery = getViewQuery();
    if (pageSize > 0) {
        viewQuery.limit(pageSize);
    }
    if (nextPageKey != null) {
        viewQuery.startKey(nextPageKey);
    }
    if (skip) {
        viewQuery.skip(1);
    }
    ViewResult result = store.queryStore(viewQuery);
    List<ViewResult.Row> rows = result.getRows();
    try {
        for (ViewResult.Row row : result.getRows()) {
            T tuple = getTuple(row);
            outputPort.emit(tuple);
        }
    } catch (Throwable cause) {
        Throwables.propagate(cause);
    }
    if (rows.size() > 0) {
        // Use the last row as the start key and skip one item
        // In case we reach the end we will continue to make the request with last row till there is more data available
        // in the store
        nextPageKey = rows.get(rows.size() - 1).getKey();
        // The skip option should only be used with small values, as skipping a large range of documents this way is inefficient.
        skip = true;
    }
}
Also used : ViewQuery(org.ektorp.ViewQuery) ViewResult(org.ektorp.ViewResult)

Aggregations

ViewQuery (org.ektorp.ViewQuery)1 ViewResult (org.ektorp.ViewResult)1