use of org.apache.phoenix.schema.types.PDataType 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.schema.types.PDataType 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.schema.types.PDataType in project phoenix by apache.
the class DistinctValueAggregateFunction method newClientAggregator.
@Override
public DistinctValueWithCountClientAggregator newClientAggregator() {
PDataType baseType = getAggregatorExpression().getDataType().isArrayType() ? PVarbinary.INSTANCE : getAggregatorExpression().getDataType();
PDataType resultType = PDataType.fromTypeId(baseType.getSqlType() + PDataType.ARRAY_TYPE_BASE);
return new DistinctValueClientAggregator(getAggregatorExpression().getSortOrder(), baseType, resultType);
}
use of org.apache.phoenix.schema.types.PDataType 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.schema.types.PDataType 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