Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/incubator-phoenix/pull/8#discussion_r10095240
--- Diff:
phoenix-core/src/test/java/org/apache/phoenix/schema/PDataTypeForArraysTest.java
---
@@ -183,6 +363,236 @@ public void
testForVarCharArrayForOddNumberWithIndex() {
assertEquals("random12", Bytes.toString(res));
}
+ @Test
+ public void testPositionSearchWithVarLengthArrayWithNullValue1() {
+ String[] strArr = new String[5];
+ strArr[0] = "abx";
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = "ran";
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 2, PDataType.VARCHAR);
+ 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));
+ }
+
+ @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(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 2, PDataType.VARCHAR);
+ 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));
+ }
+ @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(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR);
+ 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));
+ }
+
+ @Test
+ public void testForVarCharArrayForOddNumberWithIndex4() {
+ String[] strArr = new String[5];
+ strArr[0] = "abx";
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = null;
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR);
+ 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));
+ }
+
+ @Test
+ public void testForVarCharArrayForOddNumberWithIndex5() {
+ String[] strArr = new String[5];
+ strArr[0] = "abx";
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = "random12";
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR);
+ 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));
+ }
+
+ @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(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR);
+ 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));
+ }
+ @Test
+ public void testPositionSearchWithVarLengthArrayWithNullValue5() {
+ String[] strArr = new String[5];
+ strArr[0] = "abx";
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = "ran";
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR);
+ 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));
+ }
+
+ @Test
+ public void
testPositionSearchWithVarLengthArrayWithNullValueAtTheStart1() {
+ String[] strArr = new String[5];
+ strArr[0] = null;
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = "ran";
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 3, PDataType.VARCHAR);
+ 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));
+ }
+
+ @Test
+ public void
testPositionSearchWithVarLengthArrayWithNullValueAtTheStart2() {
+ String[] strArr = new String[5];
+ strArr[0] = null;
+ strArr[1] = "ereref";
+ strArr[2] = "random";
+ strArr[3] = null;
+ strArr[4] = "ran";
+ PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 0, PDataType.VARCHAR);
+ 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));
+ }
+
+ @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(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR);
+ 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));
+ }
+
+ @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(
+ PDataType.VARCHAR, strArr);
+ byte[] bytes = PDataType.VARCHAR_ARRAY.toBytes(arr);
+ ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
+ PArrayDataType.positionAtArrayElement(ptr, 4, PDataType.VARCHAR);
+ 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));
+ }
+
--- End diff --
These tests are awesome! How about a few more to test byte array comparison
of two ARRAYs of the same type?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---