Search in sources :

Example 66 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingAllPDataTypesToVarBinary.

@Test
public void testCoerceExpressionSupportsCoercingAllPDataTypesToVarBinary() throws Exception {
    for (PDataType p : PDataType.values()) {
        if (!p.isArrayType()) {
            LiteralExpression v = LiteralExpression.newConstant(map.get(p.getJavaClass()), p);
            CoerceExpression e = new CoerceExpression(v, PVarbinary.INSTANCE);
            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
            e.evaluate(null, ptr);
            Object obj = e.getDataType().toObject(ptr);
            assertTrue("Coercing to VARBINARY failed for PDataType " + p, obj instanceof byte[]);
        }
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PDataType(org.apache.phoenix.schema.types.PDataType) Test(org.junit.Test)

Example 67 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingAllPDataTypesToBinary.

@Test
public void testCoerceExpressionSupportsCoercingAllPDataTypesToBinary() throws Exception {
    for (PDataType p : PDataType.values()) {
        if (!p.isArrayType()) {
            LiteralExpression v = LiteralExpression.newConstant(map.get(p.getJavaClass()), p);
            CoerceExpression e = new CoerceExpression(v, PBinary.INSTANCE);
            ImmutableBytesWritable ptr = new ImmutableBytesWritable();
            e.evaluate(null, ptr);
            Object obj = e.getDataType().toObject(ptr);
            assertTrue("Coercing to BINARY failed for PDataType " + p, obj instanceof byte[]);
        }
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PDataType(org.apache.phoenix.schema.types.PDataType) Test(org.junit.Test)

Example 68 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingCharToVarchar.

@Test
public void testCoerceExpressionSupportsCoercingCharToVarchar() throws Exception {
    LiteralExpression v = LiteralExpression.newConstant("a", PChar.INSTANCE);
    CoerceExpression e = new CoerceExpression(v, PVarchar.INSTANCE);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    e.evaluate(null, ptr);
    Object obj = e.getDataType().toObject(ptr);
    assertTrue(obj instanceof String);
    String value = (String) obj;
    assertTrue(value.equals("a"));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Test(org.junit.Test)

Example 69 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingIntToLong.

@Test
public void testCoerceExpressionSupportsCoercingIntToLong() throws Exception {
    LiteralExpression v = LiteralExpression.newConstant(1, PInteger.INSTANCE);
    CoerceExpression e = new CoerceExpression(v, PLong.INSTANCE);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    e.evaluate(null, ptr);
    Object obj = e.getDataType().toObject(ptr);
    assertTrue(obj instanceof Long);
    Long value = (Long) obj;
    assertTrue(value.equals(Long.valueOf(1)));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PLong(org.apache.phoenix.schema.types.PLong) Test(org.junit.Test)

Example 70 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable in project phoenix by apache.

the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingIntToDecimal.

@Test
public void testCoerceExpressionSupportsCoercingIntToDecimal() throws Exception {
    LiteralExpression v = LiteralExpression.newConstant(1, PInteger.INSTANCE);
    CoerceExpression e = new CoerceExpression(v, PDecimal.INSTANCE);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    e.evaluate(null, ptr);
    Object obj = e.getDataType().toObject(ptr);
    assertTrue(obj instanceof BigDecimal);
    BigDecimal value = (BigDecimal) obj;
    assertTrue(value.equals(BigDecimal.valueOf(1)));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

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