Search in sources :

Example 96 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class PDataTypeForArraysTest method testForBooleanArray.

@Test
public void testForBooleanArray() {
    Boolean[] boolArr = new Boolean[2];
    boolArr[0] = true;
    boolArr[1] = false;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PBoolean.INSTANCE, boolArr);
    PBooleanArray.INSTANCE.toObject(arr, PBooleanArray.INSTANCE);
    byte[] bytes = PBooleanArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PBooleanArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PBoolean(org.apache.phoenix.schema.types.PBoolean) Test(org.junit.Test)

Example 97 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class PDataTypeForArraysTest method testForTimeStampArray.

@Test
public void testForTimeStampArray() {
    Timestamp[] timeStampArr = new Timestamp[2];
    timeStampArr[0] = new Timestamp(System.currentTimeMillis());
    timeStampArr[1] = new Timestamp(900000l);
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PTimestamp.INSTANCE, timeStampArr);
    PTimestampArray.INSTANCE.toObject(arr, PTimestampArray.INSTANCE);
    byte[] bytes = PTimestampArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PTimestampArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PUnsignedTimestamp(org.apache.phoenix.schema.types.PUnsignedTimestamp) Timestamp(java.sql.Timestamp) PTimestamp(org.apache.phoenix.schema.types.PTimestamp) Test(org.junit.Test)

Example 98 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class PDataTypeForArraysTest method testPositionSearchWithVarLengthArrayWithAllNulls.

@Test
public void testPositionSearchWithVarLengthArrayWithAllNulls() {
    String[] strArr = new String[5];
    strArr[0] = null;
    strArr[1] = null;
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = null;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    PArrayDataTypeDecoder.positionAtArrayElement(ptr, 4, 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("", 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)

Example 99 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class PDataTypeForArraysTest method testForVarCharArrayForWithTwoelementsElementArrayWithIndex.

@Test
public void testForVarCharArrayForWithTwoelementsElementArrayWithIndex() {
    String[] strArr = new String[2];
    strArr[0] = "abx";
    strArr[1] = "ereref";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    PArrayDataTypeDecoder.positionAtArrayElement(ptr, 1, 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("ereref", 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)

Example 100 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class PDataTypeForArraysTest method testIsRowKeyOrderOptimized3.

@Test
public void testIsRowKeyOrderOptimized3() {
    Object[] objects = new Object[] { "a", "b", "c" };
    PhoenixArray arr = new PhoenixArray(PVarchar.INSTANCE, objects);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr, SortOrder.DESC);
    for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] == QueryConstants.DESC_SEPARATOR_BYTE) {
            bytes[i] = QueryConstants.SEPARATOR_BYTE;
        }
    }
    assertFalse(PArrayDataType.isRowKeyOrderOptimized(PVarcharArray.INSTANCE, SortOrder.DESC, bytes, 0, bytes.length));
}
Also used : 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

PhoenixArray (org.apache.phoenix.schema.types.PhoenixArray)107 Test (org.junit.Test)97 Connection (java.sql.Connection)25 ResultSet (java.sql.ResultSet)25 PSmallint (org.apache.phoenix.schema.types.PSmallint)25 PTinyint (org.apache.phoenix.schema.types.PTinyint)25 PUnsignedSmallint (org.apache.phoenix.schema.types.PUnsignedSmallint)25 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)25 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)23 PreparedStatement (java.sql.PreparedStatement)7 Properties (java.util.Properties)7 BaseTest (org.apache.phoenix.query.BaseTest)7 Array (java.sql.Array)6 PDouble (org.apache.phoenix.schema.types.PDouble)5 PLong (org.apache.phoenix.schema.types.PLong)4 PUnsignedLong (org.apache.phoenix.schema.types.PUnsignedLong)4 Timestamp (java.sql.Timestamp)3 PTimestamp (org.apache.phoenix.schema.types.PTimestamp)3 PUnsignedDouble (org.apache.phoenix.schema.types.PUnsignedDouble)3 PUnsignedTimestamp (org.apache.phoenix.schema.types.PUnsignedTimestamp)3