-
Notifications
You must be signed in to change notification settings - Fork 351
/
column_collection.go
59 lines (48 loc) · 1.29 KB
/
column_collection.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
package metastore
import (
"fmt"
mserrors "github.com/treeverse/lakefs/pkg/metastore/errors"
)
type ColumnCollection struct {
columns []*FieldSchema
}
func (c *ColumnCollection) Name(i int) string {
return c.columns[i].Name
}
func (c *ColumnCollection) Len() int {
return len(c.columns)
}
func (c *ColumnCollection) Less(i, j int) bool {
return compareColumns(c.columns[i], c.columns[j]) == ItemLess
}
func (c *ColumnCollection) Swap(i, j int) {
c.columns[i], c.columns[j] = c.columns[j], c.columns[i]
}
func (c *ColumnCollection) Value(i int) interface{} {
return c.columns[i]
}
func (c *ColumnCollection) CompareWith(i int, v interface{}, j int) CompareResult {
if otherIter, ok := v.(*ColumnCollection); ok {
return compareColumns(c.columns[i], otherIter.columns[j])
}
err := fmt.Errorf("%w ColumnCollection, got %T", mserrors.ErrExpectedType, v)
panic(err)
}
func compareColumns(columnA, columnB *FieldSchema) CompareResult {
nameA, nameB := columnA.Name, columnB.Name
if nameA < nameB {
return ItemLess
}
if nameA > nameB {
return ItemGreater
}
if columnA.Type == columnB.Type && columnA.Comment == columnB.Comment {
return ItemSame
}
return ItemSameKey
}
func NewColumnCollection(columns []*FieldSchema) *ColumnCollection {
return &ColumnCollection{
columns: columns,
}
}