-
Notifications
You must be signed in to change notification settings - Fork 53
/
query_raw_test.go
65 lines (56 loc) · 1.47 KB
/
query_raw_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//go:build (amd64 || arm64 || riscv64) && !purego
package ch
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/ClickHouse/ch-go/proto"
)
func TestClient_Query_Raw(t *testing.T) {
ctx := context.Background()
t.Parallel()
t.Run("InsertMapOfFixedStrArrayStr", func(t *testing.T) {
t.Parallel()
conn := Conn(t)
createTable := Query{
Body: "CREATE TABLE test_table (v Map(FixedString(16), Array(String))) ENGINE = TinyLog",
}
require.NoError(t, conn.Do(ctx, createTable), "create table")
type K = [16]byte
data := &proto.ColMap[K, []string]{
Keys: new(proto.ColRawOf[K]),
Values: new(proto.ColStr).Array(),
}
data.AppendArr([]map[K][]string{
{
K{1: 123, 2: 4}: []string{"Hello", "World"},
},
{
K{1: 124, 2: 3}: []string{"Hi"},
K{1: 124, 2: 1}: []string{"Hello"},
},
})
insertQuery := Query{
Body: "INSERT INTO test_table VALUES",
Input: []proto.InputColumn{
{Name: "v", Data: data},
},
}
require.NoError(t, conn.Do(ctx, insertQuery), "insert")
gotData := &proto.ColMap[K, []string]{
Keys: new(proto.ColRawOf[K]),
Values: new(proto.ColStr).Array(),
}
selectData := Query{
Body: "SELECT * FROM test_table",
Result: proto.Results{
{Name: "v", Data: gotData},
},
}
require.NoError(t, conn.Do(ctx, selectData), "select")
require.Equal(t, data.Rows(), gotData.Rows())
for i := 0; i < data.Rows(); i++ {
require.Equal(t, data.Row(i), gotData.Row(i))
}
})
}