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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations