From 8a0701f7b5e4e35b384de0af3ba7ff4dd48c3e30 Mon Sep 17 00:00:00 2001 From: Kuba Kaflik Date: Mon, 24 Jun 2024 15:51:23 +0200 Subject: [PATCH] Align `allow_suspicious_low_cardinality_types` and `allow_suspicious_low_cardinality_types ` settings in tests due to ClickHouse Cloud incompatibility (#1331) * Remove setting `allow_suspicious_low_cardinality_types` in tests due to ClickHouse Cloud incompatibility * Set "allow_experimental_object_type" only when testing JSON and skip on cloud --- tests/issues/1049_test.go | 6 +- tests/issues/1072_test.go | 4 +- tests/issues/1106_test.go | 3 +- tests/issues/1113_test.go | 1 + tests/issues/1119_test.go | 1 + tests/issues/1128_test.go | 3 +- tests/issues/1164_test.go | 18 +++--- tests/issues/1169_test.go | 3 +- tests/issues/1200_pr_test.go | 3 +- tests/issues/1216_test.go | 3 +- tests/issues/1229_test.go | 3 +- tests/issues/1247_test.go | 3 +- tests/issues/1271_test.go | 8 +-- tests/issues/1280_test.go | 3 +- tests/issues/692_test.go | 4 +- tests/lowcardinality_test.go | 96 +++++++++++++------------------- tests/map_test.go | 4 +- tests/std/json_test.go | 11 +++- tests/std/lowcardinality_test.go | 64 ++++++++++----------- tests/std/map_test.go | 4 +- 20 files changed, 104 insertions(+), 141 deletions(-) diff --git a/tests/issues/1049_test.go b/tests/issues/1049_test.go index 53719ea978..0699ad306f 100644 --- a/tests/issues/1049_test.go +++ b/tests/issues/1049_test.go @@ -2,17 +2,17 @@ package issues import ( "context" + "testing" + "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" - "testing" ) func Test1049(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1072_test.go b/tests/issues/1072_test.go index 02fa79d4dc..33db6d4cbc 100644 --- a/tests/issues/1072_test.go +++ b/tests/issues/1072_test.go @@ -2,13 +2,15 @@ package issues import ( "context" + "testing" + "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" - "testing" ) func Test1072(t *testing.T) { + clickhouse_tests.SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.") var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ "max_execution_time": 60, diff --git a/tests/issues/1106_test.go b/tests/issues/1106_test.go index 41f2f62dab..e512a6f506 100644 --- a/tests/issues/1106_test.go +++ b/tests/issues/1106_test.go @@ -13,8 +13,7 @@ import ( func Test1106(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1113_test.go b/tests/issues/1113_test.go index d20c14e99d..054c1bc131 100644 --- a/tests/issues/1113_test.go +++ b/tests/issues/1113_test.go @@ -10,6 +10,7 @@ import ( ) func Test1113(t *testing.T) { + clickhouse_tests.SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.") var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ "max_execution_time": 60, diff --git a/tests/issues/1119_test.go b/tests/issues/1119_test.go index 2493b64170..fa48c98d26 100644 --- a/tests/issues/1119_test.go +++ b/tests/issues/1119_test.go @@ -10,6 +10,7 @@ import ( ) func Test1119(t *testing.T) { + clickhouse_tests.SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.") var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ "max_execution_time": 60, diff --git a/tests/issues/1128_test.go b/tests/issues/1128_test.go index d4b9d76839..d33ba7e200 100644 --- a/tests/issues/1128_test.go +++ b/tests/issues/1128_test.go @@ -59,8 +59,7 @@ type Test struct { func Test1128(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1164_test.go b/tests/issues/1164_test.go index f044dff284..cc6c1f7518 100644 --- a/tests/issues/1164_test.go +++ b/tests/issues/1164_test.go @@ -3,18 +3,18 @@ package issues import ( "context" "fmt" + "testing" + "github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2/lib/column" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" - "testing" ) func TestIssue1164(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) @@ -57,8 +57,7 @@ func BenchmarkIssue1164(b *testing.B) { b.Run("default-10000", func(b *testing.B) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) @@ -90,8 +89,7 @@ func BenchmarkIssue1164(b *testing.B) { b.Run("preAlloc-10000", func(b *testing.B) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) @@ -125,8 +123,7 @@ func BenchmarkIssue1164(b *testing.B) { b.Run("default-50000", func(b *testing.B) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) @@ -158,8 +155,7 @@ func BenchmarkIssue1164(b *testing.B) { b.Run("preAlloc-50000", func(b *testing.B) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1169_test.go b/tests/issues/1169_test.go index e37aea9881..941bb54efe 100644 --- a/tests/issues/1169_test.go +++ b/tests/issues/1169_test.go @@ -13,8 +13,7 @@ import ( func Test1169(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1200_pr_test.go b/tests/issues/1200_pr_test.go index e5f6513aa2..5bd2fd6d23 100644 --- a/tests/issues/1200_pr_test.go +++ b/tests/issues/1200_pr_test.go @@ -13,8 +13,7 @@ import ( func Test1200(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1216_test.go b/tests/issues/1216_test.go index c6c47b84cd..933753c09d 100644 --- a/tests/issues/1216_test.go +++ b/tests/issues/1216_test.go @@ -12,8 +12,7 @@ import ( func Test1216(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1229_test.go b/tests/issues/1229_test.go index e0c6cc46e0..b5987b1adc 100644 --- a/tests/issues/1229_test.go +++ b/tests/issues/1229_test.go @@ -18,8 +18,7 @@ func Test1229(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1247_test.go b/tests/issues/1247_test.go index 0b5695434c..f0beface85 100644 --- a/tests/issues/1247_test.go +++ b/tests/issues/1247_test.go @@ -12,8 +12,7 @@ import ( func Test1247(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1271_test.go b/tests/issues/1271_test.go index 14fed38bae..b565327f3c 100644 --- a/tests/issues/1271_test.go +++ b/tests/issues/1271_test.go @@ -3,14 +3,15 @@ package issues import ( "context" "fmt" - "github.com/ClickHouse/clickhouse-go/v2/lib/driver" - "github.com/google/uuid" "math/rand" "runtime" "strings" "testing" "time" + "github.com/ClickHouse/clickhouse-go/v2/lib/driver" + "github.com/google/uuid" + "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/require" @@ -20,8 +21,7 @@ import ( func Test1271(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection("issues", clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/1280_test.go b/tests/issues/1280_test.go index df4f564f40..d46d25b7a7 100644 --- a/tests/issues/1280_test.go +++ b/tests/issues/1280_test.go @@ -13,8 +13,7 @@ import ( func Test1280(t *testing.T) { var ( conn, err = clickhouse_tests.GetConnection(testSet, clickhouse.Settings{ - "max_execution_time": 60, - "allow_experimental_object_type": true, + "max_execution_time": 60, }, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) diff --git a/tests/issues/692_test.go b/tests/issues/692_test.go index 445ce01c43..206f2c84ba 100644 --- a/tests/issues/692_test.go +++ b/tests/issues/692_test.go @@ -34,9 +34,7 @@ import ( func TestIssue692(t *testing.T) { useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false")) require.NoError(t, err) - conn, err := clickhouse_std_tests.GetDSNConnection("issues", clickhouse.Native, useSSL, url.Values{ - "allow_suspicious_low_cardinality_types": []string{"1"}, - }) + conn, err := clickhouse_std_tests.GetDSNConnection("issues", clickhouse.Native, useSSL, url.Values{}) require.NoError(t, err) if !std.CheckMinServerVersion(conn, 21, 9, 0) { t.Skip(fmt.Errorf("unsupported clickhouse version")) diff --git a/tests/lowcardinality_test.go b/tests/lowcardinality_test.go index efca9a2975..70b3e3d0be 100644 --- a/tests/lowcardinality_test.go +++ b/tests/lowcardinality_test.go @@ -20,19 +20,17 @@ package tests import ( "context" "fmt" - "github.com/stretchr/testify/require" - "math/rand" "testing" "time" + "github.com/stretchr/testify/require" + "github.com/ClickHouse/clickhouse-go/v2" "github.com/stretchr/testify/assert" ) func TestLowCardinality(t *testing.T) { - conn, err := GetNativeConnection(clickhouse.Settings{ - "allow_suspicious_low_cardinality_types": 1, - }, nil, &clickhouse.Compression{ + conn, err := GetNativeConnection(clickhouse.Settings{}, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) ctx := context.Background() @@ -43,14 +41,13 @@ func TestLowCardinality(t *testing.T) { } const ddl = ` CREATE TABLE test_lowcardinality ( - Col1 LowCardinality(String) + ID UInt64 + , Col1 LowCardinality(String) , Col2 LowCardinality(FixedString(2)) - , Col3 LowCardinality(DateTime) - , Col4 LowCardinality(Int32) - , Col5 Array(LowCardinality(String)) - , Col6 Array(Array(LowCardinality(String))) - , Col7 LowCardinality(Nullable(String)) - , Col8 Array(Array(LowCardinality(Nullable(String)))) + , Col3 Array(LowCardinality(String)) + , Col4 Array(Array(LowCardinality(String))) + , Col5 LowCardinality(Nullable(String)) + , Col6 Array(Array(LowCardinality(Nullable(String)))) ) Engine MergeTree() ORDER BY tuple() ` defer func() { @@ -60,30 +57,28 @@ func TestLowCardinality(t *testing.T) { batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_lowcardinality") require.NoError(t, err) var ( - rnd = rand.Int31() timestamp = time.Now() ) for i := 0; i < 10; i++ { var ( + id = uint64(i) col1Data = timestamp.String() col2Data = "RU" - col3Data = timestamp.Add(time.Duration(i) * time.Minute) - col4Data = rnd + int32(i) - col5Data = []string{"A", "B", "C"} - col6Data = [][]string{ + col3Data = []string{"A", "B", "C"} + col4Data = [][]string{ []string{"Q", "W", "E"}, []string{"R", "T", "Y"}, } - col7Data = &col2Data - col8Data = [][]*string{ + col5Data = &col2Data + col6Data = [][]*string{ []*string{&col2Data, nil, &col2Data}, []*string{nil, &col2Data, nil}, } ) if i%2 == 0 { - require.NoError(t, batch.Append(col1Data, col2Data, col3Data, col4Data, col5Data, col6Data, col7Data, col8Data)) + require.NoError(t, batch.Append(id, col1Data, col2Data, col3Data, col4Data, col5Data, col6Data)) } else { - require.NoError(t, batch.Append(col1Data, col2Data, col3Data, col4Data, col5Data, col6Data, nil, col8Data)) + require.NoError(t, batch.Append(id, col1Data, col2Data, col3Data, col4Data, nil, col6Data)) } } require.NoError(t, batch.Send()) @@ -92,43 +87,38 @@ func TestLowCardinality(t *testing.T) { assert.Equal(t, uint64(10), count) for i := 0; i < 10; i++ { var ( + id uint64 col1 string col2 string - col3 time.Time - col4 int32 - col5 []string - col6 [][]string - col7 *string - col8 [][]*string + col3 []string + col4 [][]string + col5 *string + col6 [][]*string ) - require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_lowcardinality WHERE Col4 = $1", rnd+int32(i)).Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8)) + require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_lowcardinality WHERE ID = $1", i).Scan(&id, &col1, &col2, &col3, &col4, &col5, &col6)) assert.Equal(t, timestamp.String(), col1) assert.Equal(t, "RU", col2) - assert.Equal(t, timestamp.Add(time.Duration(i)*time.Minute).Truncate(time.Second).In(time.UTC), col3) - assert.Equal(t, rnd+int32(i), col4) - assert.Equal(t, []string{"A", "B", "C"}, col5) + assert.Equal(t, []string{"A", "B", "C"}, col3) assert.Equal(t, [][]string{ []string{"Q", "W", "E"}, []string{"R", "T", "Y"}, - }, col6) + }, col4) switch { case i%2 == 0: - assert.Equal(t, &col2, col7) + assert.Equal(t, &col2, col5) default: - assert.Nil(t, col7) + assert.Nil(t, col5) } col2Data := "RU" assert.Equal(t, [][]*string{ []*string{&col2Data, nil, &col2Data}, []*string{nil, &col2Data, nil}, - }, col8) + }, col6) } } func TestColmunarLowCardinality(t *testing.T) { - conn, err := GetNativeConnection(clickhouse.Settings{ - "allow_suspicious_low_cardinality_types": 1, - }, nil, &clickhouse.Compression{ + conn, err := GetNativeConnection(clickhouse.Settings{}, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) ctx := context.Background() @@ -139,10 +129,9 @@ func TestColmunarLowCardinality(t *testing.T) { } const ddl = ` CREATE TABLE test_lowcardinality ( - Col1 LowCardinality(String) + ID UInt64 + , Col1 LowCardinality(String) , Col2 LowCardinality(FixedString(2)) - , Col3 LowCardinality(DateTime) - , Col4 LowCardinality(Int32) ) Engine MergeTree() ORDER BY tuple() ` defer func() { @@ -152,45 +141,36 @@ func TestColmunarLowCardinality(t *testing.T) { batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_lowcardinality") require.NoError(t, err) var ( - rnd = rand.Int31() timestamp = time.Now() + idData []uint64 col1Data []string col2Data []string - col3Data []time.Time - col4Data []int32 ) for i := 0; i < 10; i++ { + idData = append(idData, uint64(i)) col1Data = append(col1Data, timestamp.String()) col2Data = append(col2Data, "RU") - col3Data = append(col3Data, timestamp.Add(time.Duration(i)*time.Minute)) - col4Data = append(col4Data, rnd+int32(i)) } - require.NoError(t, batch.Column(0).Append(col1Data)) - require.NoError(t, batch.Column(1).Append(col2Data)) - require.NoError(t, batch.Column(2).Append(col3Data)) - require.NoError(t, batch.Column(3).Append(col4Data)) + require.NoError(t, batch.Column(0).Append(idData)) + require.NoError(t, batch.Column(1).Append(col1Data)) + require.NoError(t, batch.Column(2).Append(col2Data)) require.NoError(t, batch.Send()) var count uint64 if err := conn.QueryRow(ctx, "SELECT COUNT() FROM test_lowcardinality").Scan(&count); assert.NoError(t, err) { assert.Equal(t, uint64(10), count) } var ( + id uint64 col1 string col2 string - col3 time.Time - col4 int32 ) - require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_lowcardinality WHERE Col4 = $1", rnd+6).Scan(&col1, &col2, &col3, &col4)) + require.NoError(t, conn.QueryRow(ctx, "SELECT * FROM test_lowcardinality WHERE ID = $1", 6).Scan(&id, &col1, &col2)) assert.Equal(t, timestamp.String(), col1) assert.Equal(t, "RU", col2) - assert.Equal(t, timestamp.Add(time.Duration(6)*time.Minute).Truncate(time.Second).In(time.UTC), col3) - assert.Equal(t, int32(rnd+6), col4) } func TestLowCardinalityFlush(t *testing.T) { - conn, err := GetNativeConnection(clickhouse.Settings{ - "allow_suspicious_low_cardinality_types": 1, - }, nil, &clickhouse.Compression{ + conn, err := GetNativeConnection(clickhouse.Settings{}, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) ctx := context.Background() diff --git a/tests/map_test.go b/tests/map_test.go index ab120ce229..51194cbea2 100644 --- a/tests/map_test.go +++ b/tests/map_test.go @@ -31,9 +31,7 @@ import ( ) func TestMap(t *testing.T) { - conn, err := GetNativeConnection(clickhouse.Settings{ - "allow_suspicious_low_cardinality_types": true, - }, nil, &clickhouse.Compression{ + conn, err := GetNativeConnection(clickhouse.Settings{}, nil, &clickhouse.Compression{ Method: clickhouse.CompressionLZ4, }) ctx := context.Background() diff --git a/tests/std/json_test.go b/tests/std/json_test.go index 2bb41f0a7d..209ec4d22b 100644 --- a/tests/std/json_test.go +++ b/tests/std/json_test.go @@ -20,13 +20,14 @@ package std import ( "crypto/tls" "fmt" + "strconv" + "testing" + "time" + "github.com/ClickHouse/clickhouse-go/v2" clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "strconv" - "testing" - "time" ) type Releases struct { @@ -63,6 +64,8 @@ type GithubEvent struct { var testDate, _ = time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", "2022-05-25 17:20:57 +0100 WEST") func TestStdJson(t *testing.T) { + clickhouse_tests.SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.") + useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false")) require.NoError(t, err) var tlsConfig *tls.Config @@ -132,6 +135,8 @@ func TestStdJson(t *testing.T) { // https://github.com/ClickHouse/clickhouse-go/issues/645 func TestStdJsonWithMap(t *testing.T) { + clickhouse_tests.SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.") + useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false")) require.NoError(t, err) var tlsConfig *tls.Config diff --git a/tests/std/lowcardinality_test.go b/tests/std/lowcardinality_test.go index 0a9b1464e8..0c2536ecc2 100644 --- a/tests/std/lowcardinality_test.go +++ b/tests/std/lowcardinality_test.go @@ -20,21 +20,19 @@ package std import ( "context" "fmt" - clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" - "github.com/stretchr/testify/require" - "math/rand" "strconv" "testing" "time" + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" + "github.com/stretchr/testify/require" + "github.com/ClickHouse/clickhouse-go/v2" "github.com/stretchr/testify/assert" ) func TestStdLowCardinality(t *testing.T) { - ctx := clickhouse.Context(context.Background(), clickhouse.WithSettings(clickhouse.Settings{ - "allow_suspicious_low_cardinality_types": 1, - })) + ctx := clickhouse.Context(context.Background(), clickhouse.WithSettings(clickhouse.Settings{})) dsns := map[string]clickhouse.Protocol{"Native": clickhouse.Native, "Http": clickhouse.HTTP} useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false")) require.NoError(t, err) @@ -48,14 +46,13 @@ func TestStdLowCardinality(t *testing.T) { } const ddl = ` CREATE TABLE test_lowcardinality ( - Col1 LowCardinality(String) + ID UInt64 + , Col1 LowCardinality(String) , Col2 LowCardinality(FixedString(2)) - , Col3 LowCardinality(DateTime) - , Col4 LowCardinality(Int32) - , Col5 Array(LowCardinality(String)) - , Col6 Array(Array(LowCardinality(String))) - , Col7 LowCardinality(Nullable(String)) - , Col8 Array(Array(LowCardinality(Nullable(String)))) + , Col3 Array(LowCardinality(String)) + , Col4 Array(Array(LowCardinality(String))) + , Col5 LowCardinality(Nullable(String)) + , Col6 Array(Array(LowCardinality(Nullable(String)))) ) Engine MergeTree() ORDER BY tuple() ` defer func() { @@ -68,32 +65,30 @@ func TestStdLowCardinality(t *testing.T) { batch, err := scope.Prepare("INSERT INTO test_lowcardinality") require.NoError(t, err) var ( - rnd = rand.Int31() timestamp = time.Now() ) for i := 0; i < 10; i++ { var ( + id = uint64(i) col1Data = timestamp.String() col2Data = "RU" - col3Data = timestamp.Add(time.Duration(i) * time.Minute) - col4Data = rnd + int32(i) - col5Data = []string{"A", "B", "C"} - col6Data = [][]string{ + col3Data = []string{"A", "B", "C"} + col4Data = [][]string{ []string{"Q", "W", "E"}, []string{"R", "T", "Y"}, } - col7Data = &col2Data - col8Data = [][]*string{ + col5Data = &col2Data + col6Data = [][]*string{ []*string{&col2Data, nil, &col2Data}, []*string{nil, &col2Data, nil}, } ) if i%2 == 0 { - if _, err := batch.Exec(col1Data, col2Data, col3Data, col4Data, col5Data, col6Data, col7Data, col8Data); !assert.NoError(t, err) { + if _, err := batch.Exec(id, col1Data, col2Data, col3Data, col4Data, col5Data, col6Data); !assert.NoError(t, err) { return } } else { - if _, err := batch.Exec(col1Data, col2Data, col3Data, col4Data, col5Data, col6Data, nil, col8Data); !assert.NoError(t, err) { + if _, err := batch.Exec(id, col1Data, col2Data, col3Data, col4Data, nil, col6Data); !assert.NoError(t, err) { return } } @@ -105,36 +100,33 @@ func TestStdLowCardinality(t *testing.T) { for i := 0; i < 10; i++ { var ( + id uint64 col1 string col2 string - col3 time.Time - col4 int32 - col5 []string - col6 [][]string - col7 *string - col8 [][]*string + col3 []string + col4 [][]string + col5 *string + col6 [][]*string ) - require.NoError(t, conn.QueryRow("SELECT * FROM test_lowcardinality WHERE Col4 = $1", rnd+int32(i)).Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8)) + require.NoError(t, conn.QueryRow("SELECT * FROM test_lowcardinality WHERE ID = $1", i).Scan(&id, &col1, &col2, &col3, &col4, &col5, &col6)) assert.Equal(t, timestamp.String(), col1) assert.Equal(t, "RU", col2) - assert.Equal(t, timestamp.Add(time.Duration(i)*time.Minute).Truncate(time.Second).In(time.UTC), col3) - assert.Equal(t, rnd+int32(i), col4) - assert.Equal(t, []string{"A", "B", "C"}, col5) + assert.Equal(t, []string{"A", "B", "C"}, col3) assert.Equal(t, [][]string{ []string{"Q", "W", "E"}, []string{"R", "T", "Y"}, - }, col6) + }, col4) switch { case i%2 == 0: - assert.Equal(t, &col2, col7) + assert.Equal(t, &col2, col5) default: - assert.Nil(t, col7) + assert.Nil(t, col5) } col2Data := "RU" assert.Equal(t, [][]*string{ []*string{&col2Data, nil, &col2Data}, []*string{nil, &col2Data, nil}, - }, col8) + }, col6) } }) } diff --git a/tests/std/map_test.go b/tests/std/map_test.go index 56a2dbda0e..1b7cee95df 100644 --- a/tests/std/map_test.go +++ b/tests/std/map_test.go @@ -36,9 +36,7 @@ func TestStdMap(t *testing.T) { require.NoError(t, err) for name, protocol := range dsns { t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) { - conn, err := GetStdDSNConnection(protocol, useSSL, url.Values{ - "allow_suspicious_low_cardinality_types": []string{"1"}, - }) + conn, err := GetStdDSNConnection(protocol, useSSL, url.Values{}) require.NoError(t, err) if !CheckMinServerVersion(conn, 21, 9, 0) { t.Skip(fmt.Errorf("unsupported clickhouse version"))