use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundDateExpressionWithMultiplier.
@Test
public void testRoundDateExpressionWithMultiplier() throws Exception {
Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.MINUTE, 10);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
roundDateExpression.evaluate(null, ptr);
Object result = roundDateExpression.getDataType().toObject(ptr);
assertTrue(result instanceof Date);
Date resultDate = (Date) result;
assertEquals(DateUtil.parseDate("2012-01-01 14:30:00"), resultDate);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testFloorDateExpressionForWeek.
@Test
public void testFloorDateExpressionForWeek() throws Exception {
Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2016-01-07 08:17:28"), PDate.INSTANCE);
Expression floorDateExpression = FloorDateExpression.create(dateLiteral, TimeUnit.WEEK);
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("2016-01-04 00:00:00"), resultDate);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testRoundDecimalExpression.
// Decimal Expression Tests
@Test
public void testRoundDecimalExpression() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
Expression roundDecimalExpression = RoundDecimalExpression.create(decimalLiteral, 3);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
roundDecimalExpression.evaluate(null, ptr);
Object result = roundDecimalExpression.getDataType().toObject(ptr);
assertTrue(result instanceof BigDecimal);
BigDecimal resultDecimal = (BigDecimal) result;
assertEquals(BigDecimal.valueOf(1.239), resultDecimal);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class RoundFloorCeilExpressionsTest method testFloorDecimalExpression.
@Test
public void testFloorDecimalExpression() throws Exception {
LiteralExpression decimalLiteral = LiteralExpression.newConstant(1.23898, PDecimal.INSTANCE);
Expression floorDecimalExpression = FloorDecimalExpression.create(decimalLiteral, 3);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
floorDecimalExpression.evaluate(null, ptr);
Object result = floorDecimalExpression.getDataType().toObject(ptr);
assertTrue(result instanceof BigDecimal);
BigDecimal resultDecimal = (BigDecimal) result;
assertEquals(BigDecimal.valueOf(1.238), resultDecimal);
}
use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.
the class CbrtFunctionTest method testExpression.
private static void testExpression(LiteralExpression literal, double expected) throws SQLException {
List<Expression> expressions = Lists.newArrayList((Expression) literal);
Expression cbrtFunction = new CbrtFunction(expressions);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
cbrtFunction.evaluate(null, ptr);
Double result = (Double) cbrtFunction.getDataType().toObject(ptr, cbrtFunction.getSortOrder());
assertTrue(Math.abs(result.doubleValue() - expected) <= 1e-9);
}
Aggregations