11package com .clickhouse .jdbc ;
22
3- import com .clickhouse .client .api .Client ;
43import com .clickhouse .client .api .ClientConfigProperties ;
54import com .clickhouse .client .api .query .GenericRecord ;
5+ import com .clickhouse .data .ClickHouseVersion ;
66import org .apache .commons .lang3 .RandomStringUtils ;
7- import org .testng .Assert ;
87import org .testng .annotations .Test ;
9- import org .testng .util .Strings ;
108
119import java .net .Inet4Address ;
1210import java .net .Inet6Address ;
2018import java .util .Arrays ;
2119import java .util .List ;
2220import java .util .Properties ;
23- import java .util .concurrent .TimeUnit ;
2421
25- import static org .testng .Assert .*;
2622import static org .testng .Assert .assertEquals ;
2723import static org .testng .Assert .assertFalse ;
2824import static org .testng .Assert .assertNull ;
@@ -143,7 +139,7 @@ public void testExecuteQueryDates() throws Exception {
143139 public void testExecuteUpdateSimpleNumbers () throws Exception {
144140 try (Connection conn = getJdbcConnection ()) {
145141 try (Statement stmt = conn .createStatement ()) {
146- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".simpleNumbers (num UInt8) ENGINE = Memory " ), 0 );
142+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".simpleNumbers (num UInt8) ENGINE = MergeTree ORDER BY () " ), 0 );
147143 assertEquals (stmt .executeUpdate ("INSERT INTO " + getDatabase () + ".simpleNumbers VALUES (1), (2), (3)" ), 3 );
148144 try (ResultSet rs = stmt .executeQuery ("SELECT num FROM " + getDatabase () + ".simpleNumbers ORDER BY num" )) {
149145 assertTrue (rs .next ());
@@ -162,7 +158,7 @@ public void testExecuteUpdateSimpleNumbers() throws Exception {
162158 public void testExecuteUpdateSimpleFloats () throws Exception {
163159 try (Connection conn = getJdbcConnection ()) {
164160 try (Statement stmt = conn .createStatement ()) {
165- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".simpleFloats (num Float32) ENGINE = Memory " ), 0 );
161+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".simpleFloats (num Float32) ENGINE = MergeTree ORDER BY () " ), 0 );
166162 assertEquals (stmt .executeUpdate ("INSERT INTO " + getDatabase () + ".simpleFloats VALUES (1.1), (2.2), (3.3)" ), 3 );
167163 try (ResultSet rs = stmt .executeQuery ("SELECT num FROM " + getDatabase () + ".simpleFloats ORDER BY num" )) {
168164 assertTrue (rs .next ());
@@ -181,7 +177,7 @@ public void testExecuteUpdateSimpleFloats() throws Exception {
181177 public void testExecuteUpdateBooleans () throws Exception {
182178 try (Connection conn = getJdbcConnection ()) {
183179 try (Statement stmt = conn .createStatement ()) {
184- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".booleans (id UInt8, flag Boolean) ENGINE = Memory " ), 0 );
180+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".booleans (id UInt8, flag Boolean) ENGINE = MergeTree ORDER BY () " ), 0 );
185181 assertEquals (stmt .executeUpdate ("INSERT INTO " + getDatabase () + ".booleans VALUES (0, true), (1, false), (2, true)" ), 3 );
186182 try (ResultSet rs = stmt .executeQuery ("SELECT flag FROM " + getDatabase () + ".booleans ORDER BY id" )) {
187183 assertTrue (rs .next ());
@@ -200,7 +196,7 @@ public void testExecuteUpdateBooleans() throws Exception {
200196 public void testExecuteUpdateStrings () throws Exception {
201197 try (Connection conn = getJdbcConnection ()) {
202198 try (Statement stmt = conn .createStatement ()) {
203- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".strings (id UInt8, words String) ENGINE = Memory " ), 0 );
199+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".strings (id UInt8, words String) ENGINE = MergeTree ORDER BY () " ), 0 );
204200 assertEquals (stmt .executeUpdate ("INSERT INTO " + getDatabase () + ".strings VALUES (0, 'Hello'), (1, 'World'), (2, 'ClickHouse')" ), 3 );
205201 try (ResultSet rs = stmt .executeQuery ("SELECT words FROM " + getDatabase () + ".strings ORDER BY id" )) {
206202 assertTrue (rs .next ());
@@ -219,7 +215,7 @@ public void testExecuteUpdateStrings() throws Exception {
219215 public void testExecuteUpdateNulls () throws Exception {
220216 try (Connection conn = getJdbcConnection ()) {
221217 try (Statement stmt = conn .createStatement ()) {
222- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".nulls (id UInt8, nothing Nullable(String)) ENGINE = Memory " ), 0 );
218+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".nulls (id UInt8, nothing Nullable(String)) ENGINE = MergeTree ORDER BY () " ), 0 );
223219 assertEquals (stmt .executeUpdate ("INSERT INTO " + getDatabase () + ".nulls VALUES (0, 'Hello'), (1, NULL), (2, 'ClickHouse')" ), 3 );
224220 try (ResultSet rs = stmt .executeQuery ("SELECT nothing FROM " + getDatabase () + ".nulls ORDER BY id" )) {
225221 assertTrue (rs .next ());
@@ -238,7 +234,7 @@ public void testExecuteUpdateNulls() throws Exception {
238234 public void testExecuteUpdateDates () throws Exception {
239235 try (Connection conn = getJdbcConnection ()) {
240236 try (Statement stmt = conn .createStatement ()) {
241- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".dates (id UInt8, date Nullable(Date), datetime Nullable(DateTime)) ENGINE = Memory " ), 0 );
237+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".dates (id UInt8, date Nullable(Date), datetime Nullable(DateTime)) ENGINE = MergeTree ORDER BY () " ), 0 );
242238 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 );
243239 try (ResultSet rs = stmt .executeQuery ("SELECT date, datetime FROM " + getDatabase () + ".dates ORDER BY id" )) {
244240 assertTrue (rs .next ());
@@ -261,7 +257,7 @@ public void testExecuteUpdateDates() throws Exception {
261257 public void testExecuteUpdateBatch () throws Exception {
262258 try (Connection conn = getJdbcConnection ()) {
263259 try (Statement stmt = conn .createStatement ()) {
264- assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".batch (id UInt8, num UInt8) ENGINE = Memory " ), 0 );
260+ assertEquals (stmt .executeUpdate ("CREATE TABLE IF NOT EXISTS " + getDatabase () + ".batch (id UInt8, num UInt8) ENGINE = MergeTree ORDER BY () " ), 0 );
265261 stmt .addBatch ("INSERT INTO " + getDatabase () + ".batch VALUES (0, 1)" );
266262 stmt .addBatch ("INSERT INTO " + getDatabase () + ".batch VALUES (1, 2)" );
267263 stmt .addBatch ("INSERT INTO " + getDatabase () + ".batch VALUES (2, 3), (3, 4)" );
@@ -287,6 +283,9 @@ public void testExecuteUpdateBatch() throws Exception {
287283
288284 @ Test (groups = { "integration" })
289285 public void testJdbcEscapeSyntax () throws Exception {
286+ if (ClickHouseVersion .of (getServerVersion ()).check ("(,23.8]" )) {
287+ return ; // there is no `timestamp` function TODO: fix in JDBC
288+ }
290289 try (Connection conn = getJdbcConnection ()) {
291290 try (Statement stmt = conn .createStatement ()) {
292291 try (ResultSet rs = stmt .executeQuery ("SELECT {d '2021-11-01'} AS D, {ts '2021-08-01 12:34:56'} AS TS, " +
@@ -349,7 +348,7 @@ private void testSettingRole() throws SQLException {
349348
350349 List <String > roles = Arrays .asList ("role1" , "role2" );
351350
352- String userPass = "^" + RandomStringUtils .random (12 , true , true ) + "$" ;
351+ String userPass = "^1A " + RandomStringUtils .random (12 , true , true ) + "3B $" ;
353352 try (ConnectionImpl conn = (ConnectionImpl ) getJdbcConnection ()) {
354353 try (Statement stmt = conn .createStatement ()) {
355354 stmt .execute ("DROP ROLE IF EXISTS " + String .join (", " , roles ));
0 commit comments