Search in sources :

Example 1 with RoundDateExpression

use of org.apache.phoenix.expression.function.RoundDateExpression 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);
}
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 RoundDateExpression

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

the class RoundFloorCeilExpressionsTest method testRoundDateExpression.

// Date Expression Tests
@Test
public void testRoundDateExpression() throws Exception {
    LiteralExpression dateLiteral = LiteralExpression.newConstant(DateUtil.parseDate("2012-01-01 14:25:28"), PDate.INSTANCE);
    Expression roundDateExpression = RoundDateExpression.create(dateLiteral, TimeUnit.DAY);
    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-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