@@ -331,7 +331,7 @@ func (conn *ClickhouseConn) GenerateDDL(table Table, data iop.Dataset, temporary
331331 if keyCols := data .Columns .GetKeys (iop .PrimaryKey ); len (keyCols ) > 0 {
332332 colNames := conn .GetType ().QuoteNames (keyCols .Names ()... )
333333 primaryKey = g .F ("primary key (%s)" , strings .Join (colNames , ", " ))
334- orderBy = g . F ( "(%s)" , strings .Join (colNames , ", " ) )
334+ orderBy = strings .Join (colNames , ", " )
335335 }
336336 ddl = g .R (ddl , "primary_key" , primaryKey , "order_by" , orderBy )
337337
@@ -375,17 +375,13 @@ func (conn *ClickhouseConn) BulkImportStream(tableFName string, ds *iop.Datastre
375375 // use pre-defined function
376376 err = oldOnColumnChanged (col )
377377 if err != nil {
378- return g .Error (err , "could not process ColumnChange for Postgres " )
378+ return g .Error (err , "could not process ColumnChange for Clickhouse " )
379379 }
380380
381381 return nil
382382 }
383383 }
384384
385- // keep-alive interval to prevent idle connection timeout
386- keepAliveInterval := 60 * time .Second
387- lastPushTime := time.Time {}
388-
389385 for batch := range ds .BatchChan {
390386 if batch .ColumnsChanged () || batch .IsFirst () {
391387 columns , err = conn .GetColumns (tableFName , batch .Columns .Names ()... )
@@ -446,42 +442,6 @@ func (conn *ClickhouseConn) BulkImportStream(tableFName string, ds *iop.Datastre
446442 }
447443 }
448444
449- // Start a keep-alive goroutine to prevent idle connection timeout
450- // This sends a SELECT 1 query periodically to keep the connection alive
451- // during long pauses in the data stream (e.g., slow source reads)
452- stopKeepAlive := make (chan struct {})
453- keepAliveDone := make (chan struct {})
454- go func () {
455- defer close (keepAliveDone )
456- ticker := time .NewTicker (keepAliveInterval )
457- defer ticker .Stop ()
458- for {
459- select {
460- case <- stopKeepAlive :
461- return
462- case <- ticker .C :
463- // Execute keep-alive query within the transaction context
464- // This keeps the connection from being closed due to idle timeout
465- ds .Context .Lock ()
466- if time .Since (lastPushTime ).Seconds () > keepAliveInterval .Seconds () {
467- _ , keepAliveErr := conn .Tx ().ExecContext (ds .Context .Ctx , "SELECT 1" )
468- if keepAliveErr != nil {
469- g .Debug ("keep-alive query failed: %v" , keepAliveErr )
470- } else {
471- g .Trace ("keep-alive query executed successfully" )
472- }
473- }
474- ds .Context .Unlock ()
475- }
476- }
477- }()
478-
479- // Ensure we stop the keep-alive goroutine when done
480- defer func () {
481- close (stopKeepAlive )
482- <- keepAliveDone
483- }()
484-
485445 for row := range batch .Rows {
486446 var eG g.ErrorGroup
487447
@@ -553,7 +513,6 @@ func (conn *ClickhouseConn) BulkImportStream(tableFName string, ds *iop.Datastre
553513 // Do insert
554514 ds .Context .Lock ()
555515 _ , err := stmt .Exec (row ... )
556- lastPushTime = time .Now ()
557516 ds .Context .Unlock ()
558517 if err != nil {
559518 ds .Context .CaptureErr (g .Error (err , "could not COPY into table %s" , tableFName ))
0 commit comments