Skip to content

Commit

Permalink
Merge pull request #2059 from ClickHouse/client_v2_fix_table_name
Browse files Browse the repository at this point in the history
[client-v2] Fix table name wrapping in insert statement
  • Loading branch information
chernser authored Dec 31, 2024
2 parents ca81ec7 + a5fc84a commit 33b1fad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,

settings.setOption(ClientConfigProperties.INPUT_OUTPUT_FORMAT.getKey(), format.name());
final InsertSettings finalSettings = settings;
final String sqlStmt = "INSERT INTO \"" + tableName + "\" FORMAT " + format.name();
final String sqlStmt = "INSERT INTO " + tableName + " FORMAT " + format.name();
finalSettings.serverSetting(ClickHouseHttpProto.QPARAM_QUERY_STMT, sqlStmt);
responseSupplier = () -> {
// Selecting some node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,9 @@ public void insertRawData() throws Exception {
assertEquals(records.size(), 1000);
}

@Test(groups = { "integration" }, enabled = true)
public void insertRawDataSimple() throws Exception {
insertRawDataSimple(1000);
}
public void insertRawDataSimple(int numberOfRecords) throws Exception {
final String tableName = "raw_data_table";
@Test(groups = { "integration" }, dataProvider = "insertRawDataSimpleDataProvider", dataProviderClass = InsertTests.class)
public void insertRawDataSimple(String tableName) throws Exception {
// final String tableName = "raw_data_table";
final String createSql = String.format("CREATE TABLE IF NOT EXISTS %s " +
" (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()", tableName);

Expand All @@ -271,6 +268,7 @@ public void insertRawDataSimple(int numberOfRecords) throws Exception {
.setInputStreamCopyBufferSize(8198 * 2);
ByteArrayOutputStream data = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(data);
int numberOfRecords = 1000;
for (int i = 0; i < numberOfRecords; i++) {
writer.printf("%d\t%s\t%s\t%d\t%s\n", i, "2021-01-01 00:00:00", "name" + i, i, "p2");
}
Expand All @@ -281,6 +279,15 @@ public void insertRawDataSimple(int numberOfRecords) throws Exception {
assertEquals((int)response.getWrittenRows(), numberOfRecords );
}

@DataProvider(name = "insertRawDataSimpleDataProvider")
public static Object[][] insertRawDataSimpleDataProvider() {
return new Object[][] {
{"raw_data_table"},
{"`raw_data_table`"},
{"`" + ClickHouseServerForTest.getDatabase() + ".raw_data_table`"},
};
}

@Test(groups = { "integration" })
public void testInsertMetricsOperationId() throws Exception {
final String tableName = "insert_metrics_test";
Expand Down

0 comments on commit 33b1fad

Please sign in to comment.