From b35a868d45d6f22c94f67cd2e4ef975778bccc28 Mon Sep 17 00:00:00 2001 From: Dale Mcdiarmid Date: Sat, 19 Nov 2022 14:34:54 +0000 Subject: [PATCH] tests for nulls in tuple --- .github/workflows/run-tests.yml | 3 +- tests/issues/816_test.go | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/issues/816_test.go diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9f3da86374..2eb33f78a4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -24,9 +24,10 @@ jobs: - 1.19 clickhouse: - 22.3 - - 22.7 - 22.8 - 22.9 + - 22.10 + - 22.11 - latest steps: - uses: actions/checkout@main diff --git a/tests/issues/816_test.go b/tests/issues/816_test.go new file mode 100644 index 0000000000..82301ce3ef --- /dev/null +++ b/tests/issues/816_test.go @@ -0,0 +1,56 @@ +package issues + +import ( + "fmt" + "github.com/ClickHouse/clickhouse-go/v2" + clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests" + clickhouse_std_tests "github.com/ClickHouse/clickhouse-go/v2/tests/std" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "strconv" + "testing" +) + +func Test816(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, "false") + const ddl = ` + CREATE TABLE test_816 ( + Col1 Tuple(count Nullable(Int64), products Array(Tuple(price Nullable(Float64), qty Nullable(Int64))), price Nullable(Float64)) + ) Engine MergeTree() ORDER BY tuple() + ` + conn.Exec("DROP TABLE test_816") + defer func() { + conn.Exec("DROP TABLE test_816") + }() + _, err = conn.Exec(ddl) + require.NoError(t, err) + scope, err := conn.Begin() + require.NoError(t, err) + batch, err := scope.Prepare("INSERT INTO test_816") + require.NoError(t, err) + var ( + col1Data = map[string]interface{}{ + "count": nil, + "products": []map[string]interface{}{ + { + "price": nil, + "qty": nil, + }, + { + "price": float64(2.3), + "qty": int64(2), + }, + }, + "price": float64(1.1), + } + ) + _, err = batch.Exec(col1Data) + require.NoError(t, err) + require.NoError(t, scope.Commit()) + var col1 interface{} + require.NoError(t, conn.QueryRow("SELECT Col1 FROM test_816").Scan(&col1)) + assert.Equal(t, clickhouse_std_tests.ToJson(col1Data), clickhouse_std_tests.ToJson(col1)) + fmt.Println(col1) +}