Skip to content

Commit 2f78b7f

Browse files
committed
Cleaned up and added better comments on a couple types
Signed-off-by: Zach Musgrave <zach@liquidata.co>
1 parent c18edf9 commit 2f78b7f

File tree

6 files changed

+38
-30
lines changed

6 files changed

+38
-30
lines changed

memory/ascend_index.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ func (l *AscendIndexLookup) Indexes() []string {
2828
return []string{l.id}
2929
}
3030

31-
func (l *AscendIndexLookup) IsMergeable(sql.IndexLookup) bool {
32-
return true
31+
func (l *AscendIndexLookup) IsMergeable(lookup sql.IndexLookup) bool {
32+
_, ok := lookup.(MergeableLookup)
33+
return ok
3334
}
3435

3536
func (l *AscendIndexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {

memory/descend_index.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ func (l *DescendIndexLookup) Indexes() []string {
4545
return []string{l.id}
4646
}
4747

48-
func (l *DescendIndexLookup) IsMergeable(sql.IndexLookup) bool {
49-
return true
48+
func (l *DescendIndexLookup) IsMergeable(lookup sql.IndexLookup) bool {
49+
_, ok := lookup.(MergeableLookup)
50+
return ok
5051
}
5152

5253
func (l *DescendIndexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {

memory/index_driver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import (
66

77
const IndexDriverId = "MemoryIndexDriver"
88

9+
// TestIndexDriver is a non-performant index driver meant to aid in verification of engine correctness. It can not
10+
// create or delete indexes, but will use the index types defined in this package to alter how queries are executed,
11+
// retrieving values from the indexes rather than from the tables directly.
912
type TestIndexDriver struct {
1013
db string
1114
indexes map[string][]sql.Index
1215
}
1316

17+
// NewIndexDriver returns a new index driver for database and the indexes given, keyed by the table name.
1418
func NewIndexDriver(db string, indexes map[string][]sql.Index) *TestIndexDriver {
1519
return &TestIndexDriver{db: db, indexes: indexes}
1620
}

memory/mergeable_index.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,34 @@ func (i *MergeableDummyIndex) ID() string {
8484

8585
func (i *MergeableDummyIndex) Table() string { return i.TableName }
8686

87+
// All lookups in this package, except for UnmergeableLookup, are MergeableLookups. The IDs are mostly for testing /
88+
// verification purposes.
8789
type MergeableLookup interface {
8890
ID() string
8991
}
9092

91-
// ExpressionsIndex is an index made out of one or more expressions (usually field expressions)
93+
// ExpressionsIndex is an index made out of one or more expressions (usually field expressions), linked to a Table.
9294
type ExpressionsIndex interface {
9395
MemTable() *Table
9496
ColumnExpressions() []sql.Expression
9597
}
9698

99+
// MergeableIndexLookup is a lookup linked to an ExpressionsIndex. It can be merged with any other MergeableIndexLookup. All lookups in this package are Merge
97100
type MergeableIndexLookup struct {
98-
Key []interface{}
99-
Index ExpressionsIndex
101+
Key []interface{}
102+
Index ExpressionsIndex
103+
}
104+
105+
// memoryIndexLookup is a lookup that defines an expression to evaluate which rows are part of the index values
106+
type memoryIndexLookup interface {
107+
EvalExpression() sql.Expression
100108
}
101109

102110
var _ sql.Mergeable = (*MergeableIndexLookup)(nil)
103111
var _ sql.SetOperations = (*MergeableIndexLookup)(nil)
104112
var _ memoryIndexLookup = (*MergeableIndexLookup)(nil)
105113

106-
func (i *MergeableIndexLookup) ID() string { return strings.Join(i.Indexes(), ",") }
114+
func (i *MergeableIndexLookup) ID() string { return strings.Join(i.Indexes(), ",") }
107115

108116
func (i *MergeableIndexLookup) IsMergeable(lookup sql.IndexLookup) bool {
109117
_, ok := lookup.(MergeableLookup)
@@ -198,8 +206,9 @@ func union(idx ExpressionsIndex, left sql.IndexLookup, lookups ...sql.IndexLooku
198206
}
199207
}
200208

201-
// An index lookup that has been merged with another.
202-
// Exactly one of the Unions or Intersections fields should be set.
209+
// MergedIndexLookup is an index lookup that has been merged with another.
210+
// Exactly one of the Unions or Intersections fields should be set, and correspond to a logical AND or OR operation,
211+
// respectively.
203212
type MergedIndexLookup struct {
204213
Unions []sql.IndexLookup
205214
Intersections []sql.IndexLookup
@@ -252,6 +261,14 @@ func (m *MergedIndexLookup) Values(p sql.Partition) (sql.IndexValueIter, error)
252261
}, nil
253262
}
254263

264+
func (m *MergedIndexLookup) Indexes() []string {
265+
panic("implement me")
266+
}
267+
268+
func (m *MergedIndexLookup) ID() string {
269+
panic("implement me")
270+
}
271+
255272
func or(expressions ...sql.Expression) sql.Expression {
256273
if len(expressions) == 1 {
257274
return expressions[0]
@@ -264,12 +281,4 @@ func and(expressions ...sql.Expression) sql.Expression {
264281
return expressions[0]
265282
}
266283
return expression.NewAnd(expressions[0], and(expressions[1:]...))
267-
}
268-
269-
func (m *MergedIndexLookup) Indexes() []string {
270-
panic("implement me")
271-
}
272-
273-
func (m *MergedIndexLookup) ID() string {
274-
panic("implement me")
275284
}

memory/negative_index.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func (l *NegateIndexLookup) Indexes() []string {
3030
return []string{l.ID()}
3131
}
3232

33-
func (*NegateIndexLookup) IsMergeable(sql.IndexLookup) bool {
34-
return true
33+
func (*NegateIndexLookup) IsMergeable(lookup sql.IndexLookup) bool {
34+
_, ok := lookup.(MergeableLookup)
35+
return ok
3536
}
3637

3738
func (l *NegateIndexLookup) Union(lookups ...sql.IndexLookup) sql.IndexLookup {

memory/unmergeable_index.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,13 @@ func (u *UnmergeableDummyIndex) Get(key ...interface{}) (sql.IndexLookup, error)
3737
}, nil
3838
}
3939

40+
// UnmergeableIndexLookup is the only IndexLookup in this package that doesn't implement Mergeable, and therefore
41+
// can't be merged with other lookups.
4042
type UnmergeableIndexLookup struct {
4143
key []interface{}
4244
idx *UnmergeableDummyIndex
4345
}
4446

45-
func (u *UnmergeableIndexLookup) EvalExpression() sql.Expression {
46-
return nil
47-
}
48-
49-
type memoryIndexLookup interface {
50-
EvalExpression() sql.Expression
51-
}
52-
53-
var _ memoryIndexLookup = (*UnmergeableIndexLookup)(nil)
54-
5547
// dummyIndexValueIter does a very simple and verifiable iteration over the table values for a given index. It does this
5648
// by iterating over all the table rows for a partition and evaluating each of them for inclusion in the index. This is
5749
// not an efficient way to store an index, and is only suitable for testing the correctness of index code in the engine.

0 commit comments

Comments
 (0)