use of org.apache.hyracks.data.std.api.IPointable 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.data.std.api.IPointable 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.data.std.api.IPointable 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());
}
};
}
};
}
use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.
the class PointablePrimitiveValueProviderFactory method createPrimitiveValueProvider.
@Override
public IPrimitiveValueProvider createPrimitiveValueProvider() {
final IPointable p = pf.createPointable();
ITypeTraits traits = pf.getTypeTraits();
assert traits.isFixedLength();
final int length = traits.getFixedLength();
return new IPrimitiveValueProvider() {
@Override
public double getValue(byte[] bytes, int offset) {
p.set(bytes, offset, length);
return ((INumeric) p).doubleValue();
}
};
}
use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.
the class IntegerEqFunctionEvaluatorFactory method createScalarEvaluator.
@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private IPointable out1 = new VoidPointable();
private IPointable out2 = new VoidPointable();
private IScalarEvaluator eval1 = arg1Factory.createScalarEvaluator(ctx);
private IScalarEvaluator eval2 = arg2Factory.createScalarEvaluator(ctx);
private byte[] resultData = new byte[1];
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
eval1.evaluate(tuple, out1);
eval2.evaluate(tuple, out2);
int v1 = IntegerPointable.getInteger(out1.getByteArray(), out1.getStartOffset());
int v2 = IntegerPointable.getInteger(out2.getByteArray(), out2.getStartOffset());
boolean r = v1 == v2;
resultData[0] = r ? (byte) 1 : (byte) 0;
result.set(resultData, 0, 1);
}
};
}
Aggregations