Search in sources :

Example 91 with PhoenixArray

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

the class PDataTypeForArraysTest method testPositionSearchWithVarLengthArrayWithNullValue2.

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

Example 92 with PhoenixArray

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

the class PDataTypeForArraysTest method testForUnSignedFloatArray.

@Test
public void testForUnSignedFloatArray() {
    Float[] floatArr = new Float[2];
    floatArr[0] = 1.9993f;
    floatArr[1] = 2.786f;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PUnsignedFloat.INSTANCE, floatArr);
    PUnsignedFloatArray.INSTANCE.toObject(arr, PUnsignedFloatArray.INSTANCE);
    byte[] bytes = PUnsignedFloatArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PUnsignedFloatArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PFloat(org.apache.phoenix.schema.types.PFloat) PUnsignedFloat(org.apache.phoenix.schema.types.PUnsignedFloat) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 93 with PhoenixArray

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

the class PDataTypeForArraysTest method testVarCharArrayComparisonWithGreaterThan255NullsinMiddle.

@Test
public void testVarCharArrayComparisonWithGreaterThan255NullsinMiddle() {
    String[] strArr = new String[240];
    strArr[0] = "abc";
    strArr[1] = "bcd";
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = "bcd";
    strArr[strArr.length - 1] = "abc";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
    strArr = new String[16];
    strArr[0] = "abc";
    strArr[1] = "bcd";
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = "bcd";
    strArr[strArr.length - 1] = "abc";
    arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
    assertTrue(Bytes.compareTo(bytes1, bytes2) < 0);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 94 with PhoenixArray

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

the class PDataTypeForArraysTest method testGetArrayLengthForFixedLengthArray.

@Test
public void testGetArrayLengthForFixedLengthArray() {
    Long[] longArr = new Long[4];
    longArr[0] = 1l;
    longArr[1] = 2l;
    longArr[2] = 4l;
    longArr[3] = 5l;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PLong.INSTANCE, longArr);
    PLongArray.INSTANCE.toObject(arr, PLongArray.INSTANCE);
    byte[] bytes = PLongArray.INSTANCE.toBytes(arr);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    int length = PArrayDataType.getArrayLength(ptr, PLong.INSTANCE, null);
    assertEquals(4, length);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PLong(org.apache.phoenix.schema.types.PLong) PUnsignedLong(org.apache.phoenix.schema.types.PUnsignedLong) 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 95 with PhoenixArray

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

the class PDataTypeForArraysTest method testForUnsignedTimeArray.

@Test
public void testForUnsignedTimeArray() {
    Time[] timeArr = new Time[2];
    timeArr[0] = new Time(System.currentTimeMillis());
    timeArr[1] = new Time(900000l);
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PUnsignedTime.INSTANCE, timeArr);
    PUnsignedTimeArray.INSTANCE.toObject(arr, PUnsignedTimeArray.INSTANCE);
    byte[] bytes = PUnsignedTimeArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PUnsignedTimeArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Time(java.sql.Time) PUnsignedTime(org.apache.phoenix.schema.types.PUnsignedTime) PTime(org.apache.phoenix.schema.types.PTime) 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