use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class DayOfWeekFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression arg = getChildren().get(0);
if (!arg.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
return true;
}
long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
DateTime jodaDT = new DateTime(dateTime);
int day = jodaDT.getDayOfWeek();
PDataType returnDataType = getDataType();
byte[] byteValue = new byte[returnDataType.getByteSize()];
returnDataType.getCodec().encodeInt(day, byteValue, 0);
ptr.set(byteValue);
return true;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class DayOfYearFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression arg = getChildren().get(0);
if (!arg.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
return true;
}
long dateTime = inputCodec.decodeLong(ptr, arg.getSortOrder());
DateTime jodaDT = new DateTime(dateTime);
int day = jodaDT.getDayOfYear();
PDataType returnDataType = getDataType();
byte[] byteValue = new byte[returnDataType.getByteSize()];
returnDataType.getCodec().encodeInt(day, byteValue, 0);
ptr.set(byteValue);
return true;
}
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;
}
Aggregations