Search in sources :

Example 86 with PhoenixArray

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

the class PDataTypeForArraysTest method testForDateArray.

@Test
public void testForDateArray() {
    Date[] dateArr = new Date[2];
    dateArr[0] = new Date(System.currentTimeMillis());
    dateArr[1] = new Date(System.currentTimeMillis() + System.currentTimeMillis());
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDate.INSTANCE, dateArr);
    PDateArray.INSTANCE.toObject(arr, PDateArray.INSTANCE);
    byte[] bytes = PDateArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PDateArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PDate(org.apache.phoenix.schema.types.PDate) PUnsignedDate(org.apache.phoenix.schema.types.PUnsignedDate) Date(java.sql.Date) Test(org.junit.Test)

Example 87 with PhoenixArray

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

the class PDataTypeForArraysTest method testVarCharArrayWithNullValues1.

@Test
public void testVarCharArrayWithNullValues1() {
    String[] strArr = new String[6];
    strArr[0] = "abc";
    strArr[1] = null;
    strArr[2] = "bcd";
    strArr[3] = null;
    strArr[4] = null;
    strArr[5] = "b";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 88 with PhoenixArray

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

the class PDataTypeForArraysTest method testVarCharArrayWithNullValues3.

@Test
public void testVarCharArrayWithNullValues3() {
    String[] strArr = new String[6];
    strArr[0] = "abc";
    strArr[1] = null;
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = null;
    strArr[5] = null;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 89 with PhoenixArray

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

the class PDataTypeForArraysTest method testPositionSearchWithVarLengthArrayWithNullValueAtTheStart3.

@Test
public void testPositionSearchWithVarLengthArrayWithNullValueAtTheStart3() {
    String[] strArr = new String[5];
    strArr[0] = null;
    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, 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("ran", 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 90 with PhoenixArray

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

the class PDataTypeForArraysTest method testForVarCharArrayForEvenNumberWithIndex.

@Test
public void testForVarCharArrayForEvenNumberWithIndex() {
    String[] strArr = new String[5];
    strArr[0] = "abx";
    strArr[1] = "ereref";
    strArr[2] = "random";
    strArr[3] = "random12";
    strArr[4] = "ranzzz";
    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("ranzzz", 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

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