use of org.apache.phoenix.expression.Expression 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;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class MinAggregateFunction method newServerAggregator.
@Override
public Aggregator newServerAggregator(Configuration conf) {
Expression child = getAggregatorExpression();
final PDataType type = child.getDataType();
final Integer maxLength = child.getMaxLength();
return new MinAggregator(child.getSortOrder()) {
@Override
public PDataType getDataType() {
return type;
}
@Override
public Integer getMaxLength() {
return maxLength;
}
};
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class MinuteFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression expression = getChildExpression();
if (!expression.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
//means null
return true;
}
long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
int minute = (int) (((dateTime / 1000) % 3600) / 60);
PDataType returnType = getDataType();
byte[] byteValue = new byte[returnType.getByteSize()];
returnType.getCodec().encodeInt(minute, byteValue, 0);
ptr.set(byteValue);
return true;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class MonthFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression expression = getChildExpression();
if (!expression.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
//means null
return true;
}
long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
DateTime dt = new DateTime(dateTime);
int month = dt.getMonthOfYear();
PDataType returnType = getDataType();
byte[] byteValue = new byte[returnType.getByteSize()];
returnType.getCodec().encodeInt(month, byteValue, 0);
ptr.set(byteValue);
return true;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class JavaMathOneArgumentFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
PDataType returnType = getDataType();
Expression arg1Expr = children.get(0);
if (!arg1Expr.evaluate(tuple, ptr))
return false;
if (ptr.getLength() == 0)
return true;
double arg1 = getArg(arg1Expr, ptr);
ptr.set(new byte[returnType.getByteSize()]);
returnType.getCodec().encodeDouble(compute(arg1), ptr);
return true;
}
Aggregations