Search in sources :

Example 1 with PBinaryBase

use of org.apache.phoenix.schema.types.PBinaryBase in project phoenix by apache.

the class SetBitFunction 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 & 0x1);
    // 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() * Byte.SIZE;
    offset = (offset % len + len) % len;
    // set result
    ((PBinaryBase) dataExpr.getDataType()).setBit(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 2 with PBinaryBase

use of org.apache.phoenix.schema.types.PBinaryBase in project phoenix by apache.

the class GetBitFunction method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    // get offset parameter
    int offset;
    if (offsetPreCompute == null) {
        Expression offsetExpr = children.get(1);
        if (!offsetExpr.evaluate(tuple, ptr))
            return false;
        offset = (Integer) PInteger.INSTANCE.toObject(ptr, offsetExpr.getSortOrder());
    } else
        offset = offsetPreCompute;
    // 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() * Byte.SIZE;
    offset = (offset % len + len) % len;
    // set result
    ((PBinaryBase) dataExpr.getDataType()).getBit(ptr, dataExpr.getSortOrder(), offset, ptr);
    return true;
}
Also used : Expression(org.apache.phoenix.expression.Expression) PBinaryBase(org.apache.phoenix.schema.types.PBinaryBase)

Example 3 with PBinaryBase

use of org.apache.phoenix.schema.types.PBinaryBase in project phoenix by apache.

the class GetByteFunction method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    // get offset parameter
    int offset;
    if (offsetPreCompute == null) {
        Expression offsetExpr = children.get(1);
        if (!offsetExpr.evaluate(tuple, ptr))
            return false;
        offset = (Integer) PInteger.INSTANCE.toObject(ptr, offsetExpr.getSortOrder());
    } else
        offset = offsetPreCompute;
    // 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()).getByte(ptr, dataExpr.getSortOrder(), offset, ptr);
    return true;
}
Also used : Expression(org.apache.phoenix.expression.Expression) PBinaryBase(org.apache.phoenix.schema.types.PBinaryBase)

Example 4 with PBinaryBase

use of org.apache.phoenix.schema.types.PBinaryBase 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 5 with PBinaryBase

use of org.apache.phoenix.schema.types.PBinaryBase in project phoenix by apache.

the class OctetLengthFunction method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    // get binary data parameter
    Expression dataExpr = children.get(0);
    if (!dataExpr.evaluate(tuple, ptr))
        return false;
    // set result
    ((PBinaryBase) dataExpr.getDataType()).octetLength(ptr, dataExpr.getSortOrder(), ptr);
    return true;
}
Also used : Expression(org.apache.phoenix.expression.Expression) PBinaryBase(org.apache.phoenix.schema.types.PBinaryBase)

Aggregations

Expression (org.apache.phoenix.expression.Expression)5 PBinaryBase (org.apache.phoenix.schema.types.PBinaryBase)5 PInteger (org.apache.phoenix.schema.types.PInteger)2