Search in sources :

Example 11 with IIndex

use of org.apache.hyracks.storage.common.IIndex in project asterixdb by apache.

the class MetadataNode method searchIndex.

private <ResultType> void searchIndex(JobId jobId, IMetadataIndex index, ITupleReference searchKey, IValueExtractor<ResultType> valueExtractor, List<ResultType> results) throws MetadataException, HyracksDataException, RemoteException {
    IBinaryComparatorFactory[] comparatorFactories = index.getKeyBinaryComparatorFactory();
    if (index.getFile() == null) {
        throw new MetadataException("No file for Index " + index.getDataverseName() + "." + index.getIndexName());
    }
    String resourceName = index.getFile().getRelativePath();
    IIndex indexInstance = datasetLifecycleManager.get(resourceName);
    datasetLifecycleManager.open(resourceName);
    IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
    IBinaryComparator[] searchCmps = null;
    MultiComparator searchCmp = null;
    RangePredicate rangePred = null;
    if (searchKey != null) {
        searchCmps = new IBinaryComparator[searchKey.getFieldCount()];
        for (int i = 0; i < searchKey.getFieldCount(); i++) {
            searchCmps[i] = comparatorFactories[i].createBinaryComparator();
        }
        searchCmp = new MultiComparator(searchCmps);
    }
    rangePred = new RangePredicate(searchKey, searchKey, true, true, searchCmp, searchCmp);
    indexAccessor.search(rangeCursor, rangePred);
    try {
        while (rangeCursor.hasNext()) {
            rangeCursor.next();
            ResultType result = valueExtractor.getValue(jobId, rangeCursor.getTuple());
            if (result != null) {
                results.add(result);
            }
        }
    } finally {
        rangeCursor.close();
    }
    datasetLifecycleManager.close(resourceName);
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Example 12 with IIndex

use of org.apache.hyracks.storage.common.IIndex in project asterixdb by apache.

the class MetadataNode method printMetadata.

// Debugging Method
public String printMetadata() {
    StringBuilder sb = new StringBuilder();
    try {
        IMetadataIndex index = MetadataPrimaryIndexes.DATAVERSE_DATASET;
        String resourceName = index.getFile().toString();
        IIndex indexInstance = datasetLifecycleManager.get(resourceName);
        datasetLifecycleManager.open(resourceName);
        IIndexAccessor indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
        RangePredicate rangePred = null;
        rangePred = new RangePredicate(null, null, true, true, null, null);
        indexAccessor.search(rangeCursor, rangePred);
        try {
            while (rangeCursor.hasNext()) {
                rangeCursor.next();
                sb.append(TupleUtils.printTuple(rangeCursor.getTuple(), new ISerializerDeserializer[] { SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING) }));
            }
        } finally {
            rangeCursor.close();
        }
        datasetLifecycleManager.close(resourceName);
        index = MetadataPrimaryIndexes.DATASET_DATASET;
        indexInstance = datasetLifecycleManager.get(resourceName);
        datasetLifecycleManager.open(resourceName);
        indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
        rangePred = null;
        rangePred = new RangePredicate(null, null, true, true, null, null);
        indexAccessor.search(rangeCursor, rangePred);
        try {
            while (rangeCursor.hasNext()) {
                rangeCursor.next();
                sb.append(TupleUtils.printTuple(rangeCursor.getTuple(), new ISerializerDeserializer[] { SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING), SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING) }));
            }
        } finally {
            rangeCursor.close();
        }
        datasetLifecycleManager.close(resourceName);
        index = MetadataPrimaryIndexes.INDEX_DATASET;
        indexInstance = datasetLifecycleManager.get(resourceName);
        datasetLifecycleManager.open(resourceName);
        indexAccessor = indexInstance.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
        rangePred = null;
        rangePred = new RangePredicate(null, null, true, true, null, null);
        indexAccessor.search(rangeCursor, rangePred);
        try {
            while (rangeCursor.hasNext()) {
                rangeCursor.next();
                sb.append(TupleUtils.printTuple(rangeCursor.getTuple(), new ISerializerDeserializer[] { SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING), SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING), SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING) }));
            }
        } finally {
            rangeCursor.close();
        }
        datasetLifecycleManager.close(resourceName);
    } catch (Exception e) {
        // Debugging method
        e.printStackTrace();
    }
    return sb.toString();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) IMetadataIndex(org.apache.asterix.metadata.api.IMetadataIndex) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) ACIDException(org.apache.asterix.common.exceptions.ACIDException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) RemoteException(java.rmi.RemoteException)

