diff --git a/conn.go b/conn.go index e32bf6cc32..785bde05ef 100644 --- a/conn.go +++ b/conn.go @@ -21,6 +21,7 @@ import ( "context" "crypto/tls" "fmt" + "github.com/ClickHouse/clickhouse-go/v2/resources" "github.com/pkg/errors" "log" "net" @@ -68,6 +69,7 @@ func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, er return nil, fmt.Errorf("unsupported compression method for native protocol") } } + var ( connect = &connect{ opt: opt, @@ -87,6 +89,13 @@ func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, er if err := connect.handshake(opt.Auth.Database, opt.Auth.Username, opt.Auth.Password); err != nil { return nil, err } + + // warn only on the first connection in the pool + if num == 1 && !resources.ClientMeta.IsSupportedClickHouseVersion(connect.server.Version) { + // send to debugger and console + fmt.Printf("WARNING: version %v of ClickHouse is not supported by this client\n", connect.server.Version) + debugf("[handshake] WARNING: version %v of ClickHouse is not supported by this client - client supports %v", connect.server.Version, resources.ClientMeta.SupportedVersions()) + } return connect, nil } diff --git a/conn_handshake.go b/conn_handshake.go index 695703c974..a476bdba09 100644 --- a/conn_handshake.go +++ b/conn_handshake.go @@ -18,6 +18,7 @@ package clickhouse import ( + _ "embed" "fmt" "time" @@ -67,6 +68,7 @@ func (c *connect) handshake(database, username, password string) error { if c.server.Revision < proto.DBMS_MIN_REVISION_WITH_CLIENT_INFO { return ErrUnsupportedServerRevision } + if c.revision > c.server.Revision { c.revision = c.server.Revision c.debugf("[handshake] downgrade client proto") diff --git a/conn_http.go b/conn_http.go index 0ca16f7503..e547c05fb8 100644 --- a/conn_http.go +++ b/conn_http.go @@ -25,6 +25,7 @@ import ( "context" "database/sql/driver" "fmt" + "github.com/ClickHouse/clickhouse-go/v2/resources" "io" "io/ioutil" "net" @@ -205,6 +206,15 @@ func dialHttp(ctx context.Context, addr string, num int, opt *Options) (*httpCon if err != nil { return nil, err } + if num == 1 { + version, err := conn.readVersion(ctx) + if err != nil { + return nil, err + } + if !resources.ClientMeta.IsSupportedClickHouseVersion(version) { + fmt.Printf("WARNING: version %v of ClickHouse is not supported by this client\n", version) + } + } return &httpConnect{ client: &http.Client{ @@ -256,6 +266,23 @@ func (h *httpConnect) readTimeZone(ctx context.Context) (*time.Location, error) return nil, errors.New("unable to determine server timezone") } +func (h *httpConnect) readVersion(ctx context.Context) (proto.Version, error) { + rows, err := h.query(ctx, func(*connect, error) {}, "SELECT version()") + if err != nil { + return proto.Version{}, err + } + for rows.Next() { + var v string + rows.Scan(&v) + version, err := proto.ParseVersion(v) + if err != nil { + return proto.Version{}, err + } + return version, nil + } + return proto.Version{}, errors.New("unable to determine version") +} + func createCompressionPool(compression *Compression) (Pool[HTTPReaderWriter], error) { pool := NewPool(func() HTTPReaderWriter { switch compression.Method { @@ -347,18 +374,31 @@ func (h *httpConnect) sendQuery(ctx context.Context, r io.Reader, options *Query return res, nil } -func readResponse(response *http.Response) ([]byte, error) { - var result []byte - if response.ContentLength > 0 { - result = make([]byte, 0, response.ContentLength) - } - buf := bytes.NewBuffer(result) +func (h *httpConnect) readRawResponse(response *http.Response) (body []byte, err error) { + rw := h.compressionPool.Get() defer response.Body.Close() - _, err := buf.ReadFrom(response.Body) - if err != nil { + defer h.compressionPool.Put(rw) + if body, err = rw.read(response); err != nil { return nil, err } - return buf.Bytes(), nil + if h.compression == CompressionLZ4 || h.compression == CompressionZSTD { + result := make([]byte, len(body)) + reader := chproto.NewReader(bytes.NewReader(body)) + reader.EnableCompression() + defer reader.DisableCompression() + for { + b, err := reader.ReadByte() + if err != nil { + if errors.Is(err, io.EOF) { + break + } + return nil, err + } + result = append(result, b) + } + return result, nil + } + return body, nil } func (h *httpConnect) prepareRequest(ctx context.Context, reader io.Reader, options *QueryOptions, headers map[string]string) (*http.Request, error) { @@ -402,7 +442,8 @@ func (h *httpConnect) executeRequest(req *http.Request) (*http.Response, error) return nil, err } if resp.StatusCode != http.StatusOK { - msg, err := readResponse(resp) + + msg, err := h.readRawResponse(resp) if err != nil { return nil, errors.Wrap(err, "clickhouse [execute]:: failed to read the response") diff --git a/examples/clickhouse_api/async.go b/examples/clickhouse_api/async.go index 935b7fb7b5..414f1b1c37 100644 --- a/examples/clickhouse_api/async.go +++ b/examples/clickhouse_api/async.go @@ -29,7 +29,7 @@ func AsyncInsert() error { return err } ctx := context.Background() - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { + if !clickhouse_tests.CheckMinServerServerVersion(conn, 21, 12, 0) { return nil } defer func() { diff --git a/examples/clickhouse_api/context.go b/examples/clickhouse_api/context.go index dd83d7d78d..f3f405115f 100644 --- a/examples/clickhouse_api/context.go +++ b/examples/clickhouse_api/context.go @@ -49,7 +49,7 @@ func UseContext() error { if err != nil { return err } - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1); err != nil { + if !clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1) { return nil } // we can use context to pass settings to a specific API call diff --git a/examples/clickhouse_api/json.go b/examples/clickhouse_api/json.go index 2717bca824..5221288754 100644 --- a/examples/clickhouse_api/json.go +++ b/examples/clickhouse_api/json.go @@ -32,7 +32,7 @@ func InsertReadJSON() error { return err } ctx := context.Background() - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1); err != nil { + if !clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1) { return nil } if err != nil { @@ -108,7 +108,7 @@ func ReadComplexJSON() error { } ctx := context.Background() - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1); err != nil { + if !clickhouse_tests.CheckMinServerServerVersion(conn, 22, 6, 1) { return nil } conn.Exec(ctx, "DROP TABLE IF EXISTS example") diff --git a/examples/std/context.go b/examples/std/context.go index 8ad3ee8672..c27b9377ef 100644 --- a/examples/std/context.go +++ b/examples/std/context.go @@ -14,7 +14,7 @@ func UseContext() error { if err != nil { return err } - if err := clickhouse_tests.CheckMinServerVersion(conn, 22, 6, 1); err != nil { + if !clickhouse_tests.CheckMinServerVersion(conn, 22, 6, 1) { return nil } // we can use context to pass settings to a specific API call diff --git a/examples/std/json.go b/examples/std/json.go index ad7410375a..f65825bd0a 100644 --- a/examples/std/json.go +++ b/examples/std/json.go @@ -45,7 +45,7 @@ func JSONInsertRead() error { if err != nil { return err } - if err := std.CheckMinServerVersion(conn, 22, 6, 1); err != nil { + if !std.CheckMinServerVersion(conn, 22, 6, 1) { return nil } conn.Exec("DROP TABLE example") diff --git a/go.mod b/go.mod index fb79a6346b..9f591315a2 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/docker/docker v20.10.20+incompatible github.com/docker/go-connections v0.4.0 github.com/docker/go-units v0.5.0 + github.com/ghodss/yaml v1.0.0 github.com/google/uuid v1.3.0 github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615 github.com/paulmach/orb v0.7.1 @@ -62,5 +63,6 @@ require ( google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad // indirect google.golang.org/grpc v1.47.0 // indirect google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index bb10fed0e5..25e00a9794 100644 --- a/go.sum +++ b/go.sum @@ -375,6 +375,7 @@ github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXt github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw= github.com/go-faster/city v1.0.1/go.mod h1:jKcUJId49qdW3L1qKHH/3wPeUstCVpVSXTM6vO3VcTw= @@ -1476,6 +1477,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/lib/proto/handshake.go b/lib/proto/handshake.go index b57cc76d76..61c3bfefac 100644 --- a/lib/proto/handshake.go +++ b/lib/proto/handshake.go @@ -20,6 +20,9 @@ package proto import ( "fmt" chproto "github.com/ClickHouse/ch-go/proto" + "gopkg.in/yaml.v3" + "strconv" + "strings" "time" "github.com/ClickHouse/clickhouse-go/v2/lib/timezone" @@ -50,12 +53,38 @@ type ServerHandshake struct { Name string DisplayName string Revision uint64 - Version struct { - Major uint64 - Minor uint64 - Patch uint64 + Version Version + Timezone *time.Location +} + +type Version struct { + Major uint64 + Minor uint64 + Patch uint64 +} + +func ParseVersion(v string) (ver Version, err error) { + parts := strings.Split(v, ".") + if len(parts) < 3 { + return Version{}, fmt.Errorf("%s is not a valid version", v) + } + if ver.Major, err = strconv.ParseUint(parts[0], 10, 8); err != nil { + return Version{}, err + } + if ver.Minor, err = strconv.ParseUint(parts[1], 10, 8); err != nil { + return Version{}, err + } + if ver.Patch, err = strconv.ParseUint(parts[2], 10, 8); err != nil { + return Version{}, err + } + return ver, nil +} + +func CheckMinVersion(constraint Version, version Version) bool { + if version.Major < constraint.Major || (version.Major == constraint.Major && version.Minor < constraint.Minor) || (version.Major == constraint.Major && version.Minor == constraint.Minor && version.Patch < constraint.Patch) { + return false } - Timezone *time.Location + return true } func (srv *ServerHandshake) Decode(reader *chproto.Reader) (err error) { @@ -104,3 +133,35 @@ func (srv ServerHandshake) String() string { srv.Timezone, ) } + +func (v Version) String() string { + return fmt.Sprintf("%d.%d.%d", + v.Major, + v.Minor, + v.Patch, + ) +} + +func (v *Version) UnmarshalYAML(value *yaml.Node) (err error) { + versions := strings.Split(value.Value, ".") + if len(versions) < 1 || len(versions) > 3 { + return fmt.Errorf("%s is not a valid version", value.Value) + } + for i := range versions { + switch i { + case 0: + if v.Major, err = strconv.ParseUint(versions[i], 10, 8); err != nil { + return err + } + case 1: + if v.Minor, err = strconv.ParseUint(versions[i], 10, 8); err != nil { + return err + } + case 2: + if v.Patch, err = strconv.ParseUint(versions[i], 10, 8); err != nil { + return err + } + } + } + return nil +} diff --git a/resources/meta.go b/resources/meta.go new file mode 100644 index 0000000000..1173690257 --- /dev/null +++ b/resources/meta.go @@ -0,0 +1,78 @@ +// Licensed to ClickHouse, Inc. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. ClickHouse, Inc. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package resources + +import ( + _ "embed" + "github.com/ClickHouse/clickhouse-go/v2/lib/proto" + "gopkg.in/yaml.v3" + "strings" +) + +type Meta struct { + ClickhouseVersions []proto.Version `yaml:"clickhouse_versions"` + GoVersions []proto.Version `yaml:"go_versions"` + hVersion proto.Version +} + +//go:embed meta.yml +var metaFile []byte +var ClientMeta Meta + +func init() { + if err := yaml.Unmarshal(metaFile, &ClientMeta); err != nil { + panic(err) + } + ClientMeta.hVersion = ClientMeta.findGreatestVersion() +} + +func (m *Meta) IsSupportedClickHouseVersion(v proto.Version) bool { + for _, version := range m.ClickhouseVersions { + if version.Major == v.Major && version.Minor == v.Minor { + // check our patch is greater + return v.Patch >= version.Patch + } + } + return proto.CheckMinVersion(m.hVersion, v) +} + +func (m *Meta) SupportedVersions() string { + versions := make([]string, len(m.ClickhouseVersions), len(m.ClickhouseVersions)) + for i := range m.ClickhouseVersions { + versions[i] = m.ClickhouseVersions[i].String() + } + return strings.Join(versions, ", ") +} + +func (m *Meta) findGreatestVersion() proto.Version { + var maxVersion proto.Version + for _, version := range m.ClickhouseVersions { + if version.Major > maxVersion.Major { + maxVersion = version + } else if version.Major == maxVersion.Major { + if version.Minor > maxVersion.Minor { + maxVersion = version + } else if version.Minor == maxVersion.Minor { + if version.Patch > maxVersion.Patch { + maxVersion = version + } + } + } + } + return maxVersion +} diff --git a/resources/meta.yml b/resources/meta.yml new file mode 100644 index 0000000000..0c4753b8ed --- /dev/null +++ b/resources/meta.yml @@ -0,0 +1,8 @@ +clickhouse_versions: + - 22.3 + - 22.7 + - 22.8 + - 22.9 +go_versions: + - 1.18 + - 1.19 diff --git a/resources/meta_test.go b/resources/meta_test.go new file mode 100644 index 0000000000..b5973f0ea5 --- /dev/null +++ b/resources/meta_test.go @@ -0,0 +1,103 @@ +// Licensed to ClickHouse, Inc. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. ClickHouse, Inc. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package resources + +import ( + "github.com/ClickHouse/clickhouse-go/v2/lib/proto" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +var m Meta = Meta{ + ClickhouseVersions: []proto.Version{ + { + Major: 21, + Minor: 3, + Patch: 0, + }, + { + Major: 21, + Minor: 8, + Patch: 0, + }, + { + Major: 22, + Minor: 5, + Patch: 5, + }, + { + Major: 22, + Minor: 6, + Patch: 6, + }, + { + Major: 22, + Minor: 7, + Patch: 8, + }, + }, +} + +func TestFindGreatestVersion(t *testing.T) { + assert.Equal(t, proto.Version{ + Major: 22, + Minor: 7, + Patch: 8, + }, m.findGreatestVersion()) +} + +func TestSupportedVersions(t *testing.T) { + assert.Equal(t, "21.3.0, 21.8.0, 22.5.5, 22.6.6, 22.7.8", m.SupportedVersions()) +} + +func TestIsSupportedClickHouseVersion(t *testing.T) { + m.hVersion = m.findGreatestVersion() + require.True(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 22, + Minor: 5, + Patch: 6, + })) + require.True(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 22, + Minor: 5, + Patch: 8, + })) + require.True(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 22, + Minor: 6, + Patch: 7, + })) + require.True(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 21, + Minor: 3, + Patch: 0, + })) + + require.False(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 22, + Minor: 6, + Patch: 1, + })) + + require.False(t, m.IsSupportedClickHouseVersion(proto.Version{ + Major: 22, + Minor: 4, + Patch: 1, + })) +} diff --git a/tests/base_types_test.go b/tests/base_types_test.go index 8ace8327fd..38e250f15d 100644 --- a/tests/base_types_test.go +++ b/tests/base_types_test.go @@ -20,6 +20,7 @@ package tests import ( "context" "database/sql" + "fmt" "github.com/stretchr/testify/require" "testing" @@ -157,8 +158,8 @@ func TestSimpleInt(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_int (`1` Int64) Engine MergeTree() ORDER BY tuple()" @@ -177,8 +178,8 @@ func TestNullableInt(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_int (col1 Int64, col2 Nullable(Int64), col3 Int32, col4 Nullable(Int32), col5 Int16, col6 Nullable(Int16)) Engine MergeTree() ORDER BY tuple()" diff --git a/tests/bigint_test.go b/tests/bigint_test.go index 5d94ba46b2..b15c2368ab 100644 --- a/tests/bigint_test.go +++ b/tests/bigint_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "math/big" "testing" @@ -33,8 +34,8 @@ func TestSimpleBigInt(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -66,8 +67,8 @@ func TestBigInt(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -136,8 +137,8 @@ func TestNullableBigInt(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/bool_test.go b/tests/bool_test.go index 797f332b64..e754e1c386 100644 --- a/tests/bool_test.go +++ b/tests/bool_test.go @@ -20,6 +20,7 @@ package tests import ( "context" "database/sql" + "fmt" "github.com/ClickHouse/clickhouse-go/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -34,8 +35,8 @@ func TestBool(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -95,8 +96,8 @@ func TestColumnarBool(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/date32_test.go b/tests/date32_test.go index 8359e7446a..f5ea6deba0 100644 --- a/tests/date32_test.go +++ b/tests/date32_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" "time" @@ -34,8 +35,8 @@ func TestDate32(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -135,8 +136,8 @@ func TestNullableDate32(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -192,8 +193,8 @@ func TestColumnarDate32(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -263,8 +264,8 @@ func TestDate32Flush(t *testing.T) { Method: clickhouse.CompressionLZ4, }) ctx := context.Background() - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } require.NoError(t, err) diff --git a/tests/datetime64_test.go b/tests/datetime64_test.go index 775500800e..2dc11e0c23 100644 --- a/tests/datetime64_test.go +++ b/tests/datetime64_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" "time" @@ -33,8 +34,8 @@ func TestDateTime64(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -116,8 +117,8 @@ func TestDateTime64AsReference(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -155,8 +156,8 @@ func TestNullableDateTime64(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -242,8 +243,8 @@ func TestColumnarDateTime64(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/ddl_test.go b/tests/ddl_test.go index d44a9a4af9..575eb9a464 100644 --- a/tests/ddl_test.go +++ b/tests/ddl_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/ClickHouse/clickhouse-go/v2" "github.com/stretchr/testify/require" "testing" @@ -31,8 +32,8 @@ func TestQuotedDDL(t *testing.T) { ctx := context.Background() require.NoError(t, err) require.NoError(t, conn.Ping(ctx)) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE `test_string` (`1` String) Engine MergeTree() ORDER BY tuple()" diff --git a/tests/decimal_test.go b/tests/decimal_test.go index ab77d91233..99126fa265 100644 --- a/tests/decimal_test.go +++ b/tests/decimal_test.go @@ -35,8 +35,8 @@ func TestDecimal(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -97,8 +97,8 @@ func TestNegativeDecimal(t *testing.T) { defer func() { conn.Exec(ctx, "DROP TABLE IF EXISTS test_decimal") }() - if err := CheckMinServerServerVersion(conn, 21, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } require.NoError(t, conn.Exec(ctx, ddl)) @@ -130,8 +130,8 @@ func TestNullableDecimal(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/float_test.go b/tests/float_test.go index be94bbb503..02f2330b2c 100644 --- a/tests/float_test.go +++ b/tests/float_test.go @@ -3,6 +3,7 @@ package tests import ( "context" "database/sql" + "fmt" "github.com/stretchr/testify/require" "math/rand" "testing" @@ -17,8 +18,8 @@ func TestSimpleFloat(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/geo_multipolygon_test.go b/tests/geo_multipolygon_test.go index d5a15c9ef4..199fbe029b 100644 --- a/tests/geo_multipolygon_test.go +++ b/tests/geo_multipolygon_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "math/rand" "testing" @@ -36,8 +37,8 @@ func TestGeoMultiPolygon(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -141,8 +142,8 @@ func TestGeoMultiPolygonFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/geo_point_test.go b/tests/geo_point_test.go index ae15d2ceb0..e659b1a360 100644 --- a/tests/geo_point_test.go +++ b/tests/geo_point_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "math/rand" "testing" @@ -36,8 +37,8 @@ func TestGeoPoint(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -80,8 +81,8 @@ func TestGeoPointFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/geo_polygon_test.go b/tests/geo_polygon_test.go index 85444e2de5..b9c079b9ab 100644 --- a/tests/geo_polygon_test.go +++ b/tests/geo_polygon_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "math/rand" "testing" @@ -36,8 +37,8 @@ func TestGeoPolygon(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -105,8 +106,8 @@ func TestGeoPolygonFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/geo_ring_test.go b/tests/geo_ring_test.go index d413f22885..691ce7dc6f 100644 --- a/tests/geo_ring_test.go +++ b/tests/geo_ring_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" @@ -35,8 +36,8 @@ func TestGeoRing(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -86,8 +87,8 @@ func TestGeoRingFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/issues/389_test.go b/tests/issues/389_test.go index 525d7910a3..2febd14afb 100644 --- a/tests/issues/389_test.go +++ b/tests/issues/389_test.go @@ -19,6 +19,7 @@ package issues import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" "time" @@ -36,8 +37,8 @@ func TestIssue389(t *testing.T) { }) ) require.NoError(t, err) - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !clickhouse_tests.CheckMinServerServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/issues/406_test.go b/tests/issues/406_test.go index 5ddd054653..e186d24522 100644 --- a/tests/issues/406_test.go +++ b/tests/issues/406_test.go @@ -19,6 +19,7 @@ package issues import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" @@ -35,8 +36,8 @@ func TestIssue406(t *testing.T) { }) ) require.NoError(t, err) - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !clickhouse_tests.CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/issues/412_test.go b/tests/issues/412_test.go index 45378bd525..4f024c470b 100644 --- a/tests/issues/412_test.go +++ b/tests/issues/412_test.go @@ -19,6 +19,7 @@ package issues import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" "time" @@ -36,8 +37,8 @@ func TestIssue412(t *testing.T) { }) ) require.NoError(t, err) - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !clickhouse_tests.CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/issues/615_test.go b/tests/issues/615_test.go index 3907b9aa08..26cd0e4cc4 100644 --- a/tests/issues/615_test.go +++ b/tests/issues/615_test.go @@ -2,6 +2,7 @@ package issues import ( "context" + "fmt" "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/assert" @@ -19,8 +20,8 @@ func TestIssue615(t *testing.T) { }) ) require.NoError(t, err) - if err := clickhouse_tests.CheckMinServerServerVersion(conn, 22, 0, 0); err != nil { - t.Skip(err.Error()) + if !clickhouse_tests.CheckMinServerServerVersion(conn, 22, 0, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) } require.NoError(t, err) if err := conn.Exec( diff --git a/tests/issues/692_test.go b/tests/issues/692_test.go index e838caaacf..ddf2c97fc6 100644 --- a/tests/issues/692_test.go +++ b/tests/issues/692_test.go @@ -1,6 +1,7 @@ package issues import ( + "fmt" "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/ClickHouse/clickhouse-go/v2/tests/std" @@ -16,8 +17,8 @@ func TestIssue692(t *testing.T) { require.NoError(t, err) conn, err := clickhouse_std_tests.GetDSNConnection("issues", clickhouse.Native, useSSL, "false") require.NoError(t, err) - if err := std.CheckMinServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !std.CheckMinServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/json_test.go b/tests/json_test.go index be60a652e1..94c93c8a6a 100644 --- a/tests/json_test.go +++ b/tests/json_test.go @@ -60,8 +60,8 @@ func setupConnection(t *testing.T) driver.Conn { func setupTest(t *testing.T) (driver.Conn, func(t *testing.T)) { ctx := context.Background() conn := setupConnection(t) - if err := CheckMinServerServerVersion(conn, 22, 6, 1); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 6, 1) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) } conn.Exec(ctx, "DROP TABLE IF EXISTS json_test") ddl := `CREATE table json_test(event JSON) ENGINE=MergeTree() ORDER BY tuple();` @@ -1976,8 +1976,8 @@ func TestJSONManyColumns(t *testing.T) { ctx := context.Background() conn := setupConnection(t) conn.Exec(ctx, "DROP TABLE IF EXISTS json_test") - if err := CheckMinServerServerVersion(conn, 22, 6, 1); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 6, 1) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) } ddl := `CREATE table json_test(event JSON, event2 JSON, col1 String) ENGINE=MergeTree() ORDER BY tuple();` require.NoError(t, conn.Exec(ctx, ddl)) diff --git a/tests/lowcardinality_test.go b/tests/lowcardinality_test.go index d9495e0fc8..efca9a2975 100644 --- a/tests/lowcardinality_test.go +++ b/tests/lowcardinality_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "math/rand" "testing" @@ -36,8 +37,8 @@ func TestLowCardinality(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 19, 11, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 19, 11, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -132,8 +133,8 @@ func TestColmunarLowCardinality(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -194,8 +195,8 @@ func TestLowCardinalityFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 20, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 20, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/map_test.go b/tests/map_test.go index 0f9dff9af0..d430869d4a 100644 --- a/tests/map_test.go +++ b/tests/map_test.go @@ -33,8 +33,8 @@ func TestMap(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -107,8 +107,8 @@ func TestColumnarMap(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -172,8 +172,8 @@ func TestMapFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -254,8 +254,8 @@ func TestOrderedMap(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/nested_test.go b/tests/nested_test.go index dd67c62dab..fc5fead583 100644 --- a/tests/nested_test.go +++ b/tests/nested_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" @@ -32,8 +33,8 @@ func TestSimpleNested(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -70,8 +71,8 @@ func TestNestedFlattened(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -136,8 +137,8 @@ func TestFlattenedSimpleNested(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -184,8 +185,8 @@ func TestNestedUnFlattened(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -265,8 +266,8 @@ func TestNestedFlush(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/nullable_array_test.go b/tests/nullable_array_test.go index de597d1314..891cd1e1ab 100644 --- a/tests/nullable_array_test.go +++ b/tests/nullable_array_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "net" "testing" @@ -57,8 +58,8 @@ func TestNullableArray(t *testing.T) { conn.Exec(ctx, "DROP TABLE IF EXISTS test_nullable_array") }() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } require.NoError(t, conn.Exec(ctx, ddl)) diff --git a/tests/simple_aggregate_function_test.go b/tests/simple_aggregate_function_test.go index e80643d33c..71218c16c2 100644 --- a/tests/simple_aggregate_function_test.go +++ b/tests/simple_aggregate_function_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "github.com/stretchr/testify/require" "testing" @@ -32,8 +33,8 @@ func TestSimpleAggregateFunction(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/bigint_test.go b/tests/std/bigint_test.go index a93d83bc09..7923608bfd 100644 --- a/tests/std/bigint_test.go +++ b/tests/std/bigint_test.go @@ -36,8 +36,8 @@ func TestStdBigInt(t *testing.T) { for name, protocol := range dsns { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { if conn, err := GetStdDSNConnection(protocol, useSSL, "false"); assert.NoError(t, err) { - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -109,7 +109,7 @@ func TestStdNullableBigInt(t *testing.T) { for name, protocol := range dsns { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { if conn, err := GetStdDSNConnection(protocol, useSSL, "false"); assert.NoError(t, err) { - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { + if !CheckMinServerVersion(conn, 21, 12, 0) { t.Skip(err.Error()) return } diff --git a/tests/std/bool_test.go b/tests/std/bool_test.go index 97fa775c94..286cd11140 100644 --- a/tests/std/bool_test.go +++ b/tests/std/bool_test.go @@ -35,8 +35,8 @@ func TestStdBool(t *testing.T) { for name, protocol := range dsns { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { if conn, err := GetStdDSNConnection(protocol, useSSL, "false"); assert.NoError(t, err) { - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/date32_test.go b/tests/std/date32_test.go index c0a2868863..ea7f79d2a8 100644 --- a/tests/std/date32_test.go +++ b/tests/std/date32_test.go @@ -38,8 +38,8 @@ func TestStdDate32(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/datetime64_test.go b/tests/std/datetime64_test.go index 445baa48b3..17142f21a4 100644 --- a/tests/std/datetime64_test.go +++ b/tests/std/datetime64_test.go @@ -38,8 +38,8 @@ func TestStdDateTime64(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 20, 3, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 20, 3, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/decimal_test.go b/tests/std/decimal_test.go index 8618ff19a0..a120432411 100644 --- a/tests/std/decimal_test.go +++ b/tests/std/decimal_test.go @@ -37,8 +37,8 @@ func TestStdDecimal(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/geo_multipolygon_test.go b/tests/std/geo_multipolygon_test.go index 6ce0da7f17..b23e84fbc7 100644 --- a/tests/std/geo_multipolygon_test.go +++ b/tests/std/geo_multipolygon_test.go @@ -42,8 +42,8 @@ func TestStdGeoMultiPolygon(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/geo_point_test.go b/tests/std/geo_point_test.go index b37aab8cae..ac36cf347b 100644 --- a/tests/std/geo_point_test.go +++ b/tests/std/geo_point_test.go @@ -41,8 +41,8 @@ func TestStdGeoPoint(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/geo_polygon_test.go b/tests/std/geo_polygon_test.go index 107f61017c..071d8521b8 100644 --- a/tests/std/geo_polygon_test.go +++ b/tests/std/geo_polygon_test.go @@ -42,8 +42,8 @@ func TestStdGeoPolygon(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/geo_ring_test.go b/tests/std/geo_ring_test.go index 602b8e3bf2..75ce353e37 100644 --- a/tests/std/geo_ring_test.go +++ b/tests/std/geo_ring_test.go @@ -41,8 +41,8 @@ func TestStdGeoRing(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 12, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 12, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/json_test.go b/tests/std/json_test.go index 262fa5f2f5..8554b5601a 100644 --- a/tests/std/json_test.go +++ b/tests/std/json_test.go @@ -19,6 +19,7 @@ package std import ( "crypto/tls" + "fmt" "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/assert" @@ -70,8 +71,8 @@ func TestStdJson(t *testing.T) { } conn, err := GetStdDSNConnection(clickhouse.Native, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 22, 6, 1); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 22, 6, 1) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } conn.Close() @@ -139,8 +140,8 @@ func TestStdJsonWithMap(t *testing.T) { } conn, err := GetStdDSNConnection(clickhouse.Native, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 22, 6, 1); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 22, 6, 1) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } conn.Close() diff --git a/tests/std/lowcardinality_test.go b/tests/std/lowcardinality_test.go index cb128447d1..30be76aaed 100644 --- a/tests/std/lowcardinality_test.go +++ b/tests/std/lowcardinality_test.go @@ -42,8 +42,8 @@ func TestStdLowCardinality(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 19, 11, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 19, 11, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/map_test.go b/tests/std/map_test.go index aadba57fa6..7def3ac1f2 100644 --- a/tests/std/map_test.go +++ b/tests/std/map_test.go @@ -36,8 +36,8 @@ func TestStdMap(t *testing.T) { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { conn, err := GetStdDSNConnection(protocol, useSSL, "false") require.NoError(t, err) - if err := CheckMinServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/nested_test.go b/tests/std/nested_test.go index dde2b95109..afe0f7d438 100644 --- a/tests/std/nested_test.go +++ b/tests/std/nested_test.go @@ -19,6 +19,7 @@ package std import ( "crypto/tls" + "fmt" "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/assert" @@ -39,8 +40,8 @@ func TestStdNested(t *testing.T) { }, tlsConfig, nil) require.NoError(t, err) conn.Exec("DROP TABLE std_nested_test") - if err := CheckMinServerVersion(conn, 22, 1, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 22, 1, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/tuples_test.go b/tests/std/tuples_test.go index 49c51fcb68..13356530cf 100644 --- a/tests/std/tuples_test.go +++ b/tests/std/tuples_test.go @@ -18,6 +18,7 @@ package std import ( "crypto/tls" + "fmt" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" "strconv" @@ -41,8 +42,8 @@ func TestTuple(t *testing.T) { require.NoError(t, err) localTime := testDate.In(loc) - if err := CheckMinServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/std/utils.go b/tests/std/utils.go index d1bbb3e0fd..c4edc1a99f 100644 --- a/tests/std/utils.go +++ b/tests/std/utils.go @@ -23,6 +23,7 @@ import ( "encoding/json" "fmt" "github.com/ClickHouse/clickhouse-go/v2" + "github.com/ClickHouse/clickhouse-go/v2/lib/proto" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "strconv" "strings" @@ -33,12 +34,12 @@ func GetStdTestEnvironment() (clickhouse_tests.ClickHouseTestEnvironment, error) return clickhouse_tests.GetTestEnvironment("std") } -func CheckMinServerVersion(conn *sql.DB, major, minor, patch uint64) error { +func CheckMinServerVersion(conn *sql.DB, major, minor, patch uint64) bool { var res string if err := conn.QueryRow("SELECT version()").Scan(&res); err != nil { panic(err) } - var version clickhouse_tests.Version + var version proto.Version for i, v := range strings.Split(res, ".") { switch i { case 0: @@ -49,7 +50,7 @@ func CheckMinServerVersion(conn *sql.DB, major, minor, patch uint64) error { version.Patch, _ = strconv.ParseUint(v, 10, 64) } } - return clickhouse_tests.CheckMinVersion(clickhouse_tests.Version{ + return proto.CheckMinVersion(proto.Version{ Major: major, Minor: minor, Patch: patch, @@ -59,11 +60,11 @@ func CheckMinServerVersion(conn *sql.DB, major, minor, patch uint64) error { func GetDSNConnection(environment string, protocol clickhouse.Protocol, secure bool, compress string) (*sql.DB, error) { env, err := clickhouse_tests.GetTestEnvironment(environment) enforceReplication := "" - if clickhouse_tests.CheckMinVersion(clickhouse_tests.Version{ + if proto.CheckMinVersion(proto.Version{ Major: 22, Minor: 8, Patch: 0, - }, env.Version) == nil { + }, env.Version) { enforceReplication = "database_replicated_enforce_synchronous_settings=1" } if err != nil { @@ -94,7 +95,7 @@ func GetConnectionFromDSN(dsn string) (*sql.DB, error) { if err != nil { return conn, err } - if CheckMinServerVersion(conn, 22, 8, 0) == nil { + if CheckMinServerVersion(conn, 22, 8, 0) { dsn = fmt.Sprintf("%s&database_replicated_enforce_synchronous_settings=1", dsn) } insertQuorum := clickhouse_tests.GetEnv("CLICKHOUSE_QUORUM_INSERT", "1") @@ -110,7 +111,7 @@ func GetConnectionWithOptions(options *clickhouse.Options) *sql.DB { options.Settings = clickhouse.Settings{} } conn := clickhouse.OpenDB(options) - if CheckMinServerVersion(conn, 22, 8, 0) == nil { + if CheckMinServerVersion(conn, 22, 8, 0) { options.Settings["database_replicated_enforce_synchronous_settings"] = "1" } var err error @@ -150,11 +151,11 @@ func GetOpenDBConnection(environment string, protocol clickhouse.Protocol, setti settings["insert_quorum"], err = strconv.Atoi(clickhouse_tests.GetEnv("CLICKHOUSE_QUORUM_INSERT", "1")) settings["insert_quorum_parallel"] = 0 settings["select_sequential_consistency"] = 1 - if clickhouse_tests.CheckMinVersion(clickhouse_tests.Version{ + if proto.CheckMinVersion(proto.Version{ Major: 22, Minor: 8, Patch: 0, - }, env.Version) == nil { + }, env.Version) { settings["database_replicated_enforce_synchronous_settings"] = "1" } if err != nil { diff --git a/tests/string_test.go b/tests/string_test.go index a81cfaf11e..af0b68830c 100644 --- a/tests/string_test.go +++ b/tests/string_test.go @@ -20,6 +20,7 @@ package tests import ( "context" "database/sql" + "fmt" "github.com/stretchr/testify/require" "testing" "time" @@ -45,8 +46,8 @@ func TestSimpleString(t *testing.T) { require.NoError(t, err) require.NoError(t, conn.Ping(ctx)) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -71,8 +72,8 @@ func TestString(t *testing.T) { }) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/tuple_test.go b/tests/tuple_test.go index 9467597392..e6566b3281 100644 --- a/tests/tuple_test.go +++ b/tests/tuple_test.go @@ -35,8 +35,8 @@ func TestTuple(t *testing.T) { require.NoError(t, err) localTime := testDate.In(loc) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -115,8 +115,8 @@ func TestNamedTupleWithSlice(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(name String, `1` Int64)) Engine MergeTree() ORDER BY tuple()" @@ -147,8 +147,8 @@ func TestNamedTupleWithTypedSlice(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(name String, city String), Col2 Int32) Engine MergeTree() ORDER BY tuple()" @@ -181,8 +181,8 @@ func TestNamedTupleWithMap(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(name String, id Int64)) Engine MergeTree() ORDER BY tuple()" @@ -212,8 +212,8 @@ func TestNamedTupleWithTypedMap(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(id Int64, code Int64)) Engine MergeTree() ORDER BY tuple()" @@ -243,8 +243,8 @@ func TestNamedTupleWithEscapedColumns(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(`56` String, `a22\\`` Int64)) Engine MergeTree() ORDER BY tuple()" @@ -269,8 +269,8 @@ func TestNamedTupleIncomplete(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(name String, id Int64)) Engine MergeTree() ORDER BY tuple()" @@ -291,8 +291,8 @@ func TestUnNamedTupleWithMap(t *testing.T) { ctx := context.Background() require.NoError(t, err) // https://github.com/ClickHouse/ClickHouse/pull/36544 - if err := CheckMinServerServerVersion(conn, 22, 5, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 22, 5, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = "CREATE TABLE test_tuple (Col1 Tuple(String, Int64)) Engine MergeTree() ORDER BY tuple()" @@ -325,8 +325,8 @@ func TestColumnarTuple(t *testing.T) { conn, err := GetNativeConnection(nil, nil, nil) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` @@ -409,8 +409,8 @@ func TestTupleFlush(t *testing.T) { conn, err := GetNativeConnection(nil, nil, nil) ctx := context.Background() require.NoError(t, err) - if err := CheckMinServerServerVersion(conn, 21, 9, 0); err != nil { - t.Skip(err.Error()) + if !CheckMinServerServerVersion(conn, 21, 9, 0) { + t.Skip(fmt.Errorf("unsupported clickhouse version")) return } const ddl = ` diff --git a/tests/utils.go b/tests/utils.go index b55b2523ef..db745af2b2 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -25,6 +25,7 @@ import ( "fmt" "github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" + "github.com/ClickHouse/clickhouse-go/v2/lib/proto" "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "github.com/docker/go-units" @@ -51,12 +52,6 @@ func GetClickHouseTestVersion() string { return GetEnv("CLICKHOUSE_VERSION", defaultClickHouseVersion) } -type Version struct { - Major uint64 - Minor uint64 - Patch uint64 -} - type ClickHouseTestEnvironment struct { Port int HttpPort int @@ -66,7 +61,7 @@ type ClickHouseTestEnvironment struct { Username string Password string Database string - Version Version + Version proto.Version Container testcontainers.Container `json:"-"` } @@ -103,25 +98,18 @@ func (env *ClickHouseTestEnvironment) setVersion() { env.Version = v.Version } -func CheckMinServerServerVersion(conn driver.Conn, major, minor, patch uint64) error { +func CheckMinServerServerVersion(conn driver.Conn, major, minor, patch uint64) bool { v, err := conn.ServerVersion() if err != nil { panic(err) } - return CheckMinVersion(Version{ + return proto.CheckMinVersion(proto.Version{ Major: major, Minor: minor, Patch: patch, }, v.Version) } -func CheckMinVersion(constraint Version, version Version) error { - if version.Major < constraint.Major || (version.Major == constraint.Major && version.Minor < constraint.Minor) || (version.Major == constraint.Major && version.Minor == constraint.Minor && version.Patch < constraint.Patch) { - return fmt.Errorf("unsupported server version %d.%d.%d < %d.%d.%d", version.Major, version.Minor, version.Patch, constraint.Major, constraint.Minor, constraint.Patch) - } - return nil -} - func CreateClickHouseTestEnvironment(testSet string) (ClickHouseTestEnvironment, error) { // create a ClickHouse Container ctx := context.Background() @@ -273,7 +261,7 @@ func GetConnectionWithOptions(options *clickhouse.Options) (driver.Conn, error) if err != nil { return conn, err } - if CheckMinServerServerVersion(conn, 22, 8, 0) == nil { + if CheckMinServerServerVersion(conn, 22, 8, 0) { options.Settings["database_replicated_enforce_synchronous_settings"] = "1" } options.Settings["insert_quorum"], err = strconv.Atoi(GetEnv("CLICKHOUSE_QUORUM_INSERT", "1")) @@ -298,11 +286,11 @@ func getConnection(env ClickHouseTestEnvironment, database string, settings clic if settings == nil { settings = clickhouse.Settings{} } - if CheckMinVersion(Version{ + if proto.CheckMinVersion(proto.Version{ Major: 22, Minor: 8, Patch: 0, - }, env.Version) == nil { + }, env.Version) { settings["database_replicated_enforce_synchronous_settings"] = "1" } settings["insert_quorum"], err = strconv.Atoi(GetEnv("CLICKHOUSE_QUORUM_INSERT", "1"))