Skip to content

Commit 517a0cc

Browse files
committed
fixed typos and tests
1 parent 7775fee commit 517a0cc

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public static String enquoteIdentifier(String identifier) {
6262
* @return true if the identifier needs to be quoted, false otherwise
6363
*/
6464
private static boolean needsQuoting(String identifier) {
65+
if (identifier == null) {
66+
throw new IllegalArgumentException("identifier cannot be null");
67+
}
68+
6569
if (identifier.isEmpty()) {
6670
return true;
6771
}

client-v2/src/test/java/com/clickhouse/client/api/sql/SQLUtilsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.clickhouse.client.api.sql;
22

3+
import org.apache.commons.lang3.StringUtils;
34
import org.testng.annotations.DataProvider;
45
import org.testng.annotations.Test;
56

@@ -93,7 +94,7 @@ public Object[][] simpleIdentifierTestData() {
9394
{"hello_world", true},
9495
{"Hello123", true},
9596
{"H", true}, // minimum length
96-
{"a".repeat(128), true}, // maximum length
97+
{StringUtils.repeat("a", 128), true}, // maximum length
9798

9899
// Test cases from requirements
99100
{"G'Day", false},
@@ -110,7 +111,7 @@ public Object[][] simpleIdentifierTestData() {
110111
{"test name", false}, // contains space
111112
{"test\"name", false}, // contains quote
112113
{"test.name", false}, // contains dot
113-
{"a".repeat(129), false}, // exceeds max length
114+
{StringUtils.repeat("a", 129), false}, // exceeds max length
114115
{"testName", true},
115116
{"TEST_NAME", true},
116117
{"test123", true},

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public int getMaxFieldSize() throws SQLException {
237237
@Override
238238
public void setMaxFieldSize(int max) throws SQLException {
239239
ensureOpen();
240-
if (max <= 0) {
240+
if (max < 0) {
241241
throw new SQLException("max should be a positive integer.");
242242
}
243243
this.maxFieldSize = max;
@@ -342,7 +342,7 @@ public boolean getMoreResults() throws SQLException {
342342
public void setFetchDirection(int direction) throws SQLException {
343343
ensureOpen();
344344
if (direction != ResultSet.FETCH_FORWARD && direction != ResultSet.FETCH_REVERSE && direction != ResultSet.FETCH_UNKNOWN) {
345-
throw new SQLException("Invalid fetch direction: " + direction + ". Should be one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or ResultSet.FETCH_UNKNOW");
345+
throw new SQLException("Invalid fetch direction: " + direction + ". Should be one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or ResultSet.FETCH_UNKNOWN");
346346
}
347347
}
348348

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
import static org.testng.Assert.fail;
3737

3838

39-
@Test(groups = { "integration" })
39+
@Test(groups = {"integration"})
4040
public class StatementTest extends JdbcIntegrationTest {
4141
private static final Logger log = LoggerFactory.getLogger(StatementTest.class);
4242

43-
@Test(groups = { "integration" })
43+
@Test(groups = {"integration"})
4444
public void testExecuteQuerySimpleNumbers() throws Exception {
4545
try (Connection conn = getJdbcConnection()) {
4646
try (Statement stmt = conn.createStatement()) {
@@ -59,12 +59,12 @@ public void testExecuteQuerySimpleNumbers() throws Exception {
5959
assertEquals(rs.getLong("num"), 1);
6060
assertFalse(rs.next());
6161
}
62-
Assert.assertFalse(((StatementImpl)stmt).getLastQueryId().isEmpty());
62+
Assert.assertFalse(((StatementImpl) stmt).getLastQueryId().isEmpty());
6363
}
6464
}
6565
}
6666

67-
@Test(groups = { "integration" })
67+
@Test(groups = {"integration"})
6868
public void testExecuteQuerySimpleFloats() throws Exception {
6969
try (Connection conn = getJdbcConnection()) {
7070
try (Statement stmt = conn.createStatement()) {
@@ -80,7 +80,7 @@ public void testExecuteQuerySimpleFloats() throws Exception {
8080
}
8181
}
8282

83-
@Test(groups = { "integration" })
83+
@Test(groups = {"integration"})
8484
public void testExecuteQueryBooleans() throws Exception {
8585
try (Connection conn = getJdbcConnection()) {
8686
try (Statement stmt = conn.createStatement()) {
@@ -94,7 +94,7 @@ public void testExecuteQueryBooleans() throws Exception {
9494
}
9595
}
9696

97-
@Test(groups = { "integration" })
97+
@Test(groups = {"integration"})
9898
public void testExecuteQueryStrings() throws Exception {
9999
try (Connection conn = getJdbcConnection()) {
100100
try (Statement stmt = conn.createStatement()) {
@@ -108,7 +108,7 @@ public void testExecuteQueryStrings() throws Exception {
108108
}
109109
}
110110

111-
@Test(groups = { "integration" })
111+
@Test(groups = {"integration"})
112112
public void testExecuteQueryNulls() throws Exception {
113113
try (Connection conn = getJdbcConnection()) {
114114
try (Statement stmt = conn.createStatement()) {
@@ -124,7 +124,7 @@ public void testExecuteQueryNulls() throws Exception {
124124
}
125125
}
126126

127-
@Test(groups = { "integration" })
127+
@Test(groups = {"integration"})
128128
public void testExecuteQueryDates() throws Exception {
129129
try (Connection conn = getJdbcConnection()) {
130130
try (Statement stmt = conn.createStatement()) {
@@ -144,7 +144,7 @@ public void testExecuteQueryDates() throws Exception {
144144
}
145145
}
146146

147-
@Test(groups = { "integration" })
147+
@Test(groups = {"integration"})
148148
public void testExecuteUpdateSimpleNumbers() throws Exception {
149149
try (Connection conn = getJdbcConnection()) {
150150
try (Statement stmt = conn.createStatement()) {
@@ -163,7 +163,7 @@ public void testExecuteUpdateSimpleNumbers() throws Exception {
163163
}
164164
}
165165

166-
@Test(groups = { "integration" })
166+
@Test(groups = {"integration"})
167167
public void testExecuteUpdateSimpleFloats() throws Exception {
168168
try (Connection conn = getJdbcConnection()) {
169169
try (Statement stmt = conn.createStatement()) {
@@ -183,7 +183,7 @@ public void testExecuteUpdateSimpleFloats() throws Exception {
183183
}
184184
}
185185

186-
@Test(groups = { "integration" })
186+
@Test(groups = {"integration"})
187187
public void testExecuteUpdateBooleans() throws Exception {
188188
try (Connection conn = getJdbcConnection()) {
189189
try (Statement stmt = conn.createStatement()) {
@@ -202,7 +202,7 @@ public void testExecuteUpdateBooleans() throws Exception {
202202
}
203203
}
204204

205-
@Test(groups = { "integration" })
205+
@Test(groups = {"integration"})
206206
public void testExecuteUpdateStrings() throws Exception {
207207
try (Connection conn = getJdbcConnection()) {
208208
try (Statement stmt = conn.createStatement()) {
@@ -221,7 +221,7 @@ public void testExecuteUpdateStrings() throws Exception {
221221
}
222222
}
223223

224-
@Test(groups = { "integration" })
224+
@Test(groups = {"integration"})
225225
public void testExecuteUpdateNulls() throws Exception {
226226
try (Connection conn = getJdbcConnection()) {
227227
try (Statement stmt = conn.createStatement()) {
@@ -240,7 +240,7 @@ public void testExecuteUpdateNulls() throws Exception {
240240
}
241241
}
242242

243-
@Test(groups = { "integration" })
243+
@Test(groups = {"integration"})
244244
public void testExecuteUpdateDates() throws Exception {
245245
try (Connection conn = getJdbcConnection()) {
246246
try (Statement stmt = conn.createStatement()) {
@@ -263,7 +263,7 @@ public void testExecuteUpdateDates() throws Exception {
263263
}
264264

265265

266-
@Test(groups = { "integration" })
266+
@Test(groups = {"integration"})
267267
public void testExecuteUpdateBatch() throws Exception {
268268
try (Connection conn = getJdbcConnection()) {
269269
try (Statement stmt = conn.createStatement()) {
@@ -291,7 +291,7 @@ public void testExecuteUpdateBatch() throws Exception {
291291
}
292292
}
293293

294-
@Test(groups = { "integration" })
294+
@Test(groups = {"integration"})
295295
public void testJdbcEscapeSyntax() throws Exception {
296296
if (ClickHouseVersion.of(getServerVersion()).check("(,23.8]")) {
297297
return; // there is no `timestamp` function TODO: fix in JDBC
@@ -344,7 +344,7 @@ public void testJdbcEscapeSyntax() throws Exception {
344344
}
345345
}
346346

347-
@Test(groups = { "integration" })
347+
@Test(groups = {"integration"})
348348
public void testExecuteQueryTimeout() throws Exception {
349349
try (Connection conn = getJdbcConnection()) {
350350
try (Statement stmt = conn.createStatement()) {
@@ -359,7 +359,7 @@ public void testExecuteQueryTimeout() throws Exception {
359359
}
360360

361361

362-
@Test(groups = { "integration" })
362+
@Test(groups = {"integration"})
363363
public void testSettingRole() throws SQLException {
364364
if (earlierThan(24, 4)) {//Min version is 24.4
365365
return;
@@ -445,15 +445,15 @@ public void testGettingArrays() throws Exception {
445445
Array numberArray = rs.getArray("number_array");
446446
assertEquals(((Object[]) numberArray.getArray()).length, 3);
447447
System.out.println(((Object[]) numberArray.getArray())[0].getClass().getName());
448-
assertEquals(numberArray.getArray(), new short[] {1, 2, 3} );
448+
assertEquals(numberArray.getArray(), new short[]{1, 2, 3});
449449
Array stringArray = rs.getArray("str_array");
450450
assertEquals(((Object[]) stringArray.getArray()).length, 3);
451451
assertEquals(Arrays.stream(((Object[]) stringArray.getArray())).toList(), Arrays.asList("val1", "val2", "val3"));
452452
}
453453
}
454454

455455

456-
@Test(groups = { "integration" })
456+
@Test(groups = {"integration"})
457457
public void testWithIPs() throws Exception {
458458
try (Connection conn = getJdbcConnection()) {
459459
try (Statement stmt = conn.createStatement()) {
@@ -481,14 +481,14 @@ public void testConnectionExhaustion() throws Exception {
481481

482482
try (Connection conn = getJdbcConnection(properties)) {
483483
try (Statement stmt = conn.createStatement()) {
484-
for (int i = 0; i< maxNumConnections * 2; i++) {
484+
for (int i = 0; i < maxNumConnections * 2; i++) {
485485
stmt.executeQuery("SELECT number FROM system.numbers LIMIT 100");
486486
}
487487
}
488488
}
489489
}
490490

491-
@Test(groups = { "integration" })
491+
@Test(groups = {"integration"})
492492
public void testConcurrentCancel() throws Exception {
493493
int maxNumConnections = 3;
494494
Properties p = new Properties();
@@ -524,7 +524,7 @@ public void testConcurrentCancel() throws Exception {
524524
public void testTextFormatInResponse() throws Exception {
525525
try (Connection conn = getJdbcConnection();
526526
Statement stmt = conn.createStatement()) {
527-
Assert.expectThrows(SQLException.class, () ->stmt.executeQuery("SELECT 1 FORMAT JSON"));
527+
Assert.expectThrows(SQLException.class, () -> stmt.executeQuery("SELECT 1 FORMAT JSON"));
528528
}
529529
}
530530

@@ -543,7 +543,7 @@ void testWithClause() throws Exception {
543543
assertEquals(count, 100);
544544
}
545545

546-
@Test(groups = { "integration" })
546+
@Test(groups = {"integration"})
547547
public void testSwitchDatabase() throws Exception {
548548
String databaseName = getDatabase() + "_test_switch";
549549
String createSql = "CREATE TABLE switchDatabaseWithUse (id UInt8, words String) ENGINE = MergeTree ORDER BY ()";
@@ -571,7 +571,7 @@ public void testSwitchDatabase() throws Exception {
571571
}
572572

573573

574-
@Test(groups = { "integration" })
574+
@Test(groups = {"integration"})
575575
public void testNewLineSQLParsing() throws Exception {
576576
try (Connection conn = getJdbcConnection()) {
577577
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;";
@@ -636,20 +636,20 @@ public void testNewLineSQLParsing() throws Exception {
636636
}
637637

638638

639-
@Test(groups = { "integration" })
639+
@Test(groups = {"integration"})
640640
public void testNullableFixedStringType() throws Exception {
641641
try (Connection conn = getJdbcConnection()) {
642642
String sqlCreate = "CREATE TABLE `data_types` (`f1` FixedString(4),`f2` LowCardinality(FixedString(4)), `f3` Nullable(FixedString(4)), `f4` LowCardinality(Nullable(FixedString(4))) ) ENGINE Memory;";
643643
try (Statement stmt = conn.createStatement()) {
644644
int r = stmt.executeUpdate(sqlCreate);
645645
assertEquals(r, 0);
646646
}
647-
try(Statement stmt = conn.createStatement()) {
647+
try (Statement stmt = conn.createStatement()) {
648648
String sqlInsert = "INSERT INTO `data_types` VALUES ('val1', 'val2', 'val3', 'val4')";
649649
int r = stmt.executeUpdate(sqlInsert);
650650
assertEquals(r, 1);
651651
}
652-
try(Statement stmt = conn.createStatement()) {
652+
try (Statement stmt = conn.createStatement()) {
653653
String sqlSelect = "SELECT * FROM `data_types`";
654654
ResultSet rs = stmt.executeQuery(sqlSelect);
655655
assertTrue(rs.next());
@@ -659,7 +659,7 @@ public void testNullableFixedStringType() throws Exception {
659659
assertEquals(rs.getString(4), "val4");
660660
assertFalse(rs.next());
661661
}
662-
try(Statement stmt = conn.createStatement()) {
662+
try (Statement stmt = conn.createStatement()) {
663663
String sqlSelect = "SELECT f4 FROM `data_types`";
664664
ResultSet rs = stmt.executeQuery(sqlSelect);
665665
assertTrue(rs.next());
@@ -668,7 +668,7 @@ public void testNullableFixedStringType() throws Exception {
668668
}
669669
}
670670

671-
@Test(groups = { "integration" })
671+
@Test(groups = {"integration"})
672672
public void testWasNullFlagArray() throws Exception {
673673
try (Connection conn = getJdbcConnection()) {
674674
String sql = "SELECT NULL, ['value1', 'value2']";
@@ -707,7 +707,7 @@ public void testWasNullFlagArray() throws Exception {
707707
}
708708
}
709709

710-
@Test(groups = { "integration" })
710+
@Test(groups = {"integration"})
711711
public void testExecuteWithMaxRows() throws Exception {
712712
try (Connection conn = getJdbcConnection()) {
713713
try (Statement stmt = conn.createStatement()) {
@@ -734,7 +734,7 @@ public void testExecuteWithMaxRows() throws Exception {
734734
ServerSettings.RESULT_OVERFLOW_MODE_THROW);
735735
props.setProperty(ClientConfigProperties.serverSetting(ServerSettings.MAX_RESULT_ROWS), "100");
736736
try (Connection conn = getJdbcConnection(props);
737-
Statement stmt = conn.createStatement()) {
737+
Statement stmt = conn.createStatement()) {
738738

739739
Assert.assertThrows(SQLException.class, () -> stmt.execute("SELECT * FROM generate_series(0, 100000)"));
740740

@@ -770,7 +770,7 @@ public void testDDLStatements() throws Exception {
770770
return; // skip because we do not want to create extra on cloud instance
771771
}
772772
try (Connection conn = getJdbcConnection()) {
773-
try (Statement stmt = conn.createStatement()){
773+
try (Statement stmt = conn.createStatement()) {
774774
Assert.assertFalse(stmt.execute("CREATE USER IF NOT EXISTS 'user011' IDENTIFIED BY 'password'"));
775775

776776
try (ResultSet rs = stmt.executeQuery("SHOW USERS")) {
@@ -804,14 +804,14 @@ public void testEnquoteIdentifier() throws Exception {
804804
try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) {
805805
Object[][] identifiers = {{"simple_identifier", false}, {"complex identified", true}};
806806
for (Object[] aCase : identifiers) {
807-
stmt.enquoteIdentifier((String)aCase[0], (boolean) aCase[1]);
807+
stmt.enquoteIdentifier((String) aCase[0], (boolean) aCase[1]);
808808
}
809809
}
810810
}
811811

812812
@DataProvider(name = "ncharLiteralTestData")
813813
public Object[][] ncharLiteralTestData() {
814-
return new Object[][] {
814+
return new Object[][]{
815815
// input, expected output
816816
{"test", "N'test'"},
817817
{"O'Reilly", "N'O''Reilly'"},
@@ -839,7 +839,7 @@ public void testEnquoteNCharLiteral_NullInput() throws SQLException {
839839

840840
@Test(groups = {"integration"})
841841
public void testIsSimpleIdentifier() throws Exception {
842-
Object[][] identifiers = new Object[][] {
842+
Object[][] identifiers = new Object[][]{
843843
// identifier, expected result
844844
{"Hello", true},
845845
{"hello_world", true},
@@ -928,7 +928,7 @@ public void testCloseOnCompletion() throws Exception {
928928
try (Statement stmt = conn.createStatement()) {
929929
stmt.closeOnCompletion();
930930
try (ResultSet rs = stmt.executeQuery("CREATE TABLE test_empty_table (id String) Engine Memory")) {
931-
}catch (Exception ex){
931+
} catch (Exception ex) {
932932
ex.printStackTrace();
933933
}
934934

0 commit comments

Comments
 (0)