3737import java .util .ArrayList ;
3838import java .util .BitSet ;
3939import java .util .Random ;
40+ import java .util .stream .IntStream ;
4041
4142public class BlockBenchmark {
4243 /**
@@ -112,15 +113,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
112113 blocks [blockIndex ] = blockFactory .newBooleanArrayBlock (
113114 values ,
114115 totalPositions ,
115- null ,
116+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
116117 null ,
117118 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
118119 );
119120 }
120121 case "array-multivalue-null" -> {
121122 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
122123 int positionCount = firstValueIndexes .length - 1 ;
123- BitSet nulls = randomNulls ( positionCount );
124+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
124125
125126 blocks [blockIndex ] = blockFactory .newBooleanArrayBlock (
126127 values ,
@@ -141,7 +142,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
141142 blocks [blockIndex ] = new BooleanBigArrayBlock (
142143 valuesBigArray ,
143144 totalPositions ,
144- null ,
145+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
145146 null ,
146147 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
147148 blockFactory
@@ -150,7 +151,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
150151 case "big-array-multivalue-null" -> {
151152 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
152153 int positionCount = firstValueIndexes .length - 1 ;
153- BitSet nulls = randomNulls ( positionCount );
154+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
154155 BitArray valuesBigArray = new BitArray (totalPositions , BigArrays .NON_RECYCLING_INSTANCE );
155156 for (int i = 0 ; i < values .length ; i ++) {
156157 if (values [i ]) {
@@ -211,15 +212,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
211212 blocks [blockIndex ] = blockFactory .newBytesRefArrayBlock (
212213 values ,
213214 totalPositions ,
214- null ,
215+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
215216 null ,
216217 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
217218 );
218219 }
219220 case "array-multivalue-null" -> {
220221 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
221222 int positionCount = firstValueIndexes .length - 1 ;
222- BitSet nulls = randomNulls ( positionCount );
223+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
223224
224225 blocks [blockIndex ] = blockFactory .newBytesRefArrayBlock (
225226 values ,
@@ -257,15 +258,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
257258 blocks [blockIndex ] = blockFactory .newDoubleArrayBlock (
258259 values ,
259260 totalPositions ,
260- null ,
261+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
261262 null ,
262263 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
263264 );
264265 }
265266 case "array-multivalue-null" -> {
266267 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
267268 int positionCount = firstValueIndexes .length - 1 ;
268- BitSet nulls = randomNulls ( positionCount );
269+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
269270
270271 blocks [blockIndex ] = blockFactory .newDoubleArrayBlock (
271272 values ,
@@ -284,7 +285,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
284285 blocks [blockIndex ] = new DoubleBigArrayBlock (
285286 valuesBigArray ,
286287 totalPositions ,
287- null ,
288+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
288289 null ,
289290 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
290291 blockFactory
@@ -293,7 +294,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
293294 case "big-array-multivalue-null" -> {
294295 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
295296 int positionCount = firstValueIndexes .length - 1 ;
296- BitSet nulls = randomNulls ( positionCount );
297+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
297298 DoubleArray valuesBigArray = blockFactory .bigArrays ().newDoubleArray (totalPositions , false );
298299 for (int i = 0 ; i < values .length ; i ++) {
299300 valuesBigArray .set (i , values [i ]);
@@ -344,15 +345,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
344345 blocks [blockIndex ] = blockFactory .newIntArrayBlock (
345346 values ,
346347 totalPositions ,
347- null ,
348+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
348349 null ,
349350 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
350351 );
351352 }
352353 case "array-multivalue-null" -> {
353354 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
354355 int positionCount = firstValueIndexes .length - 1 ;
355- BitSet nulls = randomNulls ( positionCount );
356+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
356357
357358 blocks [blockIndex ] = blockFactory .newIntArrayBlock (
358359 values ,
@@ -371,7 +372,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
371372 blocks [blockIndex ] = new IntBigArrayBlock (
372373 valuesBigArray ,
373374 totalPositions ,
374- null ,
375+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
375376 null ,
376377 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
377378 blockFactory
@@ -380,7 +381,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
380381 case "big-array-multivalue-null" -> {
381382 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
382383 int positionCount = firstValueIndexes .length - 1 ;
383- BitSet nulls = randomNulls ( positionCount );
384+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
384385 IntArray valuesBigArray = blockFactory .bigArrays ().newIntArray (totalPositions , false );
385386 for (int i = 0 ; i < values .length ; i ++) {
386387 valuesBigArray .set (i , values [i ]);
@@ -431,15 +432,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
431432 blocks [blockIndex ] = blockFactory .newLongArrayBlock (
432433 values ,
433434 totalPositions ,
434- null ,
435+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
435436 null ,
436437 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
437438 );
438439 }
439440 case "array-multivalue-null" -> {
440441 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
441442 int positionCount = firstValueIndexes .length - 1 ;
442- BitSet nulls = randomNulls ( positionCount );
443+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
443444
444445 blocks [blockIndex ] = blockFactory .newLongArrayBlock (
445446 values ,
@@ -458,7 +459,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
458459 blocks [blockIndex ] = new LongBigArrayBlock (
459460 valuesBigArray ,
460461 totalPositions ,
461- null ,
462+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
462463 null ,
463464 Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
464465 blockFactory
@@ -467,7 +468,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
467468 case "big-array-multivalue-null" -> {
468469 int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
469470 int positionCount = firstValueIndexes .length - 1 ;
470- BitSet nulls = randomNulls ( positionCount );
471+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
471472 LongArray valuesBigArray = blockFactory .bigArrays ().newLongArray (totalPositions , false );
472473 for (int i = 0 ; i < values .length ; i ++) {
473474 valuesBigArray .set (i , values [i ]);
@@ -526,10 +527,10 @@ private static int[] randomFirstValueIndexes(int totalPositions) {
526527 return firstValueIndexes .stream ().mapToInt (x -> x ).toArray ();
527528 }
528529
529- private static BitSet randomNulls (int positionCount ) {
530- BitSet nulls = new BitSet (positionCount );
531- for (int i = 0 ; i < positionCount ; i ++) {
532- if (random .nextDouble () < NULL_PERCENTAGE ) {
530+ private static BitSet nullsFromFirstValues (int [] firstValueIndexes ) {
531+ BitSet nulls = new BitSet (firstValueIndexes . length - 1 );
532+ for (int i = 0 ; i < firstValueIndexes . length - 1 ; i ++) {
533+ if (firstValueIndexes [ i + 1 ] - firstValueIndexes [ i ] == 1 && random .nextDouble () < NULL_PERCENTAGE ) {
533534 nulls .set (i );
534535 }
535536 }
0 commit comments