@@ -108,6 +108,42 @@ public void testCompactBlock()
108108 new ByteArrayBlock (6 , Optional .of (rowIsNull ), createExpectedValue (6 ).getBytes ())}));
109109 }
110110
111+ @ Test
112+ public void testCopyWithAppendedNull ()
113+ {
114+ List <Type > fieldTypes = ImmutableList .of (VARCHAR , BIGINT );
115+
116+ // Test without startOffset
117+ List <Object >[] testRows = generateTestRows (fieldTypes , 3 );
118+ RowBlock rowBlock = (RowBlock ) createBlockBuilderWithValues (fieldTypes , testRows ).build ();
119+
120+ RowBlock appendedBlock = rowBlock .copyWithAppendedNull ();
121+ assertThat (appendedBlock .getPositionCount ()).isEqualTo (testRows .length + 1 );
122+ for (int i = 0 ; i < testRows .length ; i ++) {
123+ assertPositionValue (appendedBlock , i , testRows [i ]);
124+ }
125+ assertThat (appendedBlock .isNull (appendedBlock .getPositionCount () - 1 )).isTrue ();
126+
127+ // Test with startOffset
128+ RowBlock offsetBlock = rowBlock .getRegion (1 , 2 );
129+ RowBlock offsetAppendedBlock = offsetBlock .copyWithAppendedNull ();
130+ assertThat (offsetAppendedBlock .getPositionCount ()).isEqualTo (3 );
131+ for (int i = 0 ; i < 2 ; i ++) {
132+ assertPositionValue (offsetAppendedBlock , i , testRows [i + 1 ]);
133+ }
134+ assertThat (offsetAppendedBlock .isNull (2 )).isTrue ();
135+
136+ // Test startOffset + positionCount < fieldBlock[0].length
137+ List <Object >[] largerTestRows = generateTestRows (fieldTypes , 10 );
138+ RowBlock partialBlock = (RowBlock ) createBlockBuilderWithValues (fieldTypes , largerTestRows ).build ().getRegion (2 , 5 );
139+ RowBlock partialAppendedBlock = partialBlock .copyWithAppendedNull ();
140+ assertThat (partialAppendedBlock .getPositionCount ()).isEqualTo (6 );
141+ for (int i = 0 ; i < 5 ; i ++) {
142+ assertPositionValue (partialAppendedBlock , i , largerTestRows [i + 2 ]);
143+ }
144+ assertThat (partialAppendedBlock .isNull (5 )).isTrue ();
145+ }
146+
111147 private void testWith (List <Type > fieldTypes , List <Object >[] expectedValues )
112148 {
113149 Block block = createBlockBuilderWithValues (fieldTypes , expectedValues ).build ();
0 commit comments