use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.
the class PrintBinaryDescriptor 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) {
private StringBuilder stringBuilder = new StringBuilder();
private final ByteArrayPointable byteArrayPtr = new ByteArrayPointable();
private final UTF8StringPointable formatPointable = new UTF8StringPointable();
private final UTF8StringWriter writer = new UTF8StringWriter();
@Override
public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
resultStorage.reset();
evaluators[0].evaluate(tuple, pointables[0]);
evaluators[1].evaluate(tuple, pointables[1]);
try {
ATypeTag arg0Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[0].getByteArray()[pointables[0].getStartOffset()]];
ATypeTag arg1Tag = ATypeTag.VALUE_TYPE_MAPPING[pointables[1].getByteArray()[pointables[1].getStartOffset()]];
checkTypeMachingThrowsIfNot(getIdentifier().getName(), EXPECTED_INPUT_TAGS, arg0Tag, arg1Tag);
byteArrayPtr.set(pointables[0].getByteArray(), pointables[0].getStartOffset() + 1, pointables[0].getLength());
formatPointable.set(pointables[1].getByteArray(), pointables[1].getStartOffset() + 1, pointables[1].getLength());
int lengthBinary = byteArrayPtr.getContentLength();
stringBuilder.setLength(0);
if (HEX_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
HexPrinter.printHexString(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
} else if (BASE64_FORMAT.ignoreCaseCompareTo(formatPointable) == 0) {
Base64Printer.printBase64Binary(byteArrayPtr.getByteArray(), byteArrayPtr.getContentStartOffset(), lengthBinary, stringBuilder);
} else {
throw new UnsupportedItemTypeException(getIdentifier(), arg1Tag.serialize());
}
dataOutput.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
writer.writeUTF8(stringBuilder.toString(), dataOutput);
} catch (IOException e) {
throw new HyracksDataException(e);
}
result.set(resultStorage);
}
};
}
};
}
Aggregations