Skip to content

Commit acca784

Browse files
committed
add test case
1 parent 2bf8de6 commit acca784

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

conn_http_batch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func (h *httpConnect) prepareBatch(ctx context.Context, query string, opts drive
7373
return nil, err
7474
}
7575
// these column types cannot be specified in INSERT queries
76-
if default_type == "MATERIALIZED" || default_type == "ALIAS" {
77-
continue
76+
if default_type == "MATERIALIZED" || default_type == "ALIAS" {
77+
continue
7878
}
7979
colNames = append(colNames, colName)
8080
columns[colName] = colType

tests/std/mat_cols_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to ClickHouse, Inc. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. ClickHouse, Inc. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package std
19+
20+
import (
21+
"fmt"
22+
"math/big"
23+
"strconv"
24+
"testing"
25+
26+
"github.com/ClickHouse/clickhouse-go/v2"
27+
clickhouse_tests "github.com/ClickHouse/clickhouse-go/v2/tests"
28+
"github.com/stretchr/testify/assert"
29+
"github.com/stretchr/testify/require"
30+
)
31+
32+
func TestMatColInsert(t *testing.T) {
33+
dsns := map[string]clickhouse.Protocol{"Native": clickhouse.Native, "Http": clickhouse.HTTP}
34+
useSSL, err := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_SSL", "false"))
35+
require.NoError(t, err)
36+
for name, protocol := range dsns {
37+
t.Run(fmt.Sprintf("%s Protocol", name), func(t *testing.T) {
38+
if conn, err := GetStdDSNConnection(protocol, useSSL, nil); assert.NoError(t, err) {
39+
if !CheckMinServerVersion(conn, 21, 12, 0) {
40+
t.Skip(fmt.Errorf("unsupported clickhouse version"))
41+
return
42+
}
43+
const ddl = `
44+
CREATE TABLE test_mat_cols (
45+
Col1 Int128
46+
, Col2 MATERIALIZED Col1 * 2
47+
) Engine MergeTree() ORDER BY tuple()
48+
`
49+
defer func() {
50+
conn.Exec("DROP TABLE test_mat_cols")
51+
}()
52+
_, err := conn.Exec(ddl)
53+
require.NoError(t, err)
54+
scope, err := conn.Begin()
55+
require.NoError(t, err)
56+
batch, err := scope.Prepare("INSERT INTO test_mat_cols")
57+
require.NoError(t, err)
58+
var (
59+
col1Data = big.NewInt(128)
60+
col2Data = big.NewInt(128 * 2)
61+
)
62+
_, err = batch.Exec(col1Data)
63+
require.NoError(t, err)
64+
require.NoError(t, scope.Commit())
65+
var (
66+
col1 big.Int
67+
col2 big.Int
68+
)
69+
require.NoError(t, conn.QueryRow("SELECT * FROM test_mat_cols").Scan(&col1))
70+
assert.Equal(t, *col1Data, col1)
71+
require.NoError(t, conn.QueryRow("SELECT Col1, Col2 from test_mat_cols").Scan(&col1, &col2))
72+
assert.Equal(t, *col1Data, col1)
73+
assert.Equal(t, *col2Data, col2)
74+
}
75+
})
76+
}
77+
}

0 commit comments

Comments
 (0)