use of org.ektorp.ViewQuery 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;
}
}
use of org.ektorp.ViewQuery in project gora by apache.
the class CouchDBStore method deleteByQuery.
/**
* Deletes all the objects matching the query.
* See also the note on <a href="#visibility">visibility</a>.
*
* @param query matching records to this query will be deleted
* @return number of deleted records
*/
@Override
public long deleteByQuery(Query<K, T> query) {
final K key = query.getKey();
final K startKey = query.getStartKey();
final K endKey = query.getEndKey();
if (key == null && startKey == null && endKey == null) {
deleteSchema();
createSchema();
return -1;
} else {
final ViewQuery viewQuery = new ViewQuery().allDocs().includeDocs(true).key(key).startKey(startKey).endKey(endKey);
final List<Map> result = db.queryView(viewQuery, Map.class);
final Map<String, List<String>> revisionsToPurge = new HashMap<>();
for (Map map : result) {
final List<String> revisions = new ArrayList<>();
String keyString = map.get("_id").toString();
String rev = map.get("_rev").toString();
revisions.add(rev);
revisionsToPurge.put(keyString, revisions);
}
return db.purge(revisionsToPurge).getPurged().size();
}
}
use of org.ektorp.ViewQuery in project gora by apache.
the class CouchDBStore method execute.
/**
* Execute the query and return the result.
*/
@Override
public Result<K, T> execute(Query<K, T> query) {
query.setFields(getFieldsToQuery(query.getFields()));
final ViewQuery viewQuery = new ViewQuery().allDocs().includeDocs(true).startKey(query.getStartKey()).endKey(query.getEndKey()).limit(//FIXME GORA have long value but ektorp client use integer
Ints.checkedCast(query.getLimit()));
CouchDBResult<K, T> couchDBResult = new CouchDBResult<>(this, query, db.queryView(viewQuery, Map.class));
return couchDBResult;
}
use of org.ektorp.ViewQuery in project apex-malhar by apache.
the class CouchDBTestHelper method createAndFetchViewQuery.
public static ViewQuery createAndFetchViewQuery() {
if (!connector.contains(DESIGN_DOC_ID)) {
// The design document doesn't exist in the database so we create it.
JsonNode rootNode = mapper.createObjectNode();
((ObjectNode) rootNode).put("language", "javascript");
((ObjectNode) rootNode).putObject("views").putObject(TEST_VIEW).put("map", "function(doc) {\n emit(doc._id, doc);\n}");
connector.create(DESIGN_DOC_ID, rootNode);
}
return new ViewQuery().designDocId(DESIGN_DOC_ID).viewName(TEST_VIEW);
}
Aggregations