-
Notifications
You must be signed in to change notification settings - Fork 153
/
collation.go
53 lines (42 loc) · 1.12 KB
/
collation.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
package plan
import (
"fmt"
)
const (
CollationKey = "collation"
)
// CollationAttr is a physical attribute that describes the collation
// of the rows within a table. Note: the collation attribute does not
// say anything about how the tables in a stream are ordered.
type CollationAttr struct {
Columns []string
Desc bool
}
var _ PhysicalAttr = (*CollationAttr)(nil)
func (ca *CollationAttr) Key() string { return CollationKey }
func (ca *CollationAttr) SuccessorsMustRequire() bool {
return false
}
func (ca *CollationAttr) SatisfiedBy(attr PhysicalAttr) bool {
gotCollation, ok := attr.(*CollationAttr)
if !ok {
return false
}
if ca.Desc != gotCollation.Desc {
return false
}
if len(ca.Columns) > len(gotCollation.Columns) {
return false
}
// Note that if we are looking for collation of [a, b] and we get a collation of [a, b, c]
// the collation is still satisfied.
for i, col := range ca.Columns {
if gotCollation.Columns[i] != col {
return false
}
}
return true
}
func (ca *CollationAttr) String() string {
return fmt.Sprintf("%v{Columns: %v, Desc: %v}", CollationKey, ca.Columns, ca.Desc)
}