Search in sources :

Example 61 with ImmutableBytesWritable

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);
}
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 62 with ImmutableBytesWritable

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);
}
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 63 with ImmutableBytesWritable

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);
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 64 with ImmutableBytesWritable

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);
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 65 with ImmutableBytesWritable

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);
}
Also used : CbrtFunction(org.apache.phoenix.expression.function.CbrtFunction) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PUnsignedDouble(org.apache.phoenix.schema.types.PUnsignedDouble) PDouble(org.apache.phoenix.schema.types.PDouble)

Aggregations

ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)296 Test (org.junit.Test)86 Expression (org.apache.phoenix.expression.Expression)36 IOException (java.io.IOException)33 PhoenixArray (org.apache.phoenix.schema.types.PhoenixArray)30 ArrayList (java.util.ArrayList)28 Configuration (org.apache.hadoop.conf.Configuration)28 Result (org.apache.hadoop.hbase.client.Result)28 Cell (org.apache.hadoop.hbase.Cell)27 KeyValue (org.apache.hadoop.hbase.KeyValue)27 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)27 PTable (org.apache.phoenix.schema.PTable)27 PDataType (org.apache.phoenix.schema.types.PDataType)26 PSmallint (org.apache.phoenix.schema.types.PSmallint)25 PTinyint (org.apache.phoenix.schema.types.PTinyint)23 Put (org.apache.hadoop.hbase.client.Put)20 PUnsignedSmallint (org.apache.phoenix.schema.types.PUnsignedSmallint)20 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)20 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)19 List (java.util.List)18