Search in sources :

Example 11 with PDataType

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

Example 12 with PDataType

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

Example 13 with PDataType

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

Example 14 with PDataType

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

Example 15 with PDataType

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

Aggregations

PDataType (org.apache.phoenix.schema.types.PDataType)152 Expression (org.apache.phoenix.expression.Expression)54 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)31 SortOrder (org.apache.phoenix.schema.SortOrder)29 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)21 CoerceExpression (org.apache.phoenix.expression.CoerceExpression)18 Test (org.junit.Test)15 PDatum (org.apache.phoenix.schema.PDatum)12 BigDecimal (java.math.BigDecimal)11 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)11 List (java.util.List)10 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)10 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)10 SingleCellConstructorExpression (org.apache.phoenix.expression.SingleCellConstructorExpression)10 IOException (java.io.IOException)9 PreparedStatement (java.sql.PreparedStatement)7 Pair (org.apache.hadoop.hbase.util.Pair)7 Date (java.sql.Date)6 AndExpression (org.apache.phoenix.expression.AndExpression)6