use of org.apache.phoenix.expression.function.FloorDateExpression 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.phoenix.expression.function.FloorDateExpression 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.phoenix.expression.function.FloorDateExpression 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);
}
use of org.apache.phoenix.expression.function.FloorDateExpression in project phoenix by apache.
the class FloorParseNode method getFloorExpression.
public static Expression getFloorExpression(List<Expression> children) throws SQLException {
final Expression firstChild = children.get(0);
final PDataType firstChildDataType = firstChild.getDataType();
//Which is exactly what FloorDateExpression does too.
if (firstChildDataType.isCoercibleTo(PTimestamp.INSTANCE)) {
return FloorDateExpression.create(children);
} else if (firstChildDataType.isCoercibleTo(PDecimal.INSTANCE)) {
return FloorDecimalExpression.create(children);
} else {
throw TypeMismatchException.newException(firstChildDataType, "1");
}
}
Aggregations