|
47 | 47 | import org.apache.arrow.vector.complex.FixedSizeListVector; |
48 | 48 | import org.apache.arrow.vector.complex.LargeListVector; |
49 | 49 | import org.apache.arrow.vector.complex.ListVector; |
| 50 | +import org.apache.arrow.vector.complex.RunEndEncodedVector; |
50 | 51 | import org.apache.arrow.vector.complex.StructVector; |
51 | 52 | import org.apache.arrow.vector.complex.UnionVector; |
52 | 53 | import org.apache.arrow.vector.holders.NullableBigIntHolder; |
@@ -1025,6 +1026,72 @@ public void testAppendDenseUnionVectorMismatch() { |
1025 | 1026 | } |
1026 | 1027 | } |
1027 | 1028 |
|
| 1029 | + @Test |
| 1030 | + public void testAppendRunEndEncodedVector() { |
| 1031 | + final FieldType reeFieldType = FieldType.notNullable(ArrowType.RunEndEncoded.INSTANCE); |
| 1032 | + final Field runEndsField = |
| 1033 | + new Field("runEnds", FieldType.notNullable(Types.MinorType.INT.getType()), null); |
| 1034 | + final Field valuesField = Field.nullable("values", Types.MinorType.INT.getType()); |
| 1035 | + final List<Field> children = Arrays.asList(runEndsField, valuesField); |
| 1036 | + |
| 1037 | + final Field targetField = new Field("target", reeFieldType, children); |
| 1038 | + final Field deltaField = new Field("delta", reeFieldType, children); |
| 1039 | + try (RunEndEncodedVector target = new RunEndEncodedVector(targetField, allocator, null); |
| 1040 | + RunEndEncodedVector delta = new RunEndEncodedVector(deltaField, allocator, null)) { |
| 1041 | + |
| 1042 | + // populate target |
| 1043 | + target.allocateNew(); |
| 1044 | + // data: [1, 1, 2, null, 3, 3, 3] (7 values) |
| 1045 | + // values: [1, 2, null, 3] |
| 1046 | + // runEnds: [2, 3, 4, 7] |
| 1047 | + ValueVectorDataPopulator.setVector((IntVector) target.getValuesVector(), 1, 2, null, 3); |
| 1048 | + ValueVectorDataPopulator.setVector((IntVector) target.getRunEndsVector(), 2, 3, 4, 7); |
| 1049 | + target.setValueCount(7); |
| 1050 | + |
| 1051 | + // populate delta |
| 1052 | + delta.allocateNew(); |
| 1053 | + // data: [3, 4, 4, 5, null, null] (6 values) |
| 1054 | + // values: [3, 4, 5, null] |
| 1055 | + // runEnds: [1, 3, 4, 6] |
| 1056 | + ValueVectorDataPopulator.setVector((IntVector) delta.getValuesVector(), 3, 4, 5, null); |
| 1057 | + ValueVectorDataPopulator.setVector((IntVector) delta.getRunEndsVector(), 1, 3, 4, 6); |
| 1058 | + delta.setValueCount(6); |
| 1059 | + |
| 1060 | + VectorAppender appender = new VectorAppender(target); |
| 1061 | + delta.accept(appender, null); |
| 1062 | + |
| 1063 | + assertEquals(13, target.getValueCount()); |
| 1064 | + |
| 1065 | + final Field expectedField = new Field("expected", reeFieldType, children); |
| 1066 | + try (RunEndEncodedVector expected = new RunEndEncodedVector(expectedField, allocator, null)) { |
| 1067 | + expected.allocateNew(); |
| 1068 | + // expected data: [1, 1, 2, null, 3, 3, 3, 3, 4, 4, 5, null, null] (13 values) |
| 1069 | + // expected values: [1, 2, null, 3, 3, 4, 5, null] |
| 1070 | + // expected runEnds: [2, 3, 4, 7, 8, 10, 11, 13] |
| 1071 | + ValueVectorDataPopulator.setVector( |
| 1072 | + (IntVector) expected.getValuesVector(), 1, 2, null, 3, 3, 4, 5, null); |
| 1073 | + ValueVectorDataPopulator.setVector( |
| 1074 | + (IntVector) expected.getRunEndsVector(), 2, 3, 4, 7, 8, 10, 11, 13); |
| 1075 | + expected.setValueCount(13); |
| 1076 | + |
| 1077 | + assertVectorsEqual(expected, target); |
| 1078 | + } |
| 1079 | + |
| 1080 | + // Check that delta is unchanged. |
| 1081 | + final Field expectedDeltaField = new Field("expectedDelta", reeFieldType, children); |
| 1082 | + try (RunEndEncodedVector expectedDelta = |
| 1083 | + new RunEndEncodedVector(expectedDeltaField, allocator, null)) { |
| 1084 | + expectedDelta.allocateNew(); |
| 1085 | + ValueVectorDataPopulator.setVector( |
| 1086 | + (IntVector) expectedDelta.getValuesVector(), 3, 4, 5, null); |
| 1087 | + ValueVectorDataPopulator.setVector( |
| 1088 | + (IntVector) expectedDelta.getRunEndsVector(), 1, 3, 4, 6); |
| 1089 | + expectedDelta.setValueCount(6); |
| 1090 | + assertVectorsEqual(expectedDelta, delta); |
| 1091 | + } |
| 1092 | + } |
| 1093 | + } |
| 1094 | + |
1028 | 1095 | @Test |
1029 | 1096 | public void testAppendVectorNegative() { |
1030 | 1097 | final int vectorLength = 10; |
|
0 commit comments