2222import org .apache .datasketches .common .ArrayOfDoublesSerDe ;
2323import org .apache .datasketches .common .ArrayOfLongsSerDe ;
2424import org .apache .datasketches .common .ArrayOfStringsSerDe ;
25+ import org .apache .datasketches .common .ResizeFactor ;
2526import org .testng .annotations .Test ;
2627
2728import java .io .IOException ;
@@ -74,7 +75,7 @@ public void generateReservoirLongsSketchSampling() throws IOException {
7475 final ReservoirLongsSketch sk = ReservoirLongsSketch .getInstance (
7576 predeterminedSamples ,
7677 n ,
77- org . apache . datasketches . common . ResizeFactor .X8 ,
78+ ResizeFactor .X8 ,
7879 k
7980 );
8081
@@ -83,6 +84,56 @@ public void generateReservoirLongsSketchSampling() throws IOException {
8384 }
8485 }
8586
87+ @ Test (groups = {GENERATE_JAVA_FILES })
88+ public void generateReservoirLongsUnionEmpty () throws IOException {
89+ final int maxK = 128 ;
90+ final ReservoirLongsUnion union = ReservoirLongsUnion .newInstance (maxK );
91+
92+ Files .newOutputStream (javaPath .resolve ("reservoir_longs_union_empty_maxk" + maxK + "_java.sk" ))
93+ .write (union .toByteArray ());
94+ }
95+
96+ @ Test (groups = {GENERATE_JAVA_FILES })
97+ public void generateReservoirLongsUnionExact () throws IOException {
98+ final int maxK = 128 ;
99+ final int [] nArr = {1 , 10 , 32 , 100 , 128 };
100+
101+ for (final int n : nArr ) {
102+ final ReservoirLongsUnion union = ReservoirLongsUnion .newInstance (maxK );
103+ for (int i = 0 ; i < n ; i ++) {
104+ union .update (i );
105+ }
106+ Files .newOutputStream (javaPath .resolve ("reservoir_longs_union_exact_n" + n + "_maxk" + maxK + "_java.sk" ))
107+ .write (union .toByteArray ());
108+ }
109+ }
110+
111+ @ Test (groups = {GENERATE_JAVA_FILES })
112+ public void generateReservoirLongsUnionSampling () throws IOException {
113+ final int [] maxKArr = {32 , 64 , 128 };
114+ final long n = 1000 ;
115+
116+ for (final int maxK : maxKArr ) {
117+ final long [] predeterminedSamples = new long [maxK ];
118+ for (int i = 0 ; i < maxK ; i ++) {
119+ predeterminedSamples [i ] = i * 2 ;
120+ }
121+
122+ final ReservoirLongsSketch sk = ReservoirLongsSketch .getInstance (
123+ predeterminedSamples ,
124+ n ,
125+ ResizeFactor .X8 ,
126+ maxK
127+ );
128+
129+ final ReservoirLongsUnion union = ReservoirLongsUnion .newInstance (maxK );
130+ union .update (sk );
131+
132+ Files .newOutputStream (javaPath .resolve ("reservoir_longs_union_sampling_n" + n + "_maxk" + maxK + "_java.sk" ))
133+ .write (union .toByteArray ());
134+ }
135+ }
136+
86137 @ Test (groups = {GENERATE_JAVA_FILES })
87138 public void generateReservoirItemsSketchLongEmpty () throws IOException {
88139 final int k = 128 ;
@@ -121,7 +172,7 @@ public void generateReservoirItemsSketchLongSampling() throws IOException {
121172 final ReservoirItemsSketch <Long > sk = ReservoirItemsSketch .newInstance (
122173 predeterminedSamples ,
123174 n ,
124- org . apache . datasketches . common . ResizeFactor .X8 ,
175+ ResizeFactor .X8 ,
125176 k
126177 );
127178
@@ -168,7 +219,7 @@ public void generateReservoirItemsSketchDoubleSampling() throws IOException {
168219 final ReservoirItemsSketch <Double > sk = ReservoirItemsSketch .newInstance (
169220 predeterminedSamples ,
170221 n ,
171- org . apache . datasketches . common . ResizeFactor .X8 ,
222+ ResizeFactor .X8 ,
172223 k
173224 );
174225
@@ -215,12 +266,162 @@ public void generateReservoirItemsSketchStringSampling() throws IOException {
215266 final ReservoirItemsSketch <String > sk = ReservoirItemsSketch .newInstance (
216267 predeterminedSamples ,
217268 n ,
218- org . apache . datasketches . common . ResizeFactor .X8 ,
269+ ResizeFactor .X8 ,
219270 k
220271 );
221272
222273 Files .newOutputStream (javaPath .resolve ("reservoir_items_string_sampling_n" + n + "_k" + k + "_java.sk" ))
223274 .write (sk .toByteArray (new ArrayOfStringsSerDe ()));
224275 }
225276 }
277+
278+ @ Test (groups = {GENERATE_JAVA_FILES })
279+ public void generateReservoirItemsUnionLongEmpty () throws IOException {
280+ final int maxK = 128 ;
281+ final ReservoirItemsUnion <Long > union = ReservoirItemsUnion .newInstance (maxK );
282+
283+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_long_empty_maxk" + maxK + "_java.sk" ))
284+ .write (union .toByteArray (new ArrayOfLongsSerDe ()));
285+ }
286+
287+ @ Test (groups = {GENERATE_JAVA_FILES })
288+ public void generateReservoirItemsUnionLongExact () throws IOException {
289+ final int maxK = 128 ;
290+ final int [] nArr = {1 , 10 , 32 , 100 , 128 };
291+
292+ for (final int n : nArr ) {
293+ final ReservoirItemsUnion <Long > union = ReservoirItemsUnion .newInstance (maxK );
294+ for (int i = 0 ; i < n ; i ++) {
295+ union .update ((long ) i );
296+ }
297+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_long_exact_n" + n + "_maxk" + maxK + "_java.sk" ))
298+ .write (union .toByteArray (new ArrayOfLongsSerDe ()));
299+ }
300+ }
301+
302+ @ Test (groups = {GENERATE_JAVA_FILES })
303+ public void generateReservoirItemsUnionLongSampling () throws IOException {
304+ final int [] maxKArr = {32 , 64 , 128 };
305+ final long n = 1000 ;
306+
307+ for (final int maxK : maxKArr ) {
308+ final java .util .ArrayList <Long > predeterminedSamples = new java .util .ArrayList <>();
309+ for (int i = 0 ; i < maxK ; i ++) {
310+ predeterminedSamples .add ((long ) (i * 2 ));
311+ }
312+
313+ final ReservoirItemsSketch <Long > sk = ReservoirItemsSketch .newInstance (
314+ predeterminedSamples ,
315+ n ,
316+ ResizeFactor .X8 ,
317+ maxK
318+ );
319+
320+ final ReservoirItemsUnion <Long > union = ReservoirItemsUnion .newInstance (maxK );
321+ union .update (sk );
322+
323+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_long_sampling_n" + n + "_maxk" + maxK + "_java.sk" ))
324+ .write (union .toByteArray (new ArrayOfLongsSerDe ()));
325+ }
326+ }
327+
328+ @ Test (groups = {GENERATE_JAVA_FILES })
329+ public void generateReservoirItemsUnionDoubleEmpty () throws IOException {
330+ final int maxK = 128 ;
331+ final ReservoirItemsUnion <Double > union = ReservoirItemsUnion .newInstance (maxK );
332+
333+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_double_empty_maxk" + maxK + "_java.sk" ))
334+ .write (union .toByteArray (new ArrayOfDoublesSerDe ()));
335+ }
336+
337+ @ Test (groups = {GENERATE_JAVA_FILES })
338+ public void generateReservoirItemsUnionDoubleExact () throws IOException {
339+ final int maxK = 128 ;
340+ final int [] nArr = {1 , 10 , 32 , 100 , 128 };
341+
342+ for (final int n : nArr ) {
343+ final ReservoirItemsUnion <Double > union = ReservoirItemsUnion .newInstance (maxK );
344+ for (int i = 0 ; i < n ; i ++) {
345+ union .update ((double ) i );
346+ }
347+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_double_exact_n" + n + "_maxk" + maxK + "_java.sk" ))
348+ .write (union .toByteArray (new ArrayOfDoublesSerDe ()));
349+ }
350+ }
351+
352+ @ Test (groups = {GENERATE_JAVA_FILES })
353+ public void generateReservoirItemsUnionDoubleSampling () throws IOException {
354+ final int [] maxKArr = {32 , 64 , 128 };
355+ final long n = 1000 ;
356+
357+ for (final int maxK : maxKArr ) {
358+ final java .util .ArrayList <Double > predeterminedSamples = new java .util .ArrayList <>();
359+ for (int i = 0 ; i < maxK ; i ++) {
360+ predeterminedSamples .add ((double ) (i * 2 ));
361+ }
362+
363+ final ReservoirItemsSketch <Double > sk = ReservoirItemsSketch .newInstance (
364+ predeterminedSamples ,
365+ n ,
366+ ResizeFactor .X8 ,
367+ maxK
368+ );
369+
370+ final ReservoirItemsUnion <Double > union = ReservoirItemsUnion .newInstance (maxK );
371+ union .update (sk );
372+
373+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_double_sampling_n" + n + "_maxk" + maxK + "_java.sk" ))
374+ .write (union .toByteArray (new ArrayOfDoublesSerDe ()));
375+ }
376+ }
377+
378+ @ Test (groups = {GENERATE_JAVA_FILES })
379+ public void generateReservoirItemsUnionStringEmpty () throws IOException {
380+ final int maxK = 128 ;
381+ final ReservoirItemsUnion <String > union = ReservoirItemsUnion .newInstance (maxK );
382+
383+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_string_empty_maxk" + maxK + "_java.sk" ))
384+ .write (union .toByteArray (new ArrayOfStringsSerDe ()));
385+ }
386+
387+ @ Test (groups = {GENERATE_JAVA_FILES })
388+ public void generateReservoirItemsUnionStringExact () throws IOException {
389+ final int maxK = 128 ;
390+ final int [] nArr = {1 , 10 , 32 , 100 , 128 };
391+
392+ for (final int n : nArr ) {
393+ final ReservoirItemsUnion <String > union = ReservoirItemsUnion .newInstance (maxK );
394+ for (int i = 0 ; i < n ; i ++) {
395+ union .update ("item" + i );
396+ }
397+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_string_exact_n" + n + "_maxk" + maxK + "_java.sk" ))
398+ .write (union .toByteArray (new ArrayOfStringsSerDe ()));
399+ }
400+ }
401+
402+ @ Test (groups = {GENERATE_JAVA_FILES })
403+ public void generateReservoirItemsUnionStringSampling () throws IOException {
404+ final int [] maxKArr = {32 , 64 , 128 };
405+ final long n = 1000 ;
406+
407+ for (final int maxK : maxKArr ) {
408+ final java .util .ArrayList <String > predeterminedSamples = new java .util .ArrayList <>();
409+ for (int i = 0 ; i < maxK ; i ++) {
410+ predeterminedSamples .add ("item" + (i * 2 ));
411+ }
412+
413+ final ReservoirItemsSketch <String > sk = ReservoirItemsSketch .newInstance (
414+ predeterminedSamples ,
415+ n ,
416+ ResizeFactor .X8 ,
417+ maxK
418+ );
419+
420+ final ReservoirItemsUnion <String > union = ReservoirItemsUnion .newInstance (maxK );
421+ union .update (sk );
422+
423+ Files .newOutputStream (javaPath .resolve ("reservoir_items_union_string_sampling_n" + n + "_maxk" + maxK + "_java.sk" ))
424+ .write (union .toByteArray (new ArrayOfStringsSerDe ()));
425+ }
426+ }
226427}
0 commit comments