aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/dump_test.go
blob: f84ab2f24aaf8bca0b8a0202837e8a704d5628a6 (plain) (blame)
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
package proto_test

import (
	"bytes"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/ClickHouse/ch-go/proto"
)

func TestDump(t *testing.T) {
	// Testing decoding of Native format dump.
	//
	// CREATE TABLE test_dump (id Int8, v String)
	//   ENGINE = MergeTree()
	// ORDER BY id;
	//
	// SELECT * FROM test_dump
	//   ORDER BY id
	// INTO OUTFILE 'test_dump_native.raw' FORMAT Native;
	data, err := os.ReadFile(filepath.Join("_testdata", "test_dump_native.raw"))
	require.NoError(t, err)
	var (
		dec    proto.Block
		ids    proto.ColInt8
		values proto.ColStr
	)
	require.NoError(t, dec.DecodeRawBlock(proto.NewReader(bytes.NewReader(data)), 54451, proto.Results{
		{Name: "id", Data: &ids},
		{Name: "v", Data: &values},
	}),
	)
}

func TestDumpLowCardinality(t *testing.T) {
	data, err := os.ReadFile(filepath.Join("_testdata", "select_lc.raw"))
	require.NoError(t, err)
	col := new(proto.ColStr).LowCardinality().Array()
	var dec proto.Block
	require.NoError(t, dec.DecodeRawBlock(proto.NewReader(bytes.NewReader(data)), 54451, proto.Results{
		{Name: "v", Data: col},
	}),
	)
}