2
2
3
3
import java .sql .ResultSet ;
4
4
import java .sql .Statement ;
5
+ import java .util .Locale ;
6
+
5
7
import org .openjdk .jmh .annotations .Benchmark ;
6
8
import org .openjdk .jmh .infra .Blackhole ;
7
9
@@ -10,162 +12,210 @@ public class Query extends DriverBenchmark {
10
12
public void selectArrayOfUInt16 (Blackhole blackhole , DriverState state ) throws Throwable {
11
13
int num = state .getRandomNumber ();
12
14
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 ;
14
17
try (Statement stmt = executeQuery (state ,
15
18
"select range(100, number % 600) as v from numbers(?)" , rows )) {
16
19
ResultSet rs = stmt .getResultSet ();
17
20
while (rs .next ()) {
18
- func .consume (blackhole , rs , 1 );
21
+ func .consume (blackhole , rs , l ++, 1 );
19
22
}
20
23
}
24
+ if (l != rows ) {
25
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
26
+ }
21
27
}
22
28
23
29
@ Benchmark
24
30
public void selectMapOfInt32 (Blackhole blackhole , DriverState state ) throws Throwable {
25
31
int num = state .getRandomNumber ();
26
32
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 ;
28
35
try (Statement stmt = executeQuery (state ,
29
36
"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(?)" ,
30
37
rows )) {
31
38
ResultSet rs = stmt .getResultSet ();
32
39
while (rs .next ()) {
33
- func .consume (blackhole , rs , 1 );
40
+ func .consume (blackhole , rs , l ++, 1 );
34
41
}
35
42
}
43
+ if (l != rows ) {
44
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
45
+ }
36
46
}
37
47
38
48
@ Benchmark
39
49
public void selectTupleOfInt16 (Blackhole blackhole , DriverState state ) throws Throwable {
40
50
int num = state .getRandomNumber ();
41
51
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 ;
43
54
try (Statement stmt = executeQuery (state ,
44
55
"select tuple(arrayMap(x -> cast(x as Int16), range(100, number % 600))) as v from numbers(?)" , rows )) {
45
56
ResultSet rs = stmt .getResultSet ();
46
57
while (rs .next ()) {
47
- func .consume (blackhole , rs , 1 );
58
+ func .consume (blackhole , rs , l ++, 1 );
48
59
}
49
60
}
61
+ if (l != rows ) {
62
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
63
+ }
50
64
}
51
65
52
66
@ Benchmark
53
67
public void selectDateTime32 (Blackhole blackhole , DriverState state ) throws Throwable {
54
68
int num = state .getRandomNumber ();
55
69
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 ;
57
72
try (Statement stmt = executeQuery (state ,
58
73
"select toDateTime32(1613826920 + number) as v from numbers(?)" , rows )) {
59
74
ResultSet rs = stmt .getResultSet ();
60
75
while (rs .next ()) {
61
- func .consume (blackhole , rs , 1 );
76
+ func .consume (blackhole , rs , l ++, 1 );
62
77
}
63
78
}
79
+ if (l != rows ) {
80
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
81
+ }
64
82
}
65
83
66
84
@ Benchmark
67
85
public void selectDateTime64 (Blackhole blackhole , DriverState state ) throws Throwable {
68
86
int num = state .getRandomNumber ();
69
87
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 ;
71
90
try (Statement stmt = executeQuery (state ,
72
91
"select toDateTime64(1613826920 + number / 1000000000, 9) as v from numbers(?)" , rows )) {
73
92
ResultSet rs = stmt .getResultSet ();
74
93
while (rs .next ()) {
75
- func .consume (blackhole , rs , 1 );
94
+ func .consume (blackhole , rs , l ++, 1 );
76
95
}
77
96
}
97
+ if (l != rows ) {
98
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
99
+ }
78
100
}
79
101
80
102
@ Benchmark
81
103
public void selectInt8 (Blackhole blackhole , DriverState state ) throws Throwable {
82
104
int num = state .getRandomNumber ();
83
105
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 ;
85
108
try (Statement stmt = executeQuery (state , "select toInt8(number % 256) as v from numbers(?)" , rows )) {
86
109
ResultSet rs = stmt .getResultSet ();
87
110
while (rs .next ()) {
88
- func .consume (blackhole , rs , 1 );
111
+ func .consume (blackhole , rs , l ++, 1 );
89
112
}
90
113
}
114
+ if (l != rows ) {
115
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
116
+ }
91
117
}
92
118
93
119
@ Benchmark
94
120
public void selectUInt8 (Blackhole blackhole , DriverState state ) throws Throwable {
95
121
int num = state .getRandomNumber ();
96
122
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 ;
98
125
try (Statement stmt = executeQuery (state , "select toUInt8(number % 256) as v from numbers(?)" , rows )) {
99
126
ResultSet rs = stmt .getResultSet ();
100
127
while (rs .next ()) {
101
- func .consume (blackhole , rs , 1 );
128
+ func .consume (blackhole , rs , l ++, 1 );
102
129
}
103
130
}
131
+ if (l != rows ) {
132
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
133
+ }
104
134
}
105
135
106
136
@ Benchmark
107
137
public void selectUuid (Blackhole blackhole , DriverState state ) throws Throwable {
108
138
int num = state .getRandomNumber ();
109
139
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 ;
111
142
try (Statement stmt = executeQuery (state , "select generateUUIDv4() as v from numbers(?)" , rows )) {
112
143
ResultSet rs = stmt .getResultSet ();
113
144
while (rs .next ()) {
114
- func .consume (blackhole , rs , 1 );
145
+ func .consume (blackhole , rs , l ++, 1 );
115
146
}
116
147
}
148
+ if (l != rows ) {
149
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
150
+ }
117
151
}
118
152
119
153
@ Benchmark
120
154
public void selectInt32 (Blackhole blackhole , DriverState state ) throws Throwable {
121
155
int num = state .getRandomNumber ();
122
156
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 ;
124
159
try (Statement stmt = executeQuery (state , "select toInt32(number) as v from numbers(?)" , rows )) {
125
160
ResultSet rs = stmt .getResultSet ();
126
161
while (rs .next ()) {
127
- func .consume (blackhole , rs , 1 );
162
+ func .consume (blackhole , rs , l ++, 1 );
128
163
}
129
164
}
165
+ if (l != rows ) {
166
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
167
+ }
130
168
}
131
169
132
170
@ Benchmark
133
171
public void selectString (Blackhole blackhole , DriverState state ) throws Throwable {
134
172
int num = state .getRandomNumber ();
135
173
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 ;
137
176
try (Statement stmt = executeQuery (state , "select toString(number/3) as v from numbers(?)" , rows )) {
138
177
ResultSet rs = stmt .getResultSet ();
139
178
while (rs .next ()) {
140
- func .consume (blackhole , rs , 1 );
179
+ func .consume (blackhole , rs , l ++, 1 );
141
180
}
142
181
}
182
+ if (l != rows ) {
183
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
184
+ }
143
185
}
144
186
145
187
@ Benchmark
146
188
public void selectUInt64 (Blackhole blackhole , DriverState state ) throws Throwable {
147
189
int num = state .getRandomNumber ();
148
190
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 ;
150
193
try (Statement stmt = executeQuery (state , "select number as v from numbers(?)" , rows )) {
151
194
ResultSet rs = stmt .getResultSet ();
152
195
while (rs .next ()) {
153
- func .consume (blackhole , rs , 1 );
196
+ func .consume (blackhole , rs , l ++, 1 );
154
197
}
155
198
}
199
+ if (l != rows ) {
200
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
201
+ }
156
202
}
157
203
158
204
@ Benchmark
159
205
public void selectDecimal64 (Blackhole blackhole , DriverState state ) throws Throwable {
160
206
int num = state .getRandomNumber ();
161
207
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 ;
163
210
try (Statement stmt = executeQuery (state , "select toDecimal64(number + number / 10000, 4) as v from numbers(?)" ,
164
211
rows )) {
165
212
ResultSet rs = stmt .getResultSet ();
166
213
while (rs .next ()) {
167
- func .consume (blackhole , rs , 1 );
214
+ func .consume (blackhole , rs , l ++, 1 );
168
215
}
169
216
}
217
+ if (l != rows ) {
218
+ throw new IllegalStateException (String .format (Locale .ROOT , "Expected %d rows but got %d" , rows , l ));
219
+ }
170
220
}
171
221
}
0 commit comments