use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class ParseBinaryDescriptor 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 AbstractBinaryScalarEvaluator(ctx, args) {
@SuppressWarnings("unchecked")
private ISerializerDeserializer<ABinary> binarySerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABINARY);
private AMutableBinary aBinary = new AMutableBinary(new byte[0], 0, 0);
private final UTF8StringPointable stringPointable = new UTF8StringPointable();
private final UTF8StringPointable formatPointable = new UTF8StringPointable();
private final HexParser hexParser = new HexParser();
private final Base64Parser base64Parser = new Base64Parser();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
evaluators[1].evaluate(tuple, pointables[1]);
ATypeTag binaryTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
ATypeTag formatTag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, binaryTag, formatTag);
stringPointable.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength());
formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1, pointables[1].getLength());
if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
hexParser.generateByteArrayFromHexString(stringPointable.getByteArray(), stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
aBinary.setValue(hexParser.getByteArray(), 0, hexParser.getLength());
} else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
base64Parser.generatePureByteArrayFromBase64String(stringPointable.getByteArray(), stringPointable.getCharStartOffset(), stringPointable.getUTF8Length());
aBinary.setValue(base64Parser.getByteArray(), 0, base64Parser.getLength());
} else {
throw new UnsupportedItemTypeException(getIdentifier(), formatTag.serialize());
}
binarySerde.serialize(aBinary, dataOutput);
result.set(resultStorage);
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class StringSplitDescriptor 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 final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);
private final IScalarEvaluator patternEval = args[1].createScalarEvaluator(ctx);
// Argument pointers.
private final IPointable argString = new VoidPointable();
private final IPointable argPattern = new VoidPointable();
private final UTF8StringPointable argStrPtr = new UTF8StringPointable();
private final UTF8StringPointable argPatternPtr = new UTF8StringPointable();
// For an output string item.
private final ArrayBackedValueStorage itemStorge = new ArrayBackedValueStorage();
private final DataOutput itemOut = itemStorge.getDataOutput();
private final byte[] tempLengthArray = new byte[5];
// For the output list of strings.
private final AOrderedListType intListType = new AOrderedListType(BuiltinType.ASTRING, null);
private final OrderedListBuilder listBuilder = new OrderedListBuilder();
private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();
private final DataOutput out = resultStorage.getDataOutput();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
try {
resultStorage.reset();
// Calls argument evaluators.
stringEval.evaluate(tuple, argString);
patternEval.evaluate(tuple, argPattern);
// Gets the bytes of the source string.
byte[] srcString = argString.getByteArray();
int srcOffset = argString.getStartOffset();
int srcLen = argString.getLength();
// Type check for the first argument.
if (srcString[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 0, srcString[srcOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Gets the bytes of the pattern string.
byte[] patternString = argPattern.getByteArray();
int patternOffset = argPattern.getStartOffset();
int patternLen = argPattern.getLength();
// Type check for the second argument.
if (patternString[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
throw new TypeMismatchException(getIdentifier(), 1, patternString[patternOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
}
// Sets the UTF8 String pointables.
argStrPtr.set(srcString, srcOffset + 1, srcLen - 1);
argPatternPtr.set(patternString, patternOffset + 1, patternLen - 1);
// Gets the string length of the source string.
int inputStringLen = UTF8StringUtil.getUTFLength(srcString, srcOffset + 1);
int inputStringStart = srcOffset + 1 + UTF8StringUtil.getNumBytesToStoreLength(inputStringLen);
// Gets the string length of the pattern string.
int inputPatternLen = UTF8StringUtil.getUTFLength(patternString, patternOffset + 1);
// Handles the case that the pattern is "".
boolean emptyStringPattern = inputPatternLen == 0;
// Builds a list of strings.
listBuilder.reset(intListType);
int itemStrStart = 0;
int nextMatchStart;
while (itemStrStart < inputStringLen && (nextMatchStart = UTF8StringPointable.find(argStrPtr, argPatternPtr, false, itemStrStart)) >= 0) {
// Adds an item string.
addItemString(srcString, inputStringStart, itemStrStart, emptyStringPattern ? nextMatchStart + 1 : nextMatchStart);
itemStrStart = nextMatchStart + (emptyStringPattern ? 1 : inputPatternLen);
}
if (!emptyStringPattern) {
addItemString(srcString, inputStringStart, itemStrStart, inputStringLen);
}
listBuilder.write(out, true);
result.set(resultStorage);
} catch (IOException e1) {
throw new HyracksDataException(e1);
}
}
private void addItemString(byte[] srcString, int inputStringStart, int itemStartOffset, int nextMatchStart) throws IOException {
int itemLen = nextMatchStart - itemStartOffset;
int cbytes = UTF8StringUtil.encodeUTF8Length(itemLen, tempLengthArray, 0);
itemStorge.reset();
itemOut.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
itemOut.write(tempLengthArray, 0, cbytes);
if (itemLen > 0) {
itemOut.write(srcString, inputStringStart + itemStartOffset, itemLen);
}
listBuilder.addItem(itemStorge);
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable in project asterixdb by apache.
the class StringTrim2Descriptor 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], StringTrim2Descriptor.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, true, true);
}
};
}
};
}
use of org.apache.hyracks.data.std.primitive.UTF8StringPointable 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.data.std.primitive.UTF8StringPointable 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);
}
};
}
};
}
Aggregations