Search in sources :

Example 76 with PDataType

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

the class SortOrderIT method testNonPKCompare.

@Test
public void testNonPKCompare() throws Exception {
    List<Integer> expectedResults = Lists.newArrayList(2, 3, 4);
    Integer[] saltBuckets = new Integer[] { null, 3 };
    PDataType[] dataTypes = new PDataType[] { PDecimal.INSTANCE, PDouble.INSTANCE, PFloat.INSTANCE };
    for (Integer saltBucket : saltBuckets) {
        for (PDataType dataType : dataTypes) {
            for (SortOrder sortOrder : SortOrder.values()) {
                testCompareCompositeKey(saltBucket, dataType, sortOrder, "", expectedResults, "");
            }
        }
    }
}
Also used : BigInteger(java.math.BigInteger) PDataType(org.apache.phoenix.schema.types.PDataType) SortOrder(org.apache.phoenix.schema.SortOrder) Test(org.junit.Test)

Example 77 with PDataType

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

the class RoundJodaDateExpression method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    if (children.get(0).evaluate(tuple, ptr)) {
        if (ptr.getLength() == 0) {
            // child evaluated to null
            return true;
        }
        PDataType dataType = getDataType();
        long time = dataType.getCodec().decodeLong(ptr, children.get(0).getSortOrder());
        DateTime dt = new DateTime(time, ISOChronology.getInstanceUTC());
        long value = roundDateTime(dt);
        Date d = new Date(value);
        byte[] byteValue = dataType.toBytes(d);
        ptr.set(byteValue);
        return true;
    }
    return false;
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) DateTime(org.joda.time.DateTime) Date(java.sql.Date)

Example 78 with PDataType

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

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

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

the class RoundTimestampExpression method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    if (children.get(0).evaluate(tuple, ptr)) {
        SortOrder sortOrder = children.get(0).getSortOrder();
        PDataType dataType = getDataType();
        int nanos = dataType.getNanos(ptr, sortOrder);
        if (nanos >= HALF_OF_NANOS_IN_MILLI) {
            long timeMillis = dataType.getMillis(ptr, sortOrder);
            Timestamp roundedTs = new Timestamp(timeMillis + 1);
            byte[] byteValue = dataType.toBytes(roundedTs);
            ptr.set(byteValue);
        }
        // for timestamp we only support rounding up the milliseconds. 
        return true;
    }
    return false;
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) SortOrder(org.apache.phoenix.schema.SortOrder) Timestamp(java.sql.Timestamp) PUnsignedTimestamp(org.apache.phoenix.schema.types.PUnsignedTimestamp) PTimestamp(org.apache.phoenix.schema.types.PTimestamp)

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