-
Notifications
You must be signed in to change notification settings - Fork 624
Expand file tree
/
Copy pathStatementTest.java
More file actions
1605 lines (1436 loc) · 75.3 KB
/
StatementTest.java
File metadata and controls
1605 lines (1436 loc) · 75.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.clickhouse.jdbc;
import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.internal.ServerSettings;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.data.ClickHouseVersion;
import com.clickhouse.jdbc.internal.SqlParserFacade;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.sql.Array;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
@Test(groups = {"integration"})
public class StatementTest extends JdbcIntegrationTest {
private static final Logger log = LoggerFactory.getLogger(StatementTest.class);
@Test(groups = {"integration"})
public void testExecuteQuerySimpleNumbers() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
Assert.assertThrows(SQLException.class, () -> stmt.setFetchDirection(100));
stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
assertEquals(stmt.getFetchDirection(), ResultSet.FETCH_FORWARD); // we support only this direction
try (ResultSet rs = stmt.executeQuery("SELECT 1 AS num")) {
assertTrue(rs.next());
assertEquals(rs.getByte(1), 1);
assertEquals(rs.getByte("num"), 1);
assertEquals(rs.getShort(1), 1);
assertEquals(rs.getShort("num"), 1);
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getInt("num"), 1);
assertEquals(rs.getLong(1), 1);
assertEquals(rs.getLong("num"), 1);
assertFalse(rs.next());
}
Assert.assertFalse(((StatementImpl) stmt).getLastQueryId().isEmpty());
}
}
}
@Test(groups = {"integration"})
public void testExecuteQuerySimpleFloats() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT 1.1 AS num")) {
assertTrue(rs.next());
assertEquals(rs.getFloat(1), 1.1f);
assertEquals(rs.getFloat("num"), 1.1f);
assertEquals(rs.getDouble(1), 1.1);
assertEquals(rs.getDouble("num"), 1.1);
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteQueryBooleans() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT true AS flag")) {
assertTrue(rs.next());
assertTrue(rs.getBoolean(1));
assertTrue(rs.getBoolean("flag"));
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteQueryStrings() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT 'Hello' AS words")) {
assertTrue(rs.next());
assertEquals(rs.getString(1), "Hello");
assertEquals(rs.getString("words"), "Hello");
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteQueryNulls() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT NULL AS nothing")) {
assertTrue(rs.next());
assertNull(rs.getObject(1));
assertNull(rs.getObject("nothing"));
assertNull(rs.getString(1));
assertNull(rs.getString("nothing"));
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteQueryDates() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT toDate('2020-01-01') AS date, toDateTime('2020-01-01 10:11:12', 'Asia/Istanbul') AS datetime")) {
assertTrue(rs.next());
assertEquals(rs.getDate(1).toString(), Date.valueOf("2020-01-01").toString());
assertEquals(rs.getDate("date").toString(), Date.valueOf("2020-01-01").toString());
assertEquals(rs.getString(1), "2020-01-01");
assertEquals(rs.getString("date"), "2020-01-01");
assertEquals(rs.getDate(2).toString(), "2020-01-01");
assertEquals(rs.getDate("datetime").toString(), "2020-01-01");
assertEquals(rs.getString(2), "2020-01-01 10:11:12");
assertEquals(rs.getString("datetime"), "2020-01-01 10:11:12");
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateSimpleNumbers() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleNumbers (num UInt8) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".simpleNumbers VALUES (1), (2), (3)"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + getDatabase() + ".simpleNumbers ORDER BY num")) {
assertTrue(rs.next());
assertEquals(rs.getShort(1), 1);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 2);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 3);
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateSimpleFloats() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleFloats (num Float32) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".simpleFloats VALUES (1.1), (2.2), (3.3)"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + getDatabase() + ".simpleFloats ORDER BY num")) {
assertTrue(rs.next());
assertEquals(rs.getFloat(1), 1.1f);
assertTrue(rs.next());
assertEquals(rs.getFloat(1), 2.2f);
assertTrue(rs.next());
assertEquals(rs.getFloat(1), 3.3f);
assertFalse(rs.next());
}
assertEquals(stmt.getUpdateCount(), -1);
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateBooleans() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".booleans (id UInt8, flag Boolean) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".booleans VALUES (0, true), (1, false), (2, true)"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT flag FROM " + getDatabase() + ".booleans ORDER BY id")) {
assertTrue(rs.next());
assertTrue(rs.getBoolean(1));
assertTrue(rs.next());
assertFalse(rs.getBoolean(1));
assertTrue(rs.next());
assertTrue(rs.getBoolean(1));
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateStrings() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".strings (id UInt8, words String) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".strings VALUES (0, 'Hello'), (1, 'World'), (2, 'ClickHouse')"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT words FROM " + getDatabase() + ".strings ORDER BY id")) {
assertTrue(rs.next());
assertEquals(rs.getString(1), "Hello");
assertTrue(rs.next());
assertEquals(rs.getString(1), "World");
assertTrue(rs.next());
assertEquals(rs.getString(1), "ClickHouse");
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateNulls() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".nulls (id UInt8, nothing Nullable(String)) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".nulls VALUES (0, 'Hello'), (1, NULL), (2, 'ClickHouse')"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT nothing FROM " + getDatabase() + ".nulls ORDER BY id")) {
assertTrue(rs.next());
assertEquals(rs.getString(1), "Hello");
assertTrue(rs.next());
assertNull(rs.getString(1));
assertTrue(rs.next());
assertEquals(rs.getString(1), "ClickHouse");
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateDates() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".dates (id UInt8, date Nullable(Date), datetime Nullable(DateTime)) ENGINE = MergeTree ORDER BY ()"), 0);
assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".dates VALUES (0, '2020-01-01', '2020-01-01 10:11:12'), (1, NULL, '2020-01-01 12:10:07'), (2, '2020-01-01', NULL)"), 3);
try (ResultSet rs = stmt.executeQuery("SELECT date, datetime FROM " + getDatabase() + ".dates ORDER BY id")) {
assertTrue(rs.next());
assertEquals(rs.getDate(1).toString(), "2020-01-01");
assertEquals(rs.getDate(2).toString(), "2020-01-01");
assertTrue(rs.next());
assertNull(rs.getDate(1));
assertEquals(rs.getDate(2).toString(), "2020-01-01");
assertTrue(rs.next());
assertEquals(rs.getDate(1).toString(), "2020-01-01");
assertNull(rs.getDate(2));
assertFalse(rs.next());
}
}
}
}
private static final int ASYNC_INSERT_SETTINGS_DP_ROWS = 100_000;
@DataProvider(name = "asyncInsertSettingsDP")
public static Object[][] asyncInsertSettingsDP() {
return new Object[][]{
// asyncInsert, waitAsyncInsert, expectedUpdateCount, expectedSelectCount, should fail
{ServerSettings.OFF, ServerSettings.OFF, ASYNC_INSERT_SETTINGS_DP_ROWS, ASYNC_INSERT_SETTINGS_DP_ROWS, true},
{ServerSettings.OFF, ServerSettings.ON, ASYNC_INSERT_SETTINGS_DP_ROWS, ASYNC_INSERT_SETTINGS_DP_ROWS, true},
{ServerSettings.ON, ServerSettings.OFF, 0, -1, false}, // return immediately
{ServerSettings.ON, ServerSettings.ON, ASYNC_INSERT_SETTINGS_DP_ROWS, ASYNC_INSERT_SETTINGS_DP_ROWS, true}
};
}
@Test(groups = {"integration"}, dataProvider = "asyncInsertSettingsDP")
public void testInsertWithAsyncInsert(String asyncInsert, String waitAsyncInsert, int expectedUpdateCount, int expectedSelectCount, boolean fails) throws Exception {
String tableName = "test_async_insert_param_" + asyncInsert + "_" + waitAsyncInsert + "_" + UUID.randomUUID().toString().replace("-", "_");
Properties props = new Properties();
props.setProperty(ClientConfigProperties.serverSetting(ServerSettings.ASYNC_INSERT), asyncInsert);
props.setProperty(ClientConfigProperties.serverSetting(ServerSettings.WAIT_ASYNC_INSERT), waitAsyncInsert);
// Wait end of query off for isolation of this logic
props.setProperty(ClientConfigProperties.serverSetting(ServerSettings.WAIT_END_OF_QUERY), ServerSettings.OFF);
if (waitAsyncInsert.equals(ServerSettings.ON)) {
// make it flush to disk to check that we get result. If buffer is bigger server may wait flushing to disk.
props.setProperty(ClientConfigProperties.serverSetting("async_insert_max_data_size"), "3488890");
}
StringBuilder sb = new StringBuilder("INSERT INTO " + getDatabase() + "." + tableName + " FORMAT TSV\n");
for (int i = 0; i < ASYNC_INSERT_SETTINGS_DP_ROWS; i++) {
sb.append(i).append("\t")
.append("name_").append(i).append("\t")
.append(i * 1.1).append("\t")
.append(i % 2).append("\t")
.append("2023-01-01 10:11:12").append("\n");
}
final String insertStatement = sb.toString();
try (Connection conn = getJdbcConnection(props)) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE IF NOT EXISTS " + getDatabase() + "." + tableName + " (id UInt32, name String, value Float64, status Int8, timestamp DateTime) ENGINE = MergeTree ORDER BY id");
stmt.execute("TRUNCATE TABLE " + getDatabase() + "." + tableName);
int updateCount = stmt.executeUpdate(insertStatement);
assertEquals(updateCount, expectedUpdateCount);
try (ResultSet rs = stmt.executeQuery("SELECT count() FROM " + getDatabase() + "." + tableName)) {
assertTrue(rs.next());
int count = rs.getInt(1);
if (expectedSelectCount == -1) {
assertTrue(count < ASYNC_INSERT_SETTINGS_DP_ROWS, "Expected count to be < " + ASYNC_INSERT_SETTINGS_DP_ROWS + ", but was: " + count);
} else {
assertEquals(count, expectedSelectCount);
}
}
// verify error scenario
final String failingInsertStatement = insertStatement
+ "some\t1invalid\trow\t10\n";
try {
stmt.executeUpdate(failingInsertStatement);
assertFalse(fails, "should fail");
} catch (Exception e) {
assertTrue(fails, "should not fail");
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateBatch() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".batch (id UInt8, num UInt8) ENGINE = MergeTree ORDER BY ()"), 0);
stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (0, 1)");
stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (1, 2)");
stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (2, 3), (3, 4)");
int[] counts = stmt.executeBatch();
assertEquals(counts.length, 3);
assertEquals(counts[0], 1);
assertEquals(counts[1], 1);
assertEquals(counts[2], 2);
try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + getDatabase() + ".batch ORDER BY id")) {
assertTrue(rs.next());
assertEquals(rs.getShort(1), 1);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 2);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 3);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 4);
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteUpdateBatchReuse() throws Exception {
String tableClause = getDatabase() + ".batch_reuse";
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableClause + " (id UInt8, num UInt8) ENGINE = MergeTree ORDER BY ()"), 0);
// add and execute first invalid batch
stmt.addBatch("INSERT INTO " + tableClause + " VALUES (0, 'invalid')");
assertThrows(SQLException.class, stmt::executeBatch);
// add and execute second batch, which should fail due to the previous batch data.
stmt.addBatch("INSERT INTO " + tableClause + " VALUES (1, 2)");
assertThrows(SQLException.class, stmt::executeBatch);
// add and execute third batch, which should not fail
stmt.clearBatch();
stmt.addBatch("INSERT INTO " + tableClause + " VALUES (0, 1)");
stmt.addBatch("INSERT INTO " + tableClause + " VALUES (1, 2)");
assertEquals(stmt.executeBatch(), new int[]{1, 1});
stmt.addBatch("INSERT INTO " + tableClause + " VALUES (2, 3), (3, 4)");
assertEquals(stmt.executeBatch(), new int[]{2});
try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + tableClause + " ORDER BY id")) {
assertTrue(rs.next());
assertEquals(rs.getShort(1), 1);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 2);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 3);
assertTrue(rs.next());
assertEquals(rs.getShort(1), 4);
assertFalse(rs.next());
}
}
}
}
@Test(groups = {"integration"})
public void testJdbcEscapeSyntax() throws Exception {
if (ClickHouseVersion.of(getServerVersion()).check("(,23.8]")) {
return; // there is no `timestamp` function TODO: fix in JDBC
}
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT {d '2021-11-01'} AS D, {ts '2021-08-01 12:34:56'} AS TS, " +
"toInt32({fn ABS(-1)}) AS FNABS, {fn CONCAT('Hello', 'World')} AS FNCONCAT, {fn UCASE('hello')} AS FNUPPER, " +
"{fn LCASE('HELLO')} AS FNLOWER, {fn LTRIM(' Hello ')} AS FNLTRIM, {fn RTRIM(' Hello ')} AS FNRTRIM, " +
"toInt32({fn LENGTH('Hello')}) AS FNLENGTH, toInt32({fn POSITION('Hello', 'l')}) AS FNPOSITION, toInt32({fn MOD(10, 3)}) AS FNMOD, " +
"{fn SQRT(9)} AS FNSQRT, {fn SUBSTRING('Hello', 3, 2)} AS FNSUBSTRING")) {
assertTrue(rs.next());
assertEquals(rs.getDate(1), Date.valueOf(LocalDate.of(2021, 11, 1)));
//assertEquals(rs.getTimestamp(2), java.sql.Timestamp.valueOf(LocalDateTime.of(2021, 11, 1, 12, 34, 56)));
assertEquals(rs.getInt(3), 1);
assertEquals(rs.getInt("FNABS"), 1);
assertEquals(rs.getString(4), "HelloWorld");
assertEquals(rs.getString("FNCONCAT"), "HelloWorld");
assertEquals(rs.getString(5), "HELLO");
assertEquals(rs.getString("FNUPPER"), "HELLO");
assertEquals(rs.getString(6), "hello");
assertEquals(rs.getString("FNLOWER"), "hello");
assertEquals(rs.getString(7), "Hello ");
assertEquals(rs.getString("FNLTRIM"), "Hello ");
assertEquals(rs.getString(8), " Hello");
assertEquals(rs.getString("FNRTRIM"), " Hello");
assertEquals(rs.getInt(9), 5);
assertEquals(rs.getInt("FNLENGTH"), 5);
assertEquals(rs.getInt(10), 3);
assertEquals(rs.getInt("FNPOSITION"), 3);
assertEquals(rs.getInt(11), 1);
assertEquals(rs.getInt("FNMOD"), 1);
assertEquals(rs.getDouble(12), 3);
assertEquals(rs.getDouble("FNSQRT"), 3);
assertEquals(rs.getString(13), "ll");
assertEquals(rs.getString("FNSUBSTRING"), "ll");
assertThrows(SQLException.class, () -> rs.getString(14));
assertFalse(rs.next());
}
}
try (Statement stmt = conn.createStatement()) {
stmt.setEscapeProcessing(false);
try (ResultSet rs = stmt.executeQuery("SELECT {d '2021-11-01'} AS D")) {
fail("Expected to fail");
} catch (SQLException e) {
// ignore
}
}
}
}
@Test(groups = {"integration"})
public void testExecuteQueryTimeout() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
stmt.setQueryTimeout(1);
assertThrows(SQLException.class, () -> {
try (ResultSet rs = stmt.executeQuery("SELECT sleep(5)")) {
assertFalse(rs.next());
}
});
}
}
}
@DataProvider(name = "testSettingRolesDP")
public static Object[][] testSettingRolesDP() {
return new Object[][] {
{SqlParserFacade.SQLParser.JAVACC},
{SqlParserFacade.SQLParser.ANTLR4_PARAMS_PARSER},
{SqlParserFacade.SQLParser.ANTLR4},
};
}
@Test(groups = {"integration"}, dataProvider = "testSettingRolesDP", dataProviderClass = StatementTest.class)
public void testSettingRole(SqlParserFacade.SQLParser parser) throws SQLException {
if (earlierThan(24, 4)) {//Min version is 24.4
return;
}
List<String> roles = Arrays.asList("role1", "role2", "role3");
final String userPass = "^1A" + RandomStringUtils.random(12, true, true) + "3B$";
Properties properties = new Properties();
properties.setProperty(DriverProperties.SQL_PARSER.getKey(), parser.name());
try (ConnectionImpl conn = (ConnectionImpl) getJdbcConnection(properties)) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("DROP ROLE IF EXISTS " + String.join(", ", roles));
stmt.execute("DROP USER IF EXISTS some_user");
stmt.execute("CREATE ROLE " + String.join(", ", roles));
stmt.execute("CREATE USER some_user IDENTIFIED BY '" + userPass + "'");
stmt.execute("GRANT " + String.join(", ", roles) + " TO some_user");
stmt.execute("SET DEFAULT ROLE NONE TO some_user");
}
}
Properties info = new Properties();
info.setProperty("user", "some_user");
info.setProperty("password", userPass);
info.setProperty(DriverProperties.SQL_PARSER.getKey(), parser.name());
try (ConnectionImpl conn = new ConnectionImpl(getEndpointString(), info)) {
GenericRecord dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE role1");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 1);
assertEquals(dataRecord.getList(1).get(0), "role1");
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE role2");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 1);
assertEquals(dataRecord.getList(1).get(0), "role2");
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE NONE");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE \"role1\",\"role2\"");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 2);
assertEquals(dataRecord.getList(1).get(0), "role1");
assertEquals(dataRecord.getList(1).get(1), "role2");
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE \"role1\",\"role2\",\"role3\"");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 3);
assertEquals(dataRecord.getList(1).get(0), "role1");
assertEquals(dataRecord.getList(1).get(1), "role2");
assertEquals(dataRecord.getList(1).get(2), "role3");
}
Properties disableSavingRoles = new Properties();
disableSavingRoles.setProperty("user", "some_user");
disableSavingRoles.setProperty("password", userPass);
disableSavingRoles.setProperty(DriverProperties.REMEMBER_LAST_SET_ROLES.getKey(), "false");
disableSavingRoles.setProperty(DriverProperties.SQL_PARSER.getKey(), parser.name());
try (ConnectionImpl conn = new ConnectionImpl(getEndpointString(), disableSavingRoles)) {
GenericRecord dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE role1");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE role2");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE NONE");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE \"role1\",\"role2\"");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
try (Statement stmt = conn.createStatement()) {
stmt.execute("SET ROLE \"role1\",\"role2\",\"role3\"");
}
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
assertEquals(dataRecord.getList(1).size(), 0);
}
}
@Test
public void testGettingArrays() throws Exception {
try (ConnectionImpl conn = (ConnectionImpl) getJdbcConnection();
Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("SELECT [] as empty_array, [1, 2, 3] as number_array, " +
" ['val1', 'val2', 'val3'] as str_array");
assertTrue(rs.next());
Array emptyArray = rs.getArray("empty_array");
assertEquals(((Object[]) emptyArray.getArray()).length, 0);
Array numberArray = rs.getArray("number_array");
assertEquals(((Object[]) numberArray.getArray()).length, 3);
System.out.println(((Object[]) numberArray.getArray())[0].getClass().getName());
assertEquals(numberArray.getArray(), new short[]{1, 2, 3});
Array stringArray = rs.getArray("str_array");
assertEquals(((Object[]) stringArray.getArray()).length, 3);
assertEquals(Arrays.stream(((Object[]) stringArray.getArray())).toList(), Arrays.asList("val1", "val2", "val3"));
}
}
@Test(groups = {"integration"})
public void testConnectionExhaustion() throws Exception {
int maxNumConnections = 3;
Properties properties = new Properties();
properties.put(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), "" + maxNumConnections);
properties.put(ClientConfigProperties.CONNECTION_REQUEST_TIMEOUT.getKey(), "" + 1000); // 1 sec connection req timeout
try (Connection conn = getJdbcConnection(properties)) {
try (Statement stmt = conn.createStatement()) {
for (int i = 0; i < maxNumConnections * 2; i++) {
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 100");
}
}
}
properties.put(DriverProperties.RESULTSET_AUTO_CLOSE.getKey(), "false");
try (Connection conn = getJdbcConnection(properties)) {
try (Statement stmt = conn.createStatement()) {
try {
for (int i = 0; i < maxNumConnections * 2; i++) {
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 100");
}
fail("Exception expected");
} catch (SQLException e) {
// ignore
}
}
}
}
@Test(groups = {"integration"})
public void testCancelOnCluster() throws Exception {
// Generate non-existing cluster name to cause error
String testCluster = "test_cluster_" + RandomStringUtils.randomAlphanumeric(10);
Properties p = new Properties();
p.setProperty(DriverProperties.CLUSTER_NAME.getKey(), testCluster);
try (Connection conn = getJdbcConnection(p)) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) { // to fill queryId
try {
stmt.cancel();
fail("Should have thrown an exception for missing cluster");
} catch (SQLException e) {
assertTrue(e.getMessage().contains(testCluster), "Exception should mention the missing cluster");
}
}
}
// no cluster set - check no exception. actual cancelation is tested elsewhere
try (Connection conn = getJdbcConnection()) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1")) { // to fill queryId
stmt.cancel();
}
}
}
@Test(groups = {"integration"})
public void testConcurrentCancel() throws Exception {
int maxNumConnections = 3;
Properties p = new Properties();
p.put(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), String.valueOf(maxNumConnections));
try (Connection conn = getJdbcConnection()) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 1000000");
stmt.cancel();
}
for (int i = 0; i < maxNumConnections; i++) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
final int threadNum = i;
log.info("Starting thread {}", threadNum);
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread(() -> {
try {
latch.countDown();
ResultSet rs = stmt.executeQuery("SELECT number FROM system.numbers LIMIT 10000000");
} catch (SQLException e) {
log.error("Error in thread {}", threadNum, e);
}
});
t.start();
latch.await();
stmt.cancel();
}
}
}
}
/**
* Waits until the given query id appears in {@code system.processes}, so we know the operation has actually
* started on the server before attempting to cancel it. Uses a dedicated connection (no session) to observe.
*/
private boolean waitForQueryToStart(String queryId, int timeoutSeconds) throws Exception {
if (queryId == null) {
return false;
}
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutSeconds);
while (System.currentTimeMillis() < deadline) {
try (Connection conn = getJdbcConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT count() FROM system.processes WHERE query_id = '" + queryId + "'")) {
if (rs.next() && rs.getLong(1) > 0) {
return true;
}
}
Thread.sleep(200);
}
return false;
}
private String waitForQueryId(StatementImpl stmt, int timeoutSeconds) throws Exception {
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutSeconds);
while (System.currentTimeMillis() < deadline) {
String queryId = stmt.getLastQueryId();
if (queryId != null && !queryId.isEmpty()) {
return queryId;
}
Thread.sleep(50);
}
return null;
}
@Test(groups = {"integration"})
public void testCancelQueryWithSession() throws Exception {
if (isCloud()) {
throw new SkipException("Cloud + HTTP doesn't work well. Enough to test locally");
}
// Regression test for #2690: cancelling a query that runs inside a session must not fail with
// "Session is locked by a concurrent client" (SESSION_IS_LOCKED). The KILL QUERY request issued by
// cancel() must not carry the session id of the query being cancelled.
String sessionId = "test-session-" + UUID.randomUUID();
try (Connection conn = getJdbcConnection()) {
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
stmt.getLocalSettings().setSessionId(sessionId);
stmt.setQueryTimeout(30); // safety net so a failed cancel cannot hang the test
final AtomicReference<Throwable> threadError = new AtomicReference<>();
final CountDownLatch started = new CountDownLatch(1);
Thread worker = new Thread(() -> {
started.countDown();
// Long-running query that only completes when killed.
try (ResultSet rs = stmt.executeQuery("SELECT count() FROM system.numbers_mt")) {
rs.next();
} catch (Throwable t) {
System.out.println("Error: " + t.getMessage());
threadError.set(t);
}
});
worker.start();
started.await();
String queryId = waitForQueryId(stmt, 15);
assertNotNull(queryId, "Query id was not assigned in time");
assertTrue(waitForQueryToStart(queryId, 15), "Query did not start on the server in time");
// Cancel from the main thread - must not throw SESSION_IS_LOCKED.
stmt.cancel();
worker.join(TimeUnit.SECONDS.toMillis(20));
assertFalse(worker.isAlive(), "Query was not cancelled and is still running");
}
}
}
@Test(groups = {"integration"})
public void testCancelInsertWithSession() throws Exception {
if (isCloud()) {
throw new SkipException("Cloud + HTTP doesn't work well. Enough to test locally");
}
// Regression test for #2690 covering a long-running INSERT executed inside a session.
String tableName = getDatabase() + ".cancel_insert_with_session";
String sessionId = "test-session-" + UUID.randomUUID();
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
try (Statement setup = conn.createStatement()) {
setup.execute("DROP TABLE IF EXISTS " + tableName);
setup.execute("CREATE TABLE " + tableName + " (num UInt64) ENGINE = MergeTree ORDER BY ()");
}
try (StatementImpl stmt = (StatementImpl) conn.createStatement()) {
stmt.getLocalSettings().setSessionId(sessionId);
stmt.setQueryTimeout(30); // safety net so a failed cancel cannot hang the test
final AtomicReference<Throwable> threadError = new AtomicReference<>();
final CountDownLatch started = new CountDownLatch(1);
Thread worker = new Thread(() -> {
started.countDown();
// Long-running insert that only completes when killed.
try {
stmt.executeUpdate("INSERT INTO " + tableName + " SELECT number FROM system.numbers_mt");
} catch (Throwable t) {
threadError.set(t);
}
});
worker.start();
started.await();
String queryId = waitForQueryId(stmt, 15);
assertNotNull(queryId, "Query id was not assigned in time");
assertTrue(waitForQueryToStart(queryId, 15), "Insert did not start on the server in time");
// Cancel from the main thread - must not throw SESSION_IS_LOCKED.
stmt.cancel();
worker.join(TimeUnit.SECONDS.toMillis(20));
assertFalse(worker.isAlive(), "Insert was not cancelled and is still running");
} finally {
try (Statement cleanup = conn.createStatement()) {
cleanup.execute("DROP TABLE IF EXISTS " + tableName);
}
}
}
}
@Test(groups = {"integration"})
public void testTextFormatInResponse() throws Exception {
try (Connection conn = getJdbcConnection();
Statement stmt = conn.createStatement()) {
Assert.expectThrows(SQLException.class, () -> stmt.executeQuery("SELECT 1 FORMAT JSON"));
}
}
@Test(groups = "integration")
void testWithClause() throws Exception {
int count = 0;
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("with data as (SELECT number FROM numbers(100)) select * from data");
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
count++;
}
}
}
assertEquals(count, 100);
}
@Test(groups = {"integration"})
public void testSwitchDatabase() throws Exception {
String databaseName = getDatabase() + "_test_switch";
String createSql = "CREATE TABLE switchDatabaseWithUse (id UInt8, words String) ENGINE = MergeTree ORDER BY ()";
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate(createSql), 0);
assertEquals(stmt.executeUpdate("CREATE DATABASE \"" + databaseName + "\""), 0);
assertFalse(stmt.execute("USE \"" + databaseName + "\""));
assertEquals(stmt.executeUpdate(createSql), 0);
}
try (Statement stmt = conn.createStatement()) {
stmt.execute("USE system");
ResultSet rs = stmt.executeQuery("SELECT name FROM settings LIMIT 1;");
assertTrue(rs.next());
assertNotNull(rs.getString(1));
assertFalse(rs.next());
stmt.execute("USE \"" + databaseName + "\"");
rs = stmt.executeQuery("SHOW TABLES LIMIT 1");
assertTrue(rs.next());
assertEquals(rs.getString(1), "switchDatabaseWithUse");
assertFalse(rs.next());
}
}
}
@Test(groups = {"integration"})
public void testNewLineSQLParsing() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
String sqlCreate = "CREATE TABLE balance ( `id` UUID, `currency` String, `amount` Decimal(64, 18), `create_time` DateTime64(6), `_version` UInt64, `_sign` UInt8 ) ENGINE = ReplacingMergeTree PRIMARY KEY id ORDER BY id;";
try (Statement stmt = conn.createStatement()) {
int r = stmt.executeUpdate(sqlCreate);
assertEquals(r, 0);
}
try (Statement stmt = conn.createStatement()) {
String sqlInsert = "INSERT INTO balance VALUES (generateUUIDv4(), 'EUR', '42.42', now(), 144, 255);";
int r = stmt.executeUpdate(sqlInsert);
assertEquals(r, 1);
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT amount FROM balance FINAL;\n")
.append("SELECT amount FROM balance FINAL;").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT * FROM balance\n")
.append("\n")
.append("WITH balance_cte AS (\n")
.append("SELECT\n")
.append("id, currency, amount\n")
.append("FROM balance\n")
.append("LIMIT 10\n")
.append(")\n")
.append("SELECT * FROM balance_cte;").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
assertFalse(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT amount FROM balance FINAL;\n")
.append("\n")
.append("SELECT amount FROM balance FINAL;").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT amount FROM balance FINAL;\n")
.append("\n")
.append("SELECT amount /* test */FROM balance FINAL;").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT amount FROM balance FINAL;\n")
.append("\n")
.append("SELECT amount FROM balance FINAL; /* test */").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = new StringBuilder("-- SELECT amount FROM balance FINAL;\n")
.append("\n")
.append("SELECT amount FROM balance FINAL; /* test */ -- SELECT 1").toString();
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
}
}
}
@Test(groups = {"integration"})
public void testNullableFixedStringType() throws Exception {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
String sqlCreate = "CREATE TABLE `data_types` (`f1` FixedString(4),`f2` LowCardinality(FixedString(4)), `f3` Nullable(FixedString(4)), `f4` LowCardinality(Nullable(FixedString(4))) ) ENGINE Memory;";
try (Statement stmt = conn.createStatement()) {
int r = stmt.executeUpdate(sqlCreate);
assertEquals(r, 0);
}
try (Statement stmt = conn.createStatement()) {
String sqlInsert = "INSERT INTO `data_types` VALUES ('val1', 'val2', 'val3', 'val4')";
int r = stmt.executeUpdate(sqlInsert);
assertEquals(r, 1);
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = "SELECT * FROM `data_types`";
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
assertEquals(rs.getString(1), "val1");
assertEquals(rs.getString(2), "val2");
assertEquals(rs.getString(3), "val3");
assertEquals(rs.getString(4), "val4");
assertFalse(rs.next());
}
try (Statement stmt = conn.createStatement()) {
String sqlSelect = "SELECT f4 FROM `data_types`";
ResultSet rs = stmt.executeQuery(sqlSelect);
assertTrue(rs.next());
assertEquals(rs.getString(1), "val4");
}
}
}
@Test(groups = {"integration"})
public void testWasNullFlagArray() throws Exception {
try (Connection conn = getJdbcConnection()) {
String sql = "SELECT NULL, ['value1', 'value2']";
Statement stmt = conn.createStatement();
stmt.executeQuery(sql);
ResultSet rs = stmt.getResultSet();
assertTrue(rs.next());
int val = rs.getInt(1);
assertTrue(rs.wasNull());