aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_external_data.go
blob: 706a6c585643e5f1bdfdc26cfbc35440d0704c8c (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
package clickhouse

import "github.com/ClickHouse/clickhouse-go/lib/data"

func (ch *clickhouse) sendExternalTables(externalTables []ExternalTable) error {
	ch.logf("[send external tables] count %d", len(externalTables))
	if externalTables == nil || len(externalTables) == 0 {
		return nil
	}
	block := &data.Block{}
	sentTables := make(map[string]bool, 0)
	for _, externalTable := range externalTables {
		if _, ok := sentTables[externalTable.Name]; ok {
			continue
		}
		ch.logf("[send external table] name %s", externalTable.Name)
		sentTables[externalTable.Name] = true
		block.Columns = externalTable.Columns
		block.NumColumns = uint64(len(externalTable.Columns))
		for _, row := range externalTable.Values {
			err := block.AppendRow(row)
			if err != nil {
				return err
			}
		}
		if err := ch.writeBlock(block, externalTable.Name); err != nil {
			return err
		}
		if err := ch.encoder.Flush(); err != nil {
			return err
		}
		block.Reset()
	}
	return nil
}