22
33import java .sql .ResultSet ;
44import java .sql .Statement ;
5+ import java .util .Locale ;
6+
57import org .openjdk .jmh .annotations .Benchmark ;
68import org .openjdk .jmh .infra .Blackhole ;
79
@@ -10,162 +12,210 @@ public class Query extends DriverBenchmark {
1012 public void selectArrayOfUInt16 (Blackhole blackhole , DriverState state ) throws Throwable {
1113 int num = state .getRandomNumber ();
1214 int rows = state .getSampleSize () + num ;
13- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getArray (i )));
15+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getArray (i )));
16+ int l = 0 ;
1417 try (Statement stmt = executeQuery (state ,
1518 "select range(100, number % 600) as v from numbers(?)" , rows )) {
1619 ResultSet rs = stmt .getResultSet ();
1720 while (rs .next ()) {
18- func .consume (blackhole , rs , 1 );
21+ func .consume (blackhole , rs , l ++, 1 );
1922 }
2023 }
24+ if (l != rows ) {
25+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
26+ }
2127 }
2228
2329 @ Benchmark
2430 public void selectMapOfInt32 (Blackhole blackhole , DriverState state ) throws Throwable {
2531 int num = state .getRandomNumber ();
2632 int rows = state .getSampleSize () + num ;
27- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getObject (i )));
33+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getObject (i )));
34+ int l = 0 ;
2835 try (Statement stmt = executeQuery (state ,
2936 "select cast((arrayMap(x->x+1000, range(1, number % 100)), arrayMap(x->x+10000, range(1, number %100))) as Map(Int32, Int32)) as v from numbers(?)" ,
3037 rows )) {
3138 ResultSet rs = stmt .getResultSet ();
3239 while (rs .next ()) {
33- func .consume (blackhole , rs , 1 );
40+ func .consume (blackhole , rs , l ++, 1 );
3441 }
3542 }
43+ if (l != rows ) {
44+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
45+ }
3646 }
3747
3848 @ Benchmark
3949 public void selectTupleOfInt16 (Blackhole blackhole , DriverState state ) throws Throwable {
4050 int num = state .getRandomNumber ();
4151 int rows = state .getSampleSize () + num ;
42- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getObject (i )));
52+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getObject (i )));
53+ int l = 0 ;
4354 try (Statement stmt = executeQuery (state ,
4455 "select tuple(arrayMap(x -> cast(x as Int16), range(100, number % 600))) as v from numbers(?)" , rows )) {
4556 ResultSet rs = stmt .getResultSet ();
4657 while (rs .next ()) {
47- func .consume (blackhole , rs , 1 );
58+ func .consume (blackhole , rs , l ++, 1 );
4859 }
4960 }
61+ if (l != rows ) {
62+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
63+ }
5064 }
5165
5266 @ Benchmark
5367 public void selectDateTime32 (Blackhole blackhole , DriverState state ) throws Throwable {
5468 int num = state .getRandomNumber ();
5569 int rows = state .getSampleSize () + num ;
56- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getTimestamp (i )));
70+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getTimestamp (i )));
71+ int l = 0 ;
5772 try (Statement stmt = executeQuery (state ,
5873 "select toDateTime32(1613826920 + number) as v from numbers(?)" , rows )) {
5974 ResultSet rs = stmt .getResultSet ();
6075 while (rs .next ()) {
61- func .consume (blackhole , rs , 1 );
76+ func .consume (blackhole , rs , l ++, 1 );
6277 }
6378 }
79+ if (l != rows ) {
80+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
81+ }
6482 }
6583
6684 @ Benchmark
6785 public void selectDateTime64 (Blackhole blackhole , DriverState state ) throws Throwable {
6886 int num = state .getRandomNumber ();
6987 int rows = state .getSampleSize () + num ;
70- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getTimestamp (i )));
88+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getTimestamp (i )));
89+ int l = 0 ;
7190 try (Statement stmt = executeQuery (state ,
7291 "select toDateTime64(1613826920 + number / 1000000000, 9) as v from numbers(?)" , rows )) {
7392 ResultSet rs = stmt .getResultSet ();
7493 while (rs .next ()) {
75- func .consume (blackhole , rs , 1 );
94+ func .consume (blackhole , rs , l ++, 1 );
7695 }
7796 }
97+ if (l != rows ) {
98+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
99+ }
78100 }
79101
80102 @ Benchmark
81103 public void selectInt8 (Blackhole blackhole , DriverState state ) throws Throwable {
82104 int num = state .getRandomNumber ();
83105 int rows = state .getSampleSize () + num ;
84- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getByte (i )));
106+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getByte (i )));
107+ int l = 0 ;
85108 try (Statement stmt = executeQuery (state , "select toInt8(number % 256) as v from numbers(?)" , rows )) {
86109 ResultSet rs = stmt .getResultSet ();
87110 while (rs .next ()) {
88- func .consume (blackhole , rs , 1 );
111+ func .consume (blackhole , rs , l ++, 1 );
89112 }
90113 }
114+ if (l != rows ) {
115+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
116+ }
91117 }
92118
93119 @ Benchmark
94120 public void selectUInt8 (Blackhole blackhole , DriverState state ) throws Throwable {
95121 int num = state .getRandomNumber ();
96122 int rows = state .getSampleSize () + num ;
97- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getShort (i )));
123+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getShort (i )));
124+ int l = 0 ;
98125 try (Statement stmt = executeQuery (state , "select toUInt8(number % 256) as v from numbers(?)" , rows )) {
99126 ResultSet rs = stmt .getResultSet ();
100127 while (rs .next ()) {
101- func .consume (blackhole , rs , 1 );
128+ func .consume (blackhole , rs , l ++, 1 );
102129 }
103130 }
131+ if (l != rows ) {
132+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
133+ }
104134 }
105135
106136 @ Benchmark
107137 public void selectUuid (Blackhole blackhole , DriverState state ) throws Throwable {
108138 int num = state .getRandomNumber ();
109139 int rows = state .getSampleSize () + num ;
110- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getString (i )));
140+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getString (i )));
141+ int l = 0 ;
111142 try (Statement stmt = executeQuery (state , "select generateUUIDv4() as v from numbers(?)" , rows )) {
112143 ResultSet rs = stmt .getResultSet ();
113144 while (rs .next ()) {
114- func .consume (blackhole , rs , 1 );
145+ func .consume (blackhole , rs , l ++, 1 );
115146 }
116147 }
148+ if (l != rows ) {
149+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
150+ }
117151 }
118152
119153 @ Benchmark
120154 public void selectInt32 (Blackhole blackhole , DriverState state ) throws Throwable {
121155 int num = state .getRandomNumber ();
122156 int rows = state .getSampleSize () + num ;
123- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getInt (i )));
157+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getInt (i )));
158+ int l = 0 ;
124159 try (Statement stmt = executeQuery (state , "select toInt32(number) as v from numbers(?)" , rows )) {
125160 ResultSet rs = stmt .getResultSet ();
126161 while (rs .next ()) {
127- func .consume (blackhole , rs , 1 );
162+ func .consume (blackhole , rs , l ++, 1 );
128163 }
129164 }
165+ if (l != rows ) {
166+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
167+ }
130168 }
131169
132170 @ Benchmark
133171 public void selectString (Blackhole blackhole , DriverState state ) throws Throwable {
134172 int num = state .getRandomNumber ();
135173 int rows = state .getSampleSize () + num ;
136- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getString (i )));
174+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getString (i )));
175+ int l = 0 ;
137176 try (Statement stmt = executeQuery (state , "select toString(number/3) as v from numbers(?)" , rows )) {
138177 ResultSet rs = stmt .getResultSet ();
139178 while (rs .next ()) {
140- func .consume (blackhole , rs , 1 );
179+ func .consume (blackhole , rs , l ++, 1 );
141180 }
142181 }
182+ if (l != rows ) {
183+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
184+ }
143185 }
144186
145187 @ Benchmark
146188 public void selectUInt64 (Blackhole blackhole , DriverState state ) throws Throwable {
147189 int num = state .getRandomNumber ();
148190 int rows = state .getSampleSize () + num ;
149- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getLong (i )));
191+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getLong (i )));
192+ int l = 0 ;
150193 try (Statement stmt = executeQuery (state , "select number as v from numbers(?)" , rows )) {
151194 ResultSet rs = stmt .getResultSet ();
152195 while (rs .next ()) {
153- func .consume (blackhole , rs , 1 );
196+ func .consume (blackhole , rs , l ++, 1 );
154197 }
155198 }
199+ if (l != rows ) {
200+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
201+ }
156202 }
157203
158204 @ Benchmark
159205 public void selectDecimal64 (Blackhole blackhole , DriverState state ) throws Throwable {
160206 int num = state .getRandomNumber ();
161207 int rows = state .getSampleSize () + num ;
162- ConsumeValueFunction func = state .getConsumeFunction ((b , r , i ) -> b .consume (r .getBigDecimal (i )));
208+ ConsumeValueFunction func = state .getConsumeFunction ((b , r , l , i ) -> b .consume (r .getBigDecimal (i )));
209+ int l = 0 ;
163210 try (Statement stmt = executeQuery (state , "select toDecimal64(number + number / 10000, 4) as v from numbers(?)" ,
164211 rows )) {
165212 ResultSet rs = stmt .getResultSet ();
166213 while (rs .next ()) {
167- func .consume (blackhole , rs , 1 );
214+ func .consume (blackhole , rs , l ++, 1 );
168215 }
169216 }
217+ if (l != rows ) {
218+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
219+ }
170220 }
171221}
0 commit comments