}
@Override
protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
throws AlgebricksException {
final TaggedValuePointable tvp = new TaggedValuePointable();
final UTF8StringPointable stringp1 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
final UTF8StringPointable stringp2 = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
final SequencePointable seq = (SequencePointable) SequencePointable.FACTORY.createPointable();
return new AbstractTaggedValueArgumentScalarEvaluator(args) {
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
abvs.reset();
TaggedValuePointable tvp1 = args[0];
TaggedValuePointable tvp2 = args[1];
// Only accept a sequence of strings and a string.
if (!FunctionHelper.isDerivedFromString(tvp2.getTag())) {
throw new SystemException(ErrorCode.FORG0006);
}
if (FunctionHelper.isDerivedFromString(tvp1.getTag())) {
try {
// Return first parameter as a string.
DataOutput out = abvs.getDataOutput();
tvp1.getValue(stringp1);
out.write(ValueTag.XS_STRING_TAG);
out.write(stringp1.getByteArray(), stringp1.getStartOffset(), stringp1.getLength());
result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
} catch (IOException e) {
throw new SystemException(ErrorCode.SYSE0001, e);
}
return;
} else if (tvp1.getTag() != ValueTag.SEQUENCE_TAG) {
throw new SystemException(ErrorCode.FORG0006);
}
// Operate on a sequence.
tvp1.getValue(seq);
tvp2.getValue(stringp2);
try {
// Byte Format: Type (1 byte) + String Length (2 bytes) + String.
DataOutput out = abvs.getDataOutput();
out.write(ValueTag.XS_STRING_TAG);