Search in sources :

Example 1 with TreeIndexDiskOrderScanCursor

use of org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor in project asterixdb by apache.

the class OrderedIndexExamplesTest method diskOrderScan.

protected void diskOrderScan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception {
    try {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Disk-Order Scan:");
        }
        ITreeIndexAccessor treeIndexAccessor = (ITreeIndexAccessor) indexAccessor;
        TreeIndexDiskOrderScanCursor diskOrderCursor = (TreeIndexDiskOrderScanCursor) treeIndexAccessor.createDiskOrderScanCursor();
        treeIndexAccessor.diskOrderScan(diskOrderCursor);
        try {
            while (diskOrderCursor.hasNext()) {
                diskOrderCursor.next();
                ITupleReference frameTuple = diskOrderCursor.getTuple();
                String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info(rec);
                }
            }
        } finally {
            diskOrderCursor.close();
        }
    } catch (UnsupportedOperationException e) {
        // support disk-order scan.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    } catch (ClassCastException e) {
        // an ITreeIndexAccessor, e.g., for the LSMBTree.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    }
}
Also used : TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)

Example 2 with TreeIndexDiskOrderScanCursor

use of org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor in project asterixdb by apache.

the class AbstractRTreeExamplesTest method diskOrderScan.

protected void diskOrderScan(IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes) throws Exception {
    try {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Disk-Order Scan:");
        }
        ITreeIndexAccessor treeIndexAccessor = (ITreeIndexAccessor) indexAccessor;
        TreeIndexDiskOrderScanCursor diskOrderCursor = (TreeIndexDiskOrderScanCursor) treeIndexAccessor.createDiskOrderScanCursor();
        treeIndexAccessor.diskOrderScan(diskOrderCursor);
        try {
            while (diskOrderCursor.hasNext()) {
                diskOrderCursor.next();
                ITupleReference frameTuple = diskOrderCursor.getTuple();
                String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info(rec);
                }
            }
        } finally {
            diskOrderCursor.close();
        }
    } catch (UnsupportedOperationException e) {
        // support disk-order scan.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    } catch (ClassCastException e) {
        // an ITreeIndexAccessor, e.g., for the LSMRTree.
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Ignoring disk-order scan since it's not supported.");
        }
    }
}
Also used : TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)

Example 3 with TreeIndexDiskOrderScanCursor

use of org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor in project asterixdb by apache.

the class TreeIndexDiskOrderScanOperatorNodePushable method initialize.

@Override
public void initialize() throws HyracksDataException {
    treeIndexHelper.open();
    ITreeIndex treeIndex = (ITreeIndex) treeIndexHelper.getIndexInstance();
    try {
        ITreeIndexFrame cursorFrame = treeIndex.getLeafFrameFactory().createFrame();
        ITreeIndexCursor cursor = new TreeIndexDiskOrderScanCursor(cursorFrame);
        LocalResource resource = treeIndexHelper.getResource();
        ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(resource.getId(), ctx, null);
        ITreeIndexAccessor indexAccessor = (ITreeIndexAccessor) treeIndex.createAccessor(NoOpOperationCallback.INSTANCE, searchCallback);
        try {
            writer.open();
            indexAccessor.diskOrderScan(cursor);
            int fieldCount = treeIndex.getFieldCount();
            FrameTupleAppender appender = new FrameTupleAppender(new VSizeFrame(ctx));
            ArrayTupleBuilder tb = new ArrayTupleBuilder(fieldCount);
            DataOutput dos = tb.getDataOutput();
            while (cursor.hasNext()) {
                tb.reset();
                cursor.next();
                ITupleReference frameTuple = cursor.getTuple();
                for (int i = 0; i < frameTuple.getFieldCount(); i++) {
                    dos.write(frameTuple.getFieldData(i), frameTuple.getFieldStart(i), frameTuple.getFieldLength(i));
                    tb.addFieldEndOffset();
                }
                FrameUtils.appendToWriter(writer, appender, tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize());
            }
            appender.write(writer, true);
        } catch (Throwable th) {
            writer.fail();
            throw new HyracksDataException(th);
        } finally {
            try {
                cursor.close();
            } catch (Exception cursorCloseException) {
                throw new IllegalStateException(cursorCloseException);
            } finally {
                writer.close();
            }
        }
    } catch (Throwable th) {
        treeIndexHelper.close();
        throw new HyracksDataException(th);
    }
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) DataOutput(java.io.DataOutput) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) LocalResource(org.apache.hyracks.storage.common.LocalResource) TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) ITreeIndexFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexFrame) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ITreeIndex(org.apache.hyracks.storage.am.common.api.ITreeIndex)

