use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class GuavaSplitter method split.
@Override
public boolean split(ImmutableBytesWritable srcPtr) {
String sourceStr = (String) PVarchar.INSTANCE.toObject(srcPtr);
if (sourceStr == null) {
// sourceStr evaluated to null
srcPtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
} else {
List<String> splitStrings = Lists.newArrayList(splitter.split(sourceStr));
PhoenixArray splitArray = new PhoenixArray(PVarchar.INSTANCE, splitStrings.toArray());
srcPtr.set(PVarcharArray.INSTANCE.toBytes(splitArray));
}
return true;
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testForVarCharArrayWithOneElementIndex.
@Test
public void testForVarCharArrayWithOneElementIndex() {
String[] strArr = new String[1];
strArr[0] = "abx";
PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
PArrayDataTypeDecoder.positionAtArrayElement(ptr, 0, 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("abx", Bytes.toString(res));
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testForVarCharArrayForOddNumberWithIndex3.
@Test
public void testForVarCharArrayForOddNumberWithIndex3() {
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, 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 testForVarCharArrayForOddNumberWithIndex.
@Test
public void testForVarCharArrayForOddNumberWithIndex() {
String[] strArr = new String[5];
strArr[0] = "abx";
strArr[1] = "ereref";
strArr[2] = "random";
strArr[3] = "random12";
strArr[4] = "ran";
PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
PArrayDataTypeDecoder.positionAtArrayElement(ptr, 3, 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("random12", Bytes.toString(res));
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testForVarCharArrayForOddNumberWithIndex6.
@Test
public void testForVarCharArrayForOddNumberWithIndex6() {
String[] strArr = new String[6];
strArr[0] = "abx";
strArr[1] = "ereref";
strArr[2] = "random";
strArr[3] = null;
strArr[4] = "random12";
strArr[5] = "random17";
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("random12", Bytes.toString(res));
}
Aggregations