Search in sources :

Example 1 with CeilDateExpression

use of org.apache.phoenix.expression.function.CeilDateExpression in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testCeilDateExpressionWithMultiplier.

@Test
public void testCeilDateExpressionWithMultiplier() throws Exception {
    Expression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.SECOND, 10);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ceilDateExpression.evaluate(null, ptr);
    Object result = ceilDateExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof Date);
    Date resultDate = (Date) result;
    assertEquals(DateUtil.parseDate("2012-01-01 14:25:30"), 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 2 with CeilDateExpression

use of org.apache.phoenix.expression.function.CeilDateExpression in project phoenix by apache.

the class RoundFloorCeilExpressionsTest method testCeilDateExpression.

@Test
public void testCeilDateExpression() throws Exception {
    LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression ceilDateExpression = CeilDateExpression.create(dateLiteral, TimeUnit.DAY);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ceilDateExpression.evaluate(null, ptr);
    Object result = ceilDateExpression.getDataType().toObject(ptr);
    assertTrue(result instanceof Date);
    Date resultDate = (Date) result;
    assertEquals(DateUtil.parseDate("2012-01-02 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

Date (java.sql.Date)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 CeilDateExpression (org.apache.phoenix.expression.function.CeilDateExpression)2 CeilDecimalExpression (org.apache.phoenix.expression.function.CeilDecimalExpression)2 FloorDateExpression (org.apache.phoenix.expression.function.FloorDateExpression)2 FloorDecimalExpression (org.apache.phoenix.expression.function.FloorDecimalExpression)2 RoundDateExpression (org.apache.phoenix.expression.function.RoundDateExpression)2 RoundDecimalExpression (org.apache.phoenix.expression.function.RoundDecimalExpression)2 PDate (org.apache.phoenix.schema.types.PDate)2 Test (org.junit.Test)2