@@ -1521,14 +1521,14 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15211521 * Does an insert request to a server. Data is pushed when a {@link DataStreamWriter#onOutput(OutputStream)} is called.
15221522 *
15231523 * @param tableName - target table name
1524- * @param columns - list of column names to insert data into. If null or empty, all columns will be used.
1524+ * @param columnNames - list of column names to insert data into. If null or empty, all columns will be used.
15251525 * @param writer - {@link DataStreamWriter} implementation
15261526 * @param format - source format
15271527 * @param settings - operation settings
15281528 * @return {@code CompletableFuture<InsertResponse>} - a promise to insert response
15291529 */
15301530 public CompletableFuture <InsertResponse > insert (String tableName ,
1531- List <String > columns ,
1531+ List <String > columnNames ,
15321532 DataStreamWriter writer ,
15331533 ClickHouseFormat format ,
15341534 InsertSettings settings ) {
@@ -1559,20 +1559,17 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15591559 settings .setOption (ClientConfigProperties .INPUT_OUTPUT_FORMAT .getKey (), format .name ());
15601560 final InsertSettings finalSettings = settings ;
15611561
1562- StringBuilder columnString = new StringBuilder ();
1563- if (columns != null && !columns .isEmpty ()) {
1564- columnString .append ("(" );
1565- for (int i = 0 ; i < columns .size (); i ++) {
1566- columnString .append (columns .get (i ));
1567- if (i < columns .size () - 1 ) {
1568- columnString .append (", " );
1569- }
1562+ StringBuilder sqlStmt = new StringBuilder ("INSERT INTO " ).append (tableName );
1563+ if (columnNames != null && !columnNames .isEmpty ()) {
1564+ sqlStmt .append (" (" );
1565+ for (String columnName : columnNames ) {
1566+ sqlStmt .append (columnName ).append (", " );
15701567 }
1571- columnString .append (")" );
1568+ sqlStmt .deleteCharAt (sqlStmt .length () - 2 );
1569+ sqlStmt .append (")" );
15721570 }
1573-
1574- final String sqlStmt = String .format ("INSERT INTO %s %s FORMAT %s" , tableName , columnString , format .name ());
1575- finalSettings .serverSetting (ClickHouseHttpProto .QPARAM_QUERY_STMT , sqlStmt );
1571+ sqlStmt .append (" FORMAT " ).append (format .name ());
1572+ finalSettings .serverSetting (ClickHouseHttpProto .QPARAM_QUERY_STMT , sqlStmt .toString ());
15761573 responseSupplier = () -> {
15771574 long startTime = System .nanoTime ();
15781575 // Selecting some node
0 commit comments