use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class RoundDecimalExpression method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression childExpr = children.get(0);
if (childExpr.evaluate(tuple, ptr)) {
BigDecimal value = (BigDecimal) PDecimal.INSTANCE.toObject(ptr, childExpr.getDataType(), childExpr.getSortOrder());
BigDecimal scaledValue = value.setScale(scale, getRoundingMode());
ptr.set(PDecimal.INSTANCE.toBytes(scaledValue));
return true;
}
return false;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class TestUtil method in.
public static Expression in(Expression e, Object... literals) throws SQLException {
PDataType childType = e.getDataType();
List<Expression> expressions = new ArrayList<Expression>(literals.length + 1);
expressions.add(e);
for (Object o : literals) {
expressions.add(LiteralExpression.newConstant(o, childType));
}
return InListExpression.create(expressions, false, new ImmutableBytesWritable(), true);
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class SecondFunction 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 sec = (int) ((dateTime / 1000) % 60);
PDataType returnType = getDataType();
byte[] byteValue = new byte[returnType.getByteSize()];
returnType.getCodec().encodeInt(sec, byteValue, 0);
ptr.set(byteValue);
return true;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class SetByteFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
// get offset parameter
Expression offsetExpr = children.get(1);
if (!offsetExpr.evaluate(tuple, ptr))
return false;
int offset = (Integer) PInteger.INSTANCE.toObject(ptr, offsetExpr.getSortOrder());
// get newValue parameter
Expression newValueExpr = children.get(2);
if (!newValueExpr.evaluate(tuple, ptr))
return false;
int newValue = (Integer) PInteger.INSTANCE.toObject(ptr, newValueExpr.getSortOrder());
byte newByteValue = (byte) (newValue & 0xff);
// get binary data parameter
Expression dataExpr = children.get(0);
if (!dataExpr.evaluate(tuple, ptr))
return false;
if (ptr.getLength() == 0)
return true;
int len = ptr.getLength();
offset = (offset % len + len) % len;
// set result
((PBinaryBase) dataExpr.getDataType()).setByte(ptr, dataExpr.getSortOrder(), offset, newByteValue, ptr);
return true;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class SQLTableTypeFunction method evaluate.
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
Expression child = children.get(0);
if (!child.evaluate(tuple, ptr)) {
return false;
}
if (ptr.getLength() == 0) {
return true;
}
PTableType tableType = PTableType.fromSerializedValue(ptr.get()[ptr.getOffset()]);
ptr.set(tableType.getValue().getBytes());
return true;
}
Aggregations