-
Notifications
You must be signed in to change notification settings - Fork 351
/
partition_collection.go
67 lines (55 loc) · 1.68 KB
/
partition_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
60
61
62
63
64
65
66
67
package metastore
import (
"fmt"
mserrors "github.com/treeverse/lakefs/pkg/metastore/errors"
)
type PartitionCollection struct {
partitions []*Partition
}
func NewPartitionCollection(partitions []*Partition) *PartitionCollection {
return &PartitionCollection{partitions: partitions}
}
func (p *PartitionCollection) Name(i int) string {
return p.partitions[i].Name()
}
func (p *PartitionCollection) Len() int {
return len(p.partitions)
}
func (p *PartitionCollection) Less(i, j int) bool {
return comparePartitions(p.partitions[i], p.partitions[j]) == ItemLess
}
func (p *PartitionCollection) Swap(i, j int) {
p.partitions[i], p.partitions[j] = p.partitions[j], p.partitions[i]
}
func (p *PartitionCollection) Value(i int) interface{} {
return p.partitions[i]
}
func (p *PartitionCollection) CompareWith(i int, v interface{}, j int) CompareResult {
if otherIter, ok := v.(*PartitionCollection); ok {
return comparePartitions(p.partitions[i], otherIter.partitions[j])
}
err := fmt.Errorf("%w *PartitionCollection, got %T", mserrors.ErrExpectedType, v)
panic(err)
}
func partitionValueEqual(partitionA, partitionB *Partition) bool {
if partitionA.Sd == nil && partitionB.Sd == nil {
return true
}
if partitionA.Sd == nil || partitionB.Sd == nil {
return false
}
return partitionA.LastAccessTime == partitionB.LastAccessTime && len(partitionA.Sd.Cols) == len(partitionB.Sd.Cols)
}
func comparePartitions(partitionA, partitionB *Partition) CompareResult {
nameA, nameB := partitionA.Name(), partitionB.Name()
if nameA < nameB {
return ItemLess
}
if nameA > nameB {
return ItemGreater
}
if partitionValueEqual(partitionA, partitionB) {
return ItemSame
}
return ItemSameKey
}