Search in sources :

Example 76 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class SignFunctionTest method testExpression.

private static void testExpression(LiteralExpression literal, Integer expected) throws SQLException {
    List<Expression> expressions = Lists.newArrayList((Expression) literal);
    Expression signFunction = new SignFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    signFunction.evaluate(null, ptr);
    Integer result = (Integer) signFunction.getDataType().toObject(ptr, signFunction.getSortOrder());
    assertTrue(result.compareTo(expected) == 0);
}
Also used : PInteger(org.apache.phoenix.schema.types.PInteger) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) SignFunction(org.apache.phoenix.expression.function.SignFunction)

Example 77 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class SortOrderExpressionTest method runCompareTest.

private void runCompareTest(CompareOp op, boolean expectedResult, Object lhsValue, PDataType lhsDataType, Object rhsValue, PDataType rhsDataType) throws Exception {
    List<Expression> args;
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    args = Lists.newArrayList(getLiteral(lhsValue, lhsDataType), getLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhsDataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
    args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), getLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
    args = Lists.newArrayList(getLiteral(lhsValue, lhsDataType), getInvertedLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhsDataType: " + lhsDataType + " rhs (inverted) dataType: " + rhsDataType);
    args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), getInvertedLiteral(rhsValue, rhsDataType));
    evaluateAndAssertResult(ComparisonExpression.create(op, args, ptr, true), expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhs (inverted) dataType: " + rhsDataType);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression)

Example 78 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class SortOrderExpressionTest method evaluateAndAssertResult.

private void evaluateAndAssertResult(Expression expression, Object expectedResult, String context) {
    context = context == null ? "" : context;
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    assertTrue(expression.evaluate(null, ptr));
    PDataType dataType = expression.getDataType();
    SortOrder sortOrder = expression.getSortOrder();
    Object result = dataType.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), dataType, sortOrder);
    assertEquals(context, expectedResult, result);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PDataType(org.apache.phoenix.schema.types.PDataType) SortOrder(org.apache.phoenix.schema.SortOrder)

Example 79 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testFloorDateExpressionWithMultiplier.

@Test
public void testFloorDateExpressionWithMultiplier() throws Exception {
    Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.SECOND, 10);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    floorDateExpression.evaluate(null, ptr);
    Object result = floorDateExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof Date);
    Date resultDate = (Date) result;
    assertEquals(DateUtil.parseDate("2012-01-01 14:25:20"), resultDate);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) PDate(org.apache.phoenix.schema.types.PDate) Date(java.sql.Date) Test(org.junit.Test)

Example 80 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testFloorDateExpression.

@Test
public void testFloorDateExpression() throws Exception {
    LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.DAY);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    floorDateExpression.evaluate(null, ptr);
    Object result = floorDateExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof Date);
    Date resultDate = (Date) result;
    assertEquals(DateUtil.parseDate("2012-01-01 00:00:00"), resultDate);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) RoundDecimalExpression(org.apache.phoenix.expression.function.RoundDecimalExpression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) CeilDateExpression(org.apache.phoenix.expression.function.CeilDateExpression) CeilDecimalExpression(org.apache.phoenix.expression.function.CeilDecimalExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression) PDate(org.apache.phoenix.schema.types.PDate) Date(java.sql.Date) Test(org.junit.Test)

Aggregations

ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)296 Test (org.junit.Test)86 Expression (org.apache.phoenix.expression.Expression)36 IOException (java.io.IOException)33 PhoenixArray (org.apache.phoenix.schema.types.PhoenixArray)30 ArrayList (java.util.ArrayList)28 Configuration (org.apache.hadoop.conf.Configuration)28 Result (org.apache.hadoop.hbase.client.Result)28 Cell (org.apache.hadoop.hbase.Cell)27 KeyValue (org.apache.hadoop.hbase.KeyValue)27 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)27 PTable (org.apache.phoenix.schema.PTable)27 PDataType (org.apache.phoenix.schema.types.PDataType)26 PSmallint (org.apache.phoenix.schema.types.PSmallint)25 PTinyint (org.apache.phoenix.schema.types.PTinyint)23 Put (org.apache.hadoop.hbase.client.Put)20 PUnsignedSmallint (org.apache.phoenix.schema.types.PUnsignedSmallint)20 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)20 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)19 List (java.util.List)18