Search in sources :

Example 1 with FloorDateExpression

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

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);
}
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 3 with FloorDateExpression

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);
}
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 4 with FloorDateExpression

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");
    }
}
Also used : PDataType(org.apache.phoenix.schema.types.PDataType) Expression(org.apache.phoenix.expression.Expression) FloorDateExpression(org.apache.phoenix.expression.function.FloorDateExpression) FloorDecimalExpression(org.apache.phoenix.expression.function.FloorDecimalExpression)

Aggregations

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