use of org.apache.phoenix.exception.UndecodableByteException in project phoenix by apache.
the class LengthFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression child = getStringExpression();
if (!child.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
return true;
}
int len;
if (child.getDataType() == PChar.INSTANCE) {
// Only single-byte characters allowed in CHAR
len = ptr.getLength();
} else {
try {
len = StringUtil.calculateUTF8Length(ptr.get(), ptr.getOffset(), ptr.getLength(), child.getSortOrder());
} catch (UndecodableByteException e) {
return false;
}
}
ptr.set(PInteger.INSTANCE.toBytes(len));
return true;
}
Aggregations