Skip to content

Commit 65317f4

Browse files
authored
enhance insert with different types. (#2193)
1 parent 993fcdf commit 65317f4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.clickhouse.jdbc;
22

33
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
4+
import org.apache.commons.lang3.RandomStringUtils;
45
import org.testng.annotations.Ignore;
56
import org.testng.annotations.Test;
67

@@ -281,16 +282,24 @@ void testWithClause() throws Exception {
281282
@Test(groups = { "integration" })
282283
void testInsert() throws Exception {
283284
int ROWS = 100000;
285+
String payload = RandomStringUtils.random(1024, true, true);
284286
try (Connection conn = getJdbcConnection()) {
285287
for (int j = 0; j < 10; j++) {
286288
try (Statement stmt = conn.createStatement()) {
287-
stmt.execute("CREATE TABLE insert_batch (`id` UInt32, `name` String) ENGINE = Memory");
289+
stmt.execute("CREATE TABLE insert_batch ( `off16` Int16, `str` String, `p_int8` Int8, `p_int16` Int16, `p_int32` Int32, `p_int64` Int64, `p_float32` Float32, `p_float64` Float64, `p_bool` Bool) ENGINE = Memory");
288290
}
289-
String insertQuery = "INSERT INTO insert_batch (id, name) VALUES (?,?)";
291+
String insertQuery = "INSERT INTO insert_batch (off16, str, p_int8, p_int16, p_int32, p_int64, p_float32, p_float64, p_bool) VALUES (?,?,?,?,?,?,?,?,?)";
290292
try (PreparedStatement stmt = conn.prepareStatement(insertQuery)) {
291293
for (int i = 0; i < ROWS; i++) {
292-
stmt.setInt(1, i);
293-
stmt.setString(2, "name" + i);
294+
stmt.setShort(1, (short) i);
295+
stmt.setString(2, payload);
296+
stmt.setByte(3, (byte)i);
297+
stmt.setShort(4, (short)i);
298+
stmt.setInt(5, i);
299+
stmt.setLong(6, (long)i);
300+
stmt.setFloat(7, (float)(i*0.1));
301+
stmt.setDouble(8, (double)(i*0.1));
302+
stmt.setBoolean(9, true);
294303
stmt.addBatch();
295304
}
296305
long startBatchTime = System.currentTimeMillis();

0 commit comments

Comments
 (0)