Example 13 with IIndex

use of org.apache.hyracks.storage.common.IIndex in project asterixdb by apache.

the class AbstractInvertedIndexSearchTest method runTest.

protected void runTest(LSMInvertedIndexTestContext testCtx, TupleGenerator tupleGen, List<IInvertedIndexSearchModifier> searchModifiers) throws IOException {
    IIndex invIndex = testCtx.getIndex();
    if ((invIndexType != InvertedIndexType.LSM) && (invIndexType != InvertedIndexType.PARTITIONED_LSM) || !bulkLoad) {
        invIndex.create();
        invIndex.activate();
    }
    if (bulkLoad) {
        if ((invIndexType != InvertedIndexType.LSM) && (invIndexType != InvertedIndexType.PARTITIONED_LSM)) {
            LSMInvertedIndexTestUtils.bulkLoadInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT, false);
        } else {
            LSMInvertedIndexTestUtils.bulkLoadInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT, true);
        }
    } else {
        LSMInvertedIndexTestUtils.insertIntoInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT);
    }
    invIndex.validate();
    for (IInvertedIndexSearchModifier searchModifier : searchModifiers) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("Running searches with: " + searchModifier.toString());
        }
        LSMInvertedIndexTestUtils.testIndexSearch(testCtx, tupleGen, harness.getRandom(), NUM_DOC_QUERIES, NUM_RANDOM_QUERIES, searchModifier, SCAN_COUNT_ARRAY);
    }
    invIndex.deactivate();
    invIndex.destroy();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) IInvertedIndexSearchModifier(org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndexSearchModifier)

Example 14 with IIndex

use of org.apache.hyracks.storage.common.IIndex in project asterixdb by apache.

the class TempDatasetSecondaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
    ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx);
    IResourceLifecycleManager<IIndex> indexLifeCycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath());
    if (index == null) {
        throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered.");
    }
    try {
        ITransactionContext txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        IModificationOperationCallback modCallback = new TempDatasetIndexModificationOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, false);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) IIndex(org.apache.hyracks.storage.common.IIndex) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) DatasetId(org.apache.asterix.common.transactions.DatasetId) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 15 with IIndex

use of org.apache.hyracks.storage.common.IIndex in project asterixdb by apache.

the class PrimaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx);
    IResourceLifecycleManager<IIndex> indexLifeCycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath());
    if (index == null) {
        throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered.");
    }
    try {
        ITransactionContext txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
        IModificationOperationCallback modCallback = new PrimaryIndexModificationOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp, operatorNodePushable);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, true);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) DatasetId(org.apache.asterix.common.transactions.DatasetId) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

IIndex (org.apache.hyracks.storage.common.IIndex)17 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)5 ACIDException (org.apache.asterix.common.exceptions.ACIDException)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 AString (org.apache.asterix.om.base.AString)3 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)3 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)3 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)2 DatasetId (org.apache.asterix.common.transactions.DatasetId)2 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)2 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)2 ExternalFile (org.apache.asterix.external.indexing.ExternalFile)2 FileIndexTupleTranslator (org.apache.asterix.external.indexing.FileIndexTupleTranslator)2 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)2 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)2 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)2 AbstractOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractOperatorNodePushable)2 IIndexDataflowHelper (org.apache.hyracks.storage.am.common.api.IIndexDataflowHelper)2 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)2 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)2