Skip to content

Commit

Permalink
Closing Issue #1373 (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzitnik authored Jan 2, 2024
1 parent fb65981 commit 7c98c96
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public void addBatch() throws SQLException {

ClickHouseDataProcessor processor = getDataProcessor(stream, null, columns);
int nullAsDefault = getNullAsDefault();
// validate the values before the actual write into the processor
for (int i = 0, len = values.length; i < len; i++) {
if (!flags[i]) {
throw SqlExceptionUtils
Expand All @@ -341,14 +342,17 @@ public void addBatch() throws SQLException {
"Cannot set null to non-nullable column #%d [%s]", i + 1, col));
}
}
}
// the actual write to the processor
for (int i = 0, len = values.length; i < len; i++) {
ClickHouseValue val = values[i];
try {
processor.write(val);
} catch (IOException e) {
// should not happen
throw SqlExceptionUtils.handle(e);
}
}

counter++;
clearParameters();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,37 @@ public void test03Decompress() throws SQLException {
}
Assert.assertFalse(failed, String.format("Failed when content size %d", count));
}

@Test
public void testIssue1373() throws SQLException {
String httpEndpoint = "http://" + getServerAddress(ClickHouseProtocol.HTTP) + "/";
String TABLE_NAME = "issue_1373";
String url = String.format("jdbc:ch:%s", httpEndpoint);
ClickHouseDataSource dataSource = new ClickHouseDataSource(url, new Properties());
String columnNames = "event_id, num01,event_id_01 ";
String columnValues = "('event_id String, num01 Int8, event_id_01 String')";
String sql = String.format("INSERT INTO %s (%s) SELECT %s FROM input %s", TABLE_NAME, columnNames, columnNames, columnValues);
Connection conn = dataSource.getConnection("default", "");
Statement st = conn.createStatement();
st.execute(String.format("CREATE TABLE %s (`event_id` String, `num01` Int8, `event_id_01` String) ENGINE = Log", TABLE_NAME));
int count = 1;
boolean failed = false;
try (PreparedStatement ps = conn.prepareStatement(sql)) {
while (count <= 10) {
try {
ps.setString(1, "******");
ps.setInt(2, 10);
ps.setString( 3, count == 2 ? null : "--------");
ps.addBatch();
} catch (Exception e) {
//e.printStackTrace();
}
count += 1;
}
ps.executeBatch();
} catch (SQLException sqlException) {
sqlException.printStackTrace();
failed = true;
}
Assert.assertFalse(failed, String.format("executeBatch got exception"));
}
}

0 comments on commit 7c98c96

Please sign in to comment.