use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class StringJoinDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final ListAccessor listAccessor = new ListAccessor();
private final DataOutput out = resultStorage.getDataOutput();
private final IScalarEvaluatorFactory listEvalFactory = args[0];
private final IScalarEvaluatorFactory sepEvalFactory = args[1];
private final IPointable inputArgList = new VoidPointable();
private final IPointable inputArgSep = new VoidPointable();
private final IScalarEvaluator evalList = listEvalFactory.createScalarEvaluator(ctx);
private final IScalarEvaluator evalSep = sepEvalFactory.createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);
private ISerializerDeserializer<AMissing> missingSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AMISSING);
private final byte[] tempLengthArray = new byte[5];
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalList.evaluate(tuple, inputArgList);
evalSep.evaluate(tuple, inputArgSep);
byte[] listBytes = inputArgList.getByteArray();
int listOffset = inputArgList.getStartOffset();
if (listBytes[listOffset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && listBytes[listOffset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, listBytes[listOffset], ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
}
byte[] sepBytes = inputArgSep.getByteArray();
int sepOffset = inputArgSep.getStartOffset();
if (sepBytes[sepOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, sepBytes[sepOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
int sepLen = UTF8StringUtil.getUTFLength(sepBytes, sepOffset + 1);
int sepMetaLen = UTF8StringUtil.getNumBytesToStoreLength(sepLen);
listAccessor.reset(listBytes, listOffset);
try {
// calculate length first
int utf8Len = 0;
int size = listAccessor.size();
for (int i = 0; i < size; i++) {
int itemOffset = listAccessor.getItemOffset(i);
ATypeTag itemType = listAccessor.getItemType(itemOffset);
// since the item itself has a typetag.
if (listAccessor.itemsAreSelfDescribing()) {
itemOffset += 1;
}
if (itemType != ATypeTag.STRING) {
if (itemType == ATypeTag.NULL) {
nullSerde.serialize(ANull.NULL, out);
result.set(resultStorage);
return;
}
if (itemType == ATypeTag.MISSING) {
missingSerde.serialize(AMissing.MISSING, out);
result.set(resultStorage);
return;
}
throw new UnsupportedItemTypeException(getIdentifier(), itemType.serialize());
}
int currentSize = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
if (i != size - 1 && currentSize != 0) {
utf8Len += sepLen;
}
utf8Len += currentSize;
}
out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
int cbytes = UTF8StringUtil.encodeUTF8Length(utf8Len, tempLengthArray, 0);
out.write(tempLengthArray, 0, cbytes);
for (int i = 0; i < listAccessor.size(); i++) {
int itemOffset = listAccessor.getItemOffset(i);
if (listAccessor.itemsAreSelfDescribing()) {
itemOffset += 1;
}
utf8Len = UTF8StringUtil.getUTFLength(listBytes, itemOffset);
out.write(listBytes, UTF8StringUtil.getNumBytesToStoreLength(utf8Len) + itemOffset, utf8Len);
for (int j = 0; j < sepLen; j++) {
out.writeByte(sepBytes[sepOffset + 1 + sepMetaLen + j]);
}
}
} catch (IOException | AsterixException ex) {
throw new HyracksDataException(ex);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class SleepDescriptor 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 IPointable argTime = new VoidPointable();
private final IScalarEvaluator evalValue = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator evalTime = args[1].createScalarEvaluator(ctx);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
evalValue.evaluate(tuple, result);
evalTime.evaluate(tuple, argTime);
final byte[] bytes = argTime.getByteArray();
final int offset = argTime.getStartOffset();
final long time = ATypeHierarchy.getLongValue(getIdentifier().getName(), 1, bytes, offset);
try {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.log(Level.INFO, ctx.getTaskAttemptId() + " sleeping for " + time + " ms");
}
Thread.sleep(time);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.log(Level.INFO, ctx.getTaskAttemptId() + " done sleeping for " + time + " ms");
}
}
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class Substring2Descriptor 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 argString = new VoidPointable();
private IPointable argStart = new VoidPointable();
private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
private final GrowableArray array = new GrowableArray();
private final UTF8StringBuilder builder = new UTF8StringBuilder();
private final UTF8StringPointable string = new UTF8StringPointable();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalString.evaluate(tuple, argString);
evalStart.evaluate(tuple, argStart);
byte[] bytes = argStart.getByteArray();
int offset = argStart.getStartOffset();
int start = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset) - 1;
bytes = argString.getByteArray();
offset = argString.getStartOffset();
int len = argString.getLength();
if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
string.set(bytes, offset + 1, len - 1);
array.reset();
try {
UTF8StringPointable.substr(string, start, Integer.MAX_VALUE, builder, array);
} catch (StringIndexOutOfBoundsException e) {
throw new RuntimeDataException(ErrorCode.OUT_OF_BOUND, getIdentifier(), 1, start);
} catch (IOException e) {
throw new HyracksDataException(e);
}
try {
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.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class LenDescriptor 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 final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
private final IPointable inputVal = new VoidPointable();
private final IScalarEvaluator evalList = args[0].createScalarEvaluator(ctx);
// result
private final AMutableInt64 res = new AMutableInt64(0);
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evalList.evaluate(tuple, inputVal);
byte[] serList = inputVal.getByteArray();
int offset = inputVal.getStartOffset();
if (serList[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && serList[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, serList[offset], ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
}
int numberOfitems = 0;
if (serList[offset] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
numberOfitems = AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset);
} else {
numberOfitems = AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset);
}
res.setValue(numberOfitems);
try {
int64Serde.serialize(res, out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference in project asterixdb by apache.
the class InjectFailureDescriptor 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 {
final IPointable argPtr = new VoidPointable();
final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
evals[0] = args[0].createScalarEvaluator(ctx);
evals[1] = args[1].createScalarEvaluator(ctx);
return new IScalarEvaluator() {
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
evals[1].evaluate(tuple, argPtr);
ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
if (typeTag == ATypeTag.BOOLEAN) {
boolean argResult = ABooleanSerializerDeserializer.getBoolean(argPtr.getByteArray(), argPtr.getStartOffset() + 1);
if (argResult) {
LOGGER.log(Level.SEVERE, ctx.getTaskAttemptId() + " injecting failure");
throw new RuntimeDataException(ErrorCode.INJECTED_FAILURE, getIdentifier());
}
}
// evaluate the real evaluator
evals[0].evaluate(tuple, argPtr);
result.set(argPtr.getByteArray(), argPtr.getStartOffset(), argPtr.getLength());
}
};
}
};
}
Aggregations