Search in sources :

Example 61 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class SubstringAfterDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IScalarEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable array0 = new VoidPointable();

                private IPointable array1 = new VoidPointable();

                private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);

                private IScalarEvaluator evalPattern = args[1].createScalarEvaluator(ctx);

                private final GrowableArray array = new GrowableArray();

                private final UTF8StringBuilder builder = new UTF8StringBuilder();

                private final UTF8StringPointable stringPtr = new UTF8StringPointable();

                private final UTF8StringPointable patternPtr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalString.evaluate(tuple, array0);
                    byte[] src = array0.getByteArray();
                    int srcOffset = array0.getStartOffset();
                    int srcLen = array0.getLength();
                    evalPattern.evaluate(tuple, array1);
                    byte[] pattern = array1.getByteArray();
                    int patternOffset = array1.getStartOffset();
                    int patternLen = array1.getLength();
                    if (src[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, src[srcOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    if (pattern[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, pattern[patternOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    try {
                        stringPtr.set(src, srcOffset + 1, srcLen - 1);
                        patternPtr.set(pattern, patternOffset + 1, patternLen - 1);
                        array.reset();
                        UTF8StringPointable.substrAfter(stringPtr, patternPtr, builder, array);
                        out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        out.write(array.getByteArray(), 0, array.getLength());
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) GrowableArray(org.apache.hyracks.data.std.util.GrowableArray) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) UTF8StringBuilder(org.apache.hyracks.data.std.util.UTF8StringBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)

Example 62 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class SuperActivityOperatorNodePushable method runInParallel.

private void runInParallel(OperatorNodePushableAction action) throws HyracksDataException {
    List<Future<Void>> tasks = new ArrayList<>();
    final Semaphore startSemaphore = new Semaphore(1 - operatorNodePushablesBFSOrder.size());
    final Semaphore completeSemaphore = new Semaphore(1 - operatorNodePushablesBFSOrder.size());
    try {
        for (final IOperatorNodePushable op : operatorNodePushablesBFSOrder) {
            tasks.add(ctx.getExecutorService().submit(() -> {
                startSemaphore.release();
                try {
                    action.run(op);
                } finally {
                    completeSemaphore.release();
                }
                return null;
            }));
        }
        for (Future<Void> task : tasks) {
            task.get();
        }
    } catch (InterruptedException e) {
        cancelTasks(tasks, startSemaphore, completeSemaphore);
        Thread.currentThread().interrupt();
        throw HyracksDataException.create(e);
    } catch (Exception e) {
        cancelTasks(tasks, startSemaphore, completeSemaphore);
        throw HyracksDataException.create(e);
    }
}
Also used : IOperatorNodePushable(org.apache.hyracks.api.dataflow.IOperatorNodePushable) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Semaphore(java.util.concurrent.Semaphore) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 63 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class HyracksDatasetReader method nextPartition.

private boolean nextPartition() throws HyracksDataException {
    ++lastReadPartition;
    try {
        DatasetDirectoryRecord record = getRecord(lastReadPartition);
        while (record.getEmpty() && (++lastReadPartition) < knownRecords.length) {
            record = getRecord(lastReadPartition);
        }
        if (lastReadPartition == knownRecords.length) {
            return false;
        }
        resultChannel = new DatasetNetworkInputChannel(netManager, getSocketAddress(record), jobId, resultSetId, lastReadPartition, NUM_READ_BUFFERS);
        lastMonitor = getMonitor(lastReadPartition);
        resultChannel.registerMonitor(lastMonitor);
        resultChannel.open(datasetClientCtx);
        return true;
    } catch (Exception e) {
        throw HyracksDataException.create(e);
    }
}
Also used : DatasetDirectoryRecord(org.apache.hyracks.api.dataset.DatasetDirectoryRecord) DatasetNetworkInputChannel(org.apache.hyracks.comm.channels.DatasetNetworkInputChannel) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) UnknownHostException(java.net.UnknownHostException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException)

Example 64 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class LSMBTreeTestWorker method performOp.

@Override
public void performOp(ITupleReference tuple, TestOperation op) throws HyracksDataException {
    LSMTreeIndexAccessor accessor = (LSMTreeIndexAccessor) indexAccessor;
    IIndexCursor searchCursor = accessor.createSearchCursor(false);
    LSMBTreeOpContext concreteCtx = (LSMBTreeOpContext) accessor.getCtx();
    MultiComparator cmp = concreteCtx.getCmp();
    RangePredicate rangePred = new RangePredicate(tuple, tuple, true, true, cmp, cmp);
    switch(op) {
        case INSERT:
            try {
                accessor.insert(tuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.DUPLICATE_KEY) {
                    // Ignore duplicate keys, since we get random tuples.
                    throw e;
                }
            }
            break;
        case DELETE:
            // Create a tuple reference with only key fields.
            deleteTb.reset();
            for (int i = 0; i < numKeyFields; i++) {
                deleteTb.addField(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
            }
            deleteTuple.reset(deleteTb.getFieldEndOffsets(), deleteTb.getByteArray());
            try {
                accessor.delete(deleteTuple);
            } catch (HyracksDataException e) {
                // Ignore non-existant keys, since we get random tuples.
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
                    throw e;
                }
            }
            break;
        case UPDATE:
            try {
                accessor.update(tuple);
            } catch (HyracksDataException e) {
                if (e.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY && e.getErrorCode() != ErrorCode.INDEX_NOT_UPDATABLE) {
                    // Ignore not updateable exception due to numKeys == numFields.
                    throw e;
                }
            }
            break;
        case POINT_SEARCH:
            searchCursor.reset();
            rangePred.setLowKey(tuple, true);
            rangePred.setHighKey(tuple, true);
            accessor.search(searchCursor, rangePred);
            consumeCursorTuples(searchCursor);
            break;
        case SCAN:
            searchCursor.reset();
            rangePred.setLowKey(null, true);
            rangePred.setHighKey(null, true);
            accessor.search(searchCursor, rangePred);
            consumeCursorTuples(searchCursor);
            break;
        case MERGE:
            accessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), lsmBTree.getImmutableComponents());
            break;
        default:
            throw new HyracksDataException("Op " + op.toString() + " not supported.");
    }
}
Also used : LSMBTreeOpContext(org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTreeOpContext) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) MultiComparator(org.apache.hyracks.storage.common.MultiComparator) LSMTreeIndexAccessor(org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 65 with HyracksDataException

use of org.apache.hyracks.api.exceptions.HyracksDataException in project asterixdb by apache.

the class LookupAdapterFactory method createAdapter.

public LookupAdapter<T> createAdapter(IHyracksTaskContext ctx, int partition, RecordDescriptor inRecDesc, ExternalFileIndexAccessor snapshotAccessor, IFrameWriter writer) throws HyracksDataException {
    try {
        IRecordDataParser<T> dataParser = dataParserFactory.createRecordParser(ctx);
        ILookupRecordReader<? extends T> reader = readerFactory.createRecordReader(ctx, partition, snapshotAccessor);
        reader.configure(configuration);
        RecordIdReader ridReader = RecordIdReaderFactory.create(configuration, ridFields);
        return new LookupAdapter<>(dataParser, reader, inRecDesc, ridReader, retainInput, retainMissing, isMissingWriterFactory, ctx, writer);
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : RecordIdReader(org.apache.asterix.external.indexing.RecordIdReader) LookupAdapter(org.apache.asterix.external.dataset.adapter.LookupAdapter) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)566 IOException (java.io.IOException)209 DataOutput (java.io.DataOutput)96 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)78 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)75 IPointable (org.apache.hyracks.data.std.api.IPointable)73 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)70 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)67 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)67 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)64 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)61 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)60 ArrayList (java.util.ArrayList)57 ACIDException (org.apache.asterix.common.exceptions.ACIDException)56 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)56 ATypeTag (org.apache.asterix.om.types.ATypeTag)39 AsterixException (org.apache.asterix.common.exceptions.AsterixException)36 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)32 ByteBuffer (java.nio.ByteBuffer)30 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)27