Repository: mailru/go-clickhouse
Pull request #96 (2020-04-29 09:56:07)

UUID updates


Patch:
diff --git a/.travis.yml b/.travis.yml
index 270e721..fe76471 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,7 @@ services:
   - docker
 
 before_install:
-  - travis_retry docker pull yandex/clickhouse-server:19.16.14.65
+  - travis_retry docker pull yandex/clickhouse-server:20.3.8.53
   - make up_docker_server
 
 install:
diff --git a/Makefile b/Makefile
index 108f5f1..76cd47e 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ init:
 	GO111MODULE=off go get golang.org/x/lint/golint
 
 up_docker_server: stop_docker_server
-	docker run --rm=true -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server:19.16.14.65;
+	docker run --rm=true -p 127.0.0.1:8123:8123 --name dbr-clickhouse-server -d yandex/clickhouse-server:20.3.8.53;
 
 stop_docker_server:
 	test -n "$$(docker ps --format {{.Names}} | grep dbr-clickhouse-server)" && docker stop dbr-clickhouse-server || true
diff --git a/conn.go b/conn.go
index cfe6a4f..14cd991 100644
--- a/conn.go
+++ b/conn.go
@@ -16,7 +16,7 @@ import (
 	"sync/atomic"
 	"time"
 
-	uuid "github.com/satori/go.uuid"
+	"github.com/gofrs/uuid"
 )
 
 type key int
@@ -313,7 +313,12 @@ func (c *conn) buildRequest(ctx context.Context, query string, params []driver.V
 	}
 
 	if c.killQueryOnErr && queryID == "" {
-		queryID = uuid.NewV4().String()
+		queryUUID, err := uuid.NewV4()
+		if err != nil {
+			c.log("can't generate query_id: ", err)
+		} else {
+			queryID = queryUUID.String()
+		}
 	}
 
 	reqQuery := req.URL.Query()
diff --git a/go.mod b/go.mod
index d976264..1db4313 100644
--- a/go.mod
+++ b/go.mod
@@ -1,7 +1,7 @@
 module github.com/mailru/go-clickhouse
 
 require (
-	github.com/satori/go.uuid v1.1.0
+	github.com/gofrs/uuid v3.2.0+incompatible
 	github.com/stretchr/testify v1.3.0
 )
 
diff --git a/go.sum b/go.sum
index b968373..82c010b 100644
--- a/go.sum
+++ b/go.sum
@@ -1,9 +1,9 @@
 github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
+github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/satori/go.uuid v1.1.0 h1:B9KXyj+GzIpJbV7gmr873NsY6zpbxNy24CBtGrk7jHo=
-github.com/satori/go.uuid v1.1.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
 github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=


Test patch:
diff --git a/conn_test.go b/conn_test.go
index 49c7f72..04963f8 100644
--- a/conn_test.go
+++ b/conn_test.go
@@ -4,12 +4,11 @@ import (
 	"context"
 	"database/sql"
 	"database/sql/driver"
-	"fmt"
 	"net/http"
 	"testing"
 	"time"
 
-	uuid "github.com/satori/go.uuid"
+	"github.com/gofrs/uuid"
 	"github.com/stretchr/testify/suite"
 )
 
@@ -177,18 +176,29 @@ func (s *connSuite) TestServerError() {
 }
 
 func (s *connSuite) TestServerKillQuery() {
-	queryID := uuid.NewV4().String()
-	_, err := s.connWithKillQuery.QueryContext(context.Background(), "SELECT sleep(2)")
+	// kill query and check if it is cancelled
+	queryUUID, err := uuid.NewV4()
+	s.Require().NoError(err)
+	queryID := queryUUID.String()
+	_, err = s.connWithKillQuery.QueryContext(context.WithValue(context.Background(), QueryID, queryID), "SELECT sleep(3)")
 	s.Error(err)
 	s.Contains(err.Error(), "net/http: timeout awaiting response headers")
-	rows := s.connWithKillQuery.QueryRow(fmt.Sprintf("SELECT count(query_id) FROM system.processes where query_id='%s'", queryID))
+	rows := s.connWithKillQuery.QueryRow("SELECT count(query_id) FROM system.processes where query_id=? and is_cancelled=?", queryID, 1)
 	var amount int
 	err = rows.Scan(&amount)
 	s.NoError(err)
-	s.Equal(0, amount)
+	s.Equal(1, amount)
 
-	_, err = s.connWithKillQuery.QueryContext(context.Background(), "SELECT sleep(0.5)")
+	// not kill query and check if it is not cancelled
+	queryUUID, err = uuid.NewV4()
+	s.Require().NoError(err)
+	queryID = queryUUID.String()
+	_, err = s.connWithKillQuery.QueryContext(context.WithValue(context.Background(), QueryID, queryID), "SELECT sleep(0.5)")
 	s.NoError(err)
+	rows = s.connWithKillQuery.QueryRow("SELECT count(query_id) FROM system.processes where query_id=? and is_cancelled=?", queryID, 0)
+	err = rows.Scan(&amount)
+	s.NoError(err)
+	s.Equal(0, amount)
 
 	_, err = s.conn.QueryContext(context.Background(), "SELECT sleep(2)")
 	s.NoError(err)