Example 4 with TreeIndexDiskOrderScanCursor

use of org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor in project asterixdb by apache.

the class BTree method diskOrderScan.

private void diskOrderScan(ITreeIndexCursor icursor, BTreeOpContext ctx) throws HyracksDataException {
    TreeIndexDiskOrderScanCursor cursor = (TreeIndexDiskOrderScanCursor) icursor;
    ctx.reset();
    RangePredicate diskOrderScanPred = new RangePredicate(null, null, true, true, ctx.getCmp(), ctx.getCmp());
    int maxPageId = freePageManager.getMaxPageId(ctx.getMetaFrame());
    int currentPageId = bulkloadLeafStart;
    ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, currentPageId), false);
    page.acquireReadLatch();
    try {
        cursor.setBufferCache(bufferCache);
        cursor.setFileId(fileId);
        cursor.setCurrentPageId(currentPageId);
        cursor.setMaxPageId(maxPageId);
        ctx.getCursorInitialState().setPage(page);
        ctx.getCursorInitialState().setSearchOperationCallback(ctx.getSearchCallback());
        ctx.getCursorInitialState().setOriginialKeyComparator(ctx.getCmp());
        cursor.open(ctx.getCursorInitialState(), diskOrderScanPred);
    } catch (Exception e) {
        page.releaseReadLatch();
        bufferCache.unpin(page);
        throw HyracksDataException.create(e);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with TreeIndexDiskOrderScanCursor

use of org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor in project asterixdb by apache.

the class RTree method diskOrderScan.

private void diskOrderScan(ITreeIndexCursor icursor, RTreeOpContext ctx) throws HyracksDataException {
    TreeIndexDiskOrderScanCursor cursor = (TreeIndexDiskOrderScanCursor) icursor;
    ctx.reset();
    MultiComparator cmp = MultiComparator.create(cmpFactories);
    SearchPredicate searchPred = new SearchPredicate(null, cmp);
    int currentPageId = bulkloadLeafStart;
    int maxPageId = freePageManager.getMaxPageId(ctx.getMetaFrame());
    ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, currentPageId), false);
    page.acquireReadLatch();
    try {
        cursor.setBufferCache(bufferCache);
        cursor.setFileId(fileId);
        cursor.setCurrentPageId(currentPageId);
        cursor.setMaxPageId(maxPageId);
        ctx.getCursorInitialState().setOriginialKeyComparator(ctx.getCmp());
        ctx.getCursorInitialState().setPage(page);
        cursor.open(ctx.getCursorInitialState(), searchPred);
    } catch (Exception e) {
        page.releaseReadLatch();
        bufferCache.unpin(page);
        throw new HyracksDataException(e);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) TreeIndexDiskOrderScanCursor(org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

TreeIndexDiskOrderScanCursor (org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor)5 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)3 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)3 ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)2 DataOutput (java.io.DataOutput)1 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)1 ITreeIndex (org.apache.hyracks.storage.am.common.api.ITreeIndex)1 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)1 ITreeIndexFrame (org.apache.hyracks.storage.am.common.api.ITreeIndexFrame)1 ISearchOperationCallback (org.apache.hyracks.storage.common.ISearchOperationCallback)1 ISearchPredicate (org.apache.hyracks.storage.common.ISearchPredicate)1 LocalResource (org.apache.hyracks.storage.common.LocalResource)1 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)1