Search in sources :

Example 91 with Expression

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;
}
Also used : Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) BigDecimal(java.math.BigDecimal)

Example 92 with Expression

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);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PDataType(org.apache.phoenix.schema.types.PDataType) Expression(org.apache.phoenix.expression.Expression) ByteBasedLikeExpression(org.apache.phoenix.expression.ByteBasedLikeExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) InListExpression(org.apache.phoenix.expression.InListExpression) NotExpression(org.apache.phoenix.expression.NotExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) ComparisonExpression(org.apache.phoenix.expression.ComparisonExpression) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) StringBasedLikeExpression(org.apache.phoenix.expression.StringBasedLikeExpression) AndExpression(org.apache.phoenix.expression.AndExpression) OrExpression(org.apache.phoenix.expression.OrExpression) ArrayList(java.util.ArrayList)

Example 93 with Expression

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;
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) Expression(org.apache.phoenix.expression.Expression)

Example 94 with Expression

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;
}
Also used : PInteger(org.apache.phoenix.schema.types.PInteger) Expression(org.apache.phoenix.expression.Expression) PBinaryBase(org.apache.phoenix.schema.types.PBinaryBase)

Example 95 with Expression

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;
}
Also used : Expression(org.apache.phoenix.expression.Expression) PTableType(org.apache.phoenix.schema.PTableType)

Aggregations

Expression (org.apache.phoenix.expression.Expression)182 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)101 PDataType (org.apache.phoenix.schema.types.PDataType)54 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)39 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)37 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)33 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)30 PTable (org.apache.phoenix.schema.PTable)25 ParseNode (org.apache.phoenix.parse.ParseNode)23 RowValueConstructorExpression (org.apache.phoenix.expression.RowValueConstructorExpression)22 Test (org.junit.Test)22 ComparisonExpression (org.apache.phoenix.expression.ComparisonExpression)21 AndExpression (org.apache.phoenix.expression.AndExpression)20 SingleCellColumnExpression (org.apache.phoenix.expression.SingleCellColumnExpression)20 PColumn (org.apache.phoenix.schema.PColumn)20 ArrayList (java.util.ArrayList)19 InListExpression (org.apache.phoenix.expression.InListExpression)17 IsNullExpression (org.apache.phoenix.expression.IsNullExpression)16 OrExpression (org.apache.phoenix.expression.OrExpression)16 LikeExpression (org.apache.phoenix.expression.LikeExpression)15