use of org.apache.hyracks.util.bytes.Base64Parser 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);
}
};
}
};
}
Aggregations