use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class StringLengthDescriptor 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 AMutableInt64 result = new AMutableInt64(0);
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private IPointable inputArg = new VoidPointable();
private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);
@SuppressWarnings("unchecked")
private ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);
@Override
public void evaluate(IFrameTupleReference tuple, IPointable resultPointable) throws HyracksDataException {
try {
resultStorage.reset();
eval.evaluate(tuple, inputArg);
byte[] serString = inputArg.getByteArray();
int offset = inputArg.getStartOffset();
if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
int len = UTF8StringUtil.getUTFLength(serString, offset + 1);
result.setValue(len);
int64Serde.serialize(result, out);
} else {
throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
resultPointable.set(resultStorage);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class StringRTrim2Descriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new AbstractBinaryStringStringEval(ctx, args[0], args[1], StringRTrim2Descriptor.this.getIdentifier()) {
private StringTrimmer stringTrimmer = new StringTrimmer(resultBuilder, resultArray);
@Override
protected void compute(UTF8StringPointable srcPtr, UTF8StringPointable patternPtr, UTF8StringPointable resultStrPtr) throws IOException {
stringTrimmer.build(patternPtr);
stringTrimmer.trim(srcPtr, resultStrPtr, false, true);
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class StringRepeatDescriptor 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() {
// Argument evaluators.
private IScalarEvaluator evalString = args[0].createScalarEvaluator(ctx);
private IScalarEvaluator evalStart = args[1].createScalarEvaluator(ctx);
// Argument pointers.
private IPointable argString = new VoidPointable();
private IPointable argNumber = new VoidPointable();
// For outputting the result.
private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private DataOutput out = resultStorage.getDataOutput();
private byte[] tempLengthArray = new byte[5];
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
// Calls argument evaluators.
evalString.evaluate(tuple, argString);
evalStart.evaluate(tuple, argNumber);
// Gets the repeating times.
byte[] bytes = argNumber.getByteArray();
int offset = argNumber.getStartOffset();
int repeatingTimes = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset);
// Checks repeatingTimes. It should be a non-negative value.
if (repeatingTimes < 0) {
throw new RuntimeDataException(ErrorCode.NEGATIVE_VALUE, getIdentifier(), 1, repeatingTimes);
}
// Gets the input string.
bytes = argString.getByteArray();
offset = argString.getStartOffset();
// Checks the type of the string argument.
if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Calculates the result string length.
int inputLen = UTF8StringUtil.getUTFLength(bytes, offset + 1);
// Can throw overflow exception.
int resultLen = Math.multiplyExact(inputLen, repeatingTimes);
int cbytes = UTF8StringUtil.encodeUTF8Length(resultLen, tempLengthArray, 0);
// Writes the output string.
int inputStringStart = offset + 1 + UTF8StringUtil.getNumBytesToStoreLength(inputLen);
try {
out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
out.write(tempLengthArray, 0, cbytes);
for (int numRepeats = 0; numRepeats < repeatingTimes; ++numRepeats) {
out.write(bytes, inputStringStart, inputLen);
}
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory 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.algebricks.runtime.base.IScalarEvaluatorFactory in project asterixdb by apache.
the class UUIDDescriptor method createEvaluatorFactory.
@Override
public IScalarEvaluatorFactory createEvaluatorFactory(IScalarEvaluatorFactory[] args) {
return new IScalarEvaluatorFactory() {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
private final ISerializerDeserializer<AUUID> uuidSerDe = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AUUID);
@Override
public IScalarEvaluator createScalarEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
return new IScalarEvaluator() {
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput output = resultStorage.getDataOutput();
private final AGeneratedUUID uuid = new AGeneratedUUID();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
uuid.nextUUID();
resultStorage.reset();
uuidSerDe.serialize(uuid, output);
result.set(resultStorage);
}
};
}
};
}
Aggregations