-
Notifications
You must be signed in to change notification settings - Fork 123
/
table.go
84 lines (71 loc) · 1.64 KB
/
table.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gitbase
import (
"fmt"
"github.com/src-d/go-mysql-server/sql"
)
// Table represents a gitbase table.
type Table interface {
sql.FilteredTable
sql.Checksumable
sql.PartitionCounter
gitBase
}
// Squashable represents a table that can be squashed.
type Squashable interface {
isSquashable()
}
type gitBase interface {
isGitbaseTable()
}
func printTable(
name string,
tableSchema sql.Schema,
projection []string,
filters []sql.Expression,
index sql.IndexLookup,
) string {
p := sql.NewTreePrinter()
_ = p.WriteNode("Table(%s)", name)
var children = make([]string, len(tableSchema))
for i, col := range tableSchema {
children[i] = fmt.Sprintf(
"Column(%s, %s, nullable=%v)",
col.Name,
col.Type.Type().String(),
col.Nullable,
)
}
if len(projection) > 0 {
children = append(children, printableProjection(projection))
}
if len(filters) > 0 {
children = append(children, printableFilters(filters))
}
if index != nil {
children = append(children, printableIndexes(index))
}
_ = p.WriteChildren(children...)
return p.String()
}
func printableFilters(filters []sql.Expression) string {
p := sql.NewTreePrinter()
_ = p.WriteNode("Filters")
var fs = make([]string, len(filters))
for i, f := range filters {
fs[i] = f.String()
}
_ = p.WriteChildren(fs...)
return p.String()
}
func printableProjection(projection []string) string {
p := sql.NewTreePrinter()
_ = p.WriteNode("Projected")
_ = p.WriteChildren(projection...)
return p.String()
}
func printableIndexes(idx sql.IndexLookup) string {
p := sql.NewTreePrinter()
_ = p.WriteNode("Indexes")
_ = p.WriteChildren(idx.Indexes()...)
return p.String()
}