Search in sources :

Example 81 with ImmutableBytesWritable

use of org.apache.hadoop.hbase.io.ImmutableBytesWritable 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)

Example 82 with ImmutableBytesWritable

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

the class GetSetByteBitFunctionTest method testSetByteExpression.

private void testSetByteExpression(Expression data, Expression offset, Expression newValue, byte[] expected) throws SQLException {
    List<Expression> expressions = Lists.newArrayList(data, offset, newValue);
    Expression setByteFunction = new SetByteFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    setByteFunction.evaluate(null, ptr);
    byte[] result = (byte[]) setByteFunction.getDataType().toObject(ptr, setByteFunction.getSortOrder());
    assertArrayEquals(expected, result);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) SetByteFunction(org.apache.phoenix.expression.function.SetByteFunction)

Example 83 with ImmutableBytesWritable

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

the class GetSetByteBitFunctionTest method testSetBitExpression.

private void testSetBitExpression(Expression data, Expression offset, Expression newValue, byte[] expected) throws SQLException {
    List<Expression> expressions = Lists.newArrayList(data, offset, newValue);
    Expression setBitFunction = new SetBitFunction(expressions);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    setBitFunction.evaluate(null, ptr);
    byte[] result = (byte[]) setBitFunction.getDataType().toObject(ptr, setBitFunction.getSortOrder());
    assertArrayEquals(expected, result);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) SetBitFunction(org.apache.phoenix.expression.function.SetBitFunction)

Example 84 with ImmutableBytesWritable

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

the class TestTableRowkeyPair method testsRowsKeys.

private void testsRowsKeys(String aTable, String akey, String bTable, String bkey, int expectedSignum) throws IOException {
    final ImmutableBytesWritable arowkey = new ImmutableBytesWritable(Bytes.toBytes(akey));
    TableRowkeyPair pair1 = new TableRowkeyPair(aTable, arowkey);
    ImmutableBytesWritable browkey = new ImmutableBytesWritable(Bytes.toBytes(bkey));
    TableRowkeyPair pair2 = new TableRowkeyPair(bTable, browkey);
    TableRowkeyPair.Comparator comparator = new TableRowkeyPair.Comparator();
    try (ByteArrayOutputStream baosA = new ByteArrayOutputStream();
        ByteArrayOutputStream baosB = new ByteArrayOutputStream()) {
        pair1.write(new DataOutputStream(baosA));
        pair2.write(new DataOutputStream(baosB));
        Assert.assertEquals(expectedSignum, signum(pair1.compareTo(pair2)));
        Assert.assertEquals(expectedSignum, signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())));
        Assert.assertEquals(expectedSignum, -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())));
    }
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 85 with ImmutableBytesWritable

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

the class PDataTypeForArraysTest method testPositionSearchWithVarLengthArrayWithNullValue1.

@Test
public void testPositionSearchWithVarLengthArrayWithNullValue1() {
    String[] strArr = new String[5];
    strArr[0] = "abx";
    strArr[1] = "ereref";
    strArr[2] = "random";
    strArr[3] = null;
    strArr[4] = "ran";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    PArrayDataTypeDecoder.positionAtArrayElement(ptr, 2, PVarchar.INSTANCE, PVarchar.INSTANCE.getByteSize());
    int offset = ptr.getOffset();
    int length = ptr.getLength();
    byte[] bs = ptr.get();
    byte[] res = new byte[length];
    System.arraycopy(bs, offset, res, 0, length);
    assertEquals("random", Bytes.toString(res));
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PUnsignedSmallint(org.apache.phoenix.schema.types.PUnsignedSmallint) PUnsignedTinyint(org.apache.phoenix.schema.types.PUnsignedTinyint) PTinyint(org.apache.phoenix.schema.types.PTinyint) PSmallint(org.apache.phoenix.schema.types.PSmallint) 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