use of org.sirix.index.cas.CASFilterRange in project sirix by sirixdb.
the class ScanCASIndexRange method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final DBNode doc = (DBNode) args[0];
final XdmNodeReadTrx rtx = doc.getTrx();
final IndexController controller = rtx.getResourceManager().getRtxIndexController(rtx.getRevisionNumber());
if (controller == null) {
throw new QueryException(new QNm("Document not found: " + ((Str) args[1]).stringValue()));
}
final int idx = FunUtil.getInt(args, 1, "$idx-no", -1, null, true);
final IndexDef indexDef = controller.getIndexes().getIndexDef(idx, IndexType.CAS);
if (indexDef == null) {
throw new QueryException(SDBFun.ERR_INDEX_NOT_FOUND, "Index no %s for collection %s and document %s not found.", idx, doc.getCollection().getName(), doc.getTrx().getResourceManager().getResourceConfig().getResource().getFileName().toString());
}
if (indexDef.getType() != IndexType.CAS) {
throw new QueryException(SDBFun.ERR_INVALID_INDEX_TYPE, "Index no %s for collection %s and document %s is not a CAS index.", idx, doc.getCollection().getName(), doc.getTrx().getResourceManager().getResourceConfig().getResource().getFileName().toString());
}
final Type keyType = indexDef.getContentType();
final Atomic min = Cast.cast(sctx, (Atomic) args[2], keyType, true);
final Atomic max = Cast.cast(sctx, (Atomic) args[3], keyType, true);
final boolean incMin = FunUtil.getBoolean(args, 4, "$include-low-key", true, true);
final boolean incMax = FunUtil.getBoolean(args, 5, "$include-high-key", true, true);
final String paths = FunUtil.getString(args, 6, "$paths", null, null, false);
final String[] pathArray = paths == null ? new String[] {} : paths.split(";");
final CASFilterRange filter = controller.createCASFilterRange(pathArray, min, max, incMin, incMax, new PCRCollectorImpl(rtx));
final IndexController ic = controller;
final DBNode node = doc;
return new LazySequence() {
@Override
public Iter iterate() {
return new BaseIter() {
Stream<?> s;
@Override
public Item next() throws QueryException {
if (s == null) {
s = new SirixNodeKeyStream(ic.openCASIndex(node.getTrx().getPageTrx(), indexDef, filter), node.getCollection(), node.getTrx());
}
return (Item) s.next();
}
@Override
public void close() {
if (s != null) {
s.close();
}
}
};
}
};
}
Aggregations