Search in sources :

Example 11 with Expression

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

Example 12 with Expression

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

Example 13 with Expression

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

Example 14 with Expression

use of org.apache.phoenix.expression.Expression in project phoenix by apache.

the class MonthFunction 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());
    DateTime dt = new DateTime(dateTime);
    int month = dt.getMonthOfYear();
    PDataType returnType = getDataType();
    byte[] byteValue = new byte[returnType.getByteSize()];
    returnType.getCodec().encodeInt(month, byteValue, 0);
    ptr.set(byteValue);
    return true;
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) Expression(org.apache.phoenix.expression.Expression) DateTime(org.joda.time.DateTime)

Example 15 with Expression

use of org.apache.phoenix.expression.Expression in project phoenix by apache.

the class JavaMathOneArgumentFunction method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    PDataType returnType = getDataType();
    Expression arg1Expr = children.get(0);
    if (!arg1Expr.evaluate(tuple, ptr))
        return false;
    if (ptr.getLength() == 0)
        return true;
    double arg1 = getArg(arg1Expr, ptr);
    ptr.set(new byte[returnType.getByteSize()]);
    returnType.getCodec().encodeDouble(compute(arg1), ptr);
    return true;
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) Expression(org.apache.phoenix.expression.Expression)

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