use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testVarCharArrayWithNullValues7.
@Test
public void testVarCharArrayWithNullValues7() {
String[] strArr = new String[6];
strArr[0] = null;
strArr[1] = "abc";
strArr[2] = null;
strArr[3] = "bcd";
strArr[4] = null;
strArr[5] = "cde";
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);
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testArrayConversion.
@Test
public void testArrayConversion() {
final String[] data = new String[] { "asdf", "qwerty" };
PhoenixArray phxArray = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, data);
assertTrue("Converting a PhoenixArray to a PhoenixArray should return the same object", phxArray == PVarcharArray.INSTANCE.toPhoenixArray(phxArray, PVarchar.INSTANCE));
// Create a skeleton of an Array which isn't a PhoenixArray. Make sure we can convert that.
Array customArray = new Array() {
@Override
public String getBaseTypeName() throws SQLException {
return "VARCHAR";
}
@Override
public int getBaseType() throws SQLException {
return Types.VARCHAR;
}
@Override
public Object getArray() throws SQLException {
return data;
}
@Override
public Object getArray(Map<String, Class<?>> map) throws SQLException {
return null;
}
@Override
public Object getArray(long index, int count) throws SQLException {
return null;
}
@Override
public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
return null;
}
@Override
public ResultSet getResultSet() throws SQLException {
return null;
}
@Override
public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
return null;
}
@Override
public ResultSet getResultSet(long index, int count) throws SQLException {
return null;
}
@Override
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
return null;
}
@Override
public void free() throws SQLException {
}
};
PhoenixArray copy = PVarcharArray.INSTANCE.toPhoenixArray(customArray, PVarchar.INSTANCE);
assertEquals(phxArray, copy);
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testGetArrayLengthForVariableLengthArray.
@Test
public void testGetArrayLengthForVariableLengthArray() {
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);
int result = PArrayDataType.getArrayLength(ptr, PVarchar.INSTANCE, null);
assertEquals(5, result);
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class PDataTypeForArraysTest method testForDoubleArray.
@Test
public void testForDoubleArray() {
Double[] doubleArr = new Double[2];
doubleArr[0] = 1.06;
doubleArr[1] = 2.89;
PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDouble.INSTANCE, doubleArr);
PDoubleArray.INSTANCE.toObject(arr, PDoubleArray.INSTANCE);
byte[] bytes = PDoubleArray.INSTANCE.toBytes(arr);
PhoenixArray resultArr = (PhoenixArray) PDoubleArray.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 testVarCharArrayComparisonWithGreaterThan255NullsinMiddle1.
@Test
public void testVarCharArrayComparisonWithGreaterThan255NullsinMiddle1() {
String[] strArr = new String[500];
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[500];
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);
}
Aggregations