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);
}
};
}
};
}
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);
}
}
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);
}
}
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.");
}
}
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);
}
}
Aggregations