37
37
import java .util .ArrayList ;
38
38
import java .util .BitSet ;
39
39
import java .util .Random ;
40
+ import java .util .stream .IntStream ;
40
41
41
42
public class BlockBenchmark {
42
43
/**
@@ -112,15 +113,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
112
113
blocks [blockIndex ] = blockFactory .newBooleanArrayBlock (
113
114
values ,
114
115
totalPositions ,
115
- null ,
116
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
116
117
null ,
117
118
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
118
119
);
119
120
}
120
121
case "array-multivalue-null" -> {
121
122
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
122
123
int positionCount = firstValueIndexes .length - 1 ;
123
- BitSet nulls = randomNulls ( positionCount );
124
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
124
125
125
126
blocks [blockIndex ] = blockFactory .newBooleanArrayBlock (
126
127
values ,
@@ -141,7 +142,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
141
142
blocks [blockIndex ] = new BooleanBigArrayBlock (
142
143
valuesBigArray ,
143
144
totalPositions ,
144
- null ,
145
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
145
146
null ,
146
147
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
147
148
blockFactory
@@ -150,7 +151,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
150
151
case "big-array-multivalue-null" -> {
151
152
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
152
153
int positionCount = firstValueIndexes .length - 1 ;
153
- BitSet nulls = randomNulls ( positionCount );
154
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
154
155
BitArray valuesBigArray = new BitArray (totalPositions , BigArrays .NON_RECYCLING_INSTANCE );
155
156
for (int i = 0 ; i < values .length ; i ++) {
156
157
if (values [i ]) {
@@ -211,15 +212,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
211
212
blocks [blockIndex ] = blockFactory .newBytesRefArrayBlock (
212
213
values ,
213
214
totalPositions ,
214
- null ,
215
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
215
216
null ,
216
217
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
217
218
);
218
219
}
219
220
case "array-multivalue-null" -> {
220
221
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
221
222
int positionCount = firstValueIndexes .length - 1 ;
222
- BitSet nulls = randomNulls ( positionCount );
223
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
223
224
224
225
blocks [blockIndex ] = blockFactory .newBytesRefArrayBlock (
225
226
values ,
@@ -257,15 +258,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
257
258
blocks [blockIndex ] = blockFactory .newDoubleArrayBlock (
258
259
values ,
259
260
totalPositions ,
260
- null ,
261
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
261
262
null ,
262
263
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
263
264
);
264
265
}
265
266
case "array-multivalue-null" -> {
266
267
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
267
268
int positionCount = firstValueIndexes .length - 1 ;
268
- BitSet nulls = randomNulls ( positionCount );
269
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
269
270
270
271
blocks [blockIndex ] = blockFactory .newDoubleArrayBlock (
271
272
values ,
@@ -284,7 +285,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
284
285
blocks [blockIndex ] = new DoubleBigArrayBlock (
285
286
valuesBigArray ,
286
287
totalPositions ,
287
- null ,
288
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
288
289
null ,
289
290
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
290
291
blockFactory
@@ -293,7 +294,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
293
294
case "big-array-multivalue-null" -> {
294
295
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
295
296
int positionCount = firstValueIndexes .length - 1 ;
296
- BitSet nulls = randomNulls ( positionCount );
297
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
297
298
DoubleArray valuesBigArray = blockFactory .bigArrays ().newDoubleArray (totalPositions , false );
298
299
for (int i = 0 ; i < values .length ; i ++) {
299
300
valuesBigArray .set (i , values [i ]);
@@ -344,15 +345,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
344
345
blocks [blockIndex ] = blockFactory .newIntArrayBlock (
345
346
values ,
346
347
totalPositions ,
347
- null ,
348
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
348
349
null ,
349
350
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
350
351
);
351
352
}
352
353
case "array-multivalue-null" -> {
353
354
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
354
355
int positionCount = firstValueIndexes .length - 1 ;
355
- BitSet nulls = randomNulls ( positionCount );
356
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
356
357
357
358
blocks [blockIndex ] = blockFactory .newIntArrayBlock (
358
359
values ,
@@ -371,7 +372,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
371
372
blocks [blockIndex ] = new IntBigArrayBlock (
372
373
valuesBigArray ,
373
374
totalPositions ,
374
- null ,
375
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
375
376
null ,
376
377
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
377
378
blockFactory
@@ -380,7 +381,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
380
381
case "big-array-multivalue-null" -> {
381
382
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
382
383
int positionCount = firstValueIndexes .length - 1 ;
383
- BitSet nulls = randomNulls ( positionCount );
384
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
384
385
IntArray valuesBigArray = blockFactory .bigArrays ().newIntArray (totalPositions , false );
385
386
for (int i = 0 ; i < values .length ; i ++) {
386
387
valuesBigArray .set (i , values [i ]);
@@ -431,15 +432,15 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
431
432
blocks [blockIndex ] = blockFactory .newLongArrayBlock (
432
433
values ,
433
434
totalPositions ,
434
- null ,
435
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
435
436
null ,
436
437
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING
437
438
);
438
439
}
439
440
case "array-multivalue-null" -> {
440
441
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
441
442
int positionCount = firstValueIndexes .length - 1 ;
442
- BitSet nulls = randomNulls ( positionCount );
443
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
443
444
444
445
blocks [blockIndex ] = blockFactory .newLongArrayBlock (
445
446
values ,
@@ -458,7 +459,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
458
459
blocks [blockIndex ] = new LongBigArrayBlock (
459
460
valuesBigArray ,
460
461
totalPositions ,
461
- null ,
462
+ IntStream . rangeClosed ( 0 , totalPositions ). toArray () ,
462
463
null ,
463
464
Block .MvOrdering .DEDUPLICATED_AND_SORTED_ASCENDING ,
464
465
blockFactory
@@ -467,7 +468,7 @@ static Block[] buildBlocks(String dataType, String blockKind, int totalPositions
467
468
case "big-array-multivalue-null" -> {
468
469
int [] firstValueIndexes = randomFirstValueIndexes (totalPositions );
469
470
int positionCount = firstValueIndexes .length - 1 ;
470
- BitSet nulls = randomNulls ( positionCount );
471
+ BitSet nulls = nullsFromFirstValues ( firstValueIndexes );
471
472
LongArray valuesBigArray = blockFactory .bigArrays ().newLongArray (totalPositions , false );
472
473
for (int i = 0 ; i < values .length ; i ++) {
473
474
valuesBigArray .set (i , values [i ]);
@@ -526,10 +527,10 @@ private static int[] randomFirstValueIndexes(int totalPositions) {
526
527
return firstValueIndexes .stream ().mapToInt (x -> x ).toArray ();
527
528
}
528
529
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 ) {
533
534
nulls .set (i );
534
535
}
535
536
}
0 commit comments