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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations