-
Notifications
You must be signed in to change notification settings - Fork 53
/
tuple_test.go
70 lines (65 loc) · 1.46 KB
/
tuple_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
66
67
68
69
70
package ch
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/ClickHouse/ch-go/proto"
)
func newCol[T any, C proto.ColumnOf[T]](c C, v ...T) C {
for _, vv := range v {
c.Append(vv)
}
return c
}
func TestNamedTuples(t *testing.T) {
conn := ConnOpt(t, Options{
Settings: []Setting{
{
Key: "allow_experimental_object_type",
Value: "1",
Important: true,
},
},
})
if v := conn.ServerInfo(); (v.Major < 22) || (v.Major == 22 && v.Minor < 5) {
t.Skip("Skipping (not supported)")
}
ctx := context.Background()
require.NoError(t, conn.Do(ctx, Query{
Body: "CREATE TABLE named_tuples (`1` Tuple(`s` String, `i` Int64)) ENGINE = Memory",
}))
require.NoError(t, conn.Do(ctx, Query{
Body: "INSERT INTO named_tuples VALUES",
Input: proto.Input{
{
Name: "1",
Data: proto.ColTuple{
proto.ColNamed[string]{
ColumnOf: newCol[string](new(proto.ColStr), "foo", "bar", "baz"),
Name: "s",
},
proto.ColNamed[int64]{
ColumnOf: newCol[int64](new(proto.ColInt64), 1, 2, 3),
Name: "i",
},
},
},
},
}))
var (
strData = proto.ColNamed[string]{
ColumnOf: new(proto.ColStr),
Name: "s",
}
intData = proto.ColNamed[int64]{
ColumnOf: new(proto.ColInt64),
Name: "i",
}
)
require.NoError(t, conn.Do(ctx, Query{
Body: "SELECT * FROM named_tuples",
Result: proto.Results{
{Name: "1", Data: proto.ColTuple{strData, intData}},
},
}))
}