Skip to content

Commit c52fcf5

Browse files
committed
gitbase: implement sql.PartitionCounter in all tables
Signed-off-by: Miguel Molina <[email protected]>
1 parent 1d223e6 commit c52fcf5

14 files changed

+42
-50
lines changed

blobs.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
)
2727

2828
type blobsTable struct {
29+
partitioned
2930
filters []sql.Expression
3031
projection []string
3132
index sql.IndexLookup
@@ -83,10 +84,6 @@ func (r *blobsTable) IndexLookup() sql.IndexLookup { return r.index }
8384
func (r *blobsTable) Filters() []sql.Expression { return r.filters }
8485
func (r *blobsTable) Projection() []string { return r.projection }
8586

86-
func (r *blobsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
87-
return newRepositoryPartitionIter(ctx)
88-
}
89-
9087
func (r *blobsTable) PartitionRows(
9188
ctx *sql.Context,
9289
p sql.Partition,

commit_blobs.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type commitBlobsTable struct {
13+
partitioned
1314
filters []sql.Expression
1415
index sql.IndexLookup
1516
}
@@ -55,10 +56,6 @@ func (t *commitBlobsTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
5556
func (t *commitBlobsTable) IndexLookup() sql.IndexLookup { return t.index }
5657
func (t *commitBlobsTable) Filters() []sql.Expression { return t.filters }
5758

58-
func (t *commitBlobsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
59-
return newRepositoryPartitionIter(ctx)
60-
}
61-
6259
func (t *commitBlobsTable) PartitionRows(
6360
ctx *sql.Context,
6461
p sql.Partition,

commit_files.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
type commitFilesTable struct {
17+
partitioned
1718
filters []sql.Expression
1819
index sql.IndexLookup
1920
}
@@ -60,10 +61,6 @@ func (t *commitFilesTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
6061
func (t *commitFilesTable) IndexLookup() sql.IndexLookup { return t.index }
6162
func (t *commitFilesTable) Filters() []sql.Expression { return t.filters }
6263

63-
func (t *commitFilesTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
64-
return newRepositoryPartitionIter(ctx)
65-
}
66-
6764
func (t *commitFilesTable) PartitionRows(
6865
ctx *sql.Context,
6966
p sql.Partition,

commit_trees.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
type commitTreesTable struct {
15+
partitioned
1516
filters []sql.Expression
1617
index sql.IndexLookup
1718
}
@@ -56,10 +57,6 @@ func (t *commitTreesTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
5657
func (t *commitTreesTable) IndexLookup() sql.IndexLookup { return t.index }
5758
func (t *commitTreesTable) Filters() []sql.Expression { return t.filters }
5859

59-
func (t *commitTreesTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
60-
return newRepositoryPartitionIter(ctx)
61-
}
62-
6360
func (t *commitTreesTable) PartitionRows(
6461
ctx *sql.Context,
6562
p sql.Partition,

commits.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type commitsTable struct {
13+
partitioned
1314
filters []sql.Expression
1415
index sql.IndexLookup
1516
}
@@ -66,10 +67,6 @@ func (r *commitsTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
6667
func (r *commitsTable) IndexLookup() sql.IndexLookup { return r.index }
6768
func (r *commitsTable) Filters() []sql.Expression { return r.filters }
6869

69-
func (r *commitsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
70-
return newRepositoryPartitionIter(ctx)
71-
}
72-
7370
func (r *commitsTable) PartitionRows(
7471
ctx *sql.Context,
7572
p sql.Partition,

files.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
type filesTable struct {
14+
partitioned
1415
filters []sql.Expression
1516
projection []string
1617
index sql.IndexLookup
@@ -61,10 +62,6 @@ func (r *filesTable) IndexLookup() sql.IndexLookup { return r.index }
6162
func (r *filesTable) Filters() []sql.Expression { return r.filters }
6263
func (r *filesTable) Projection() []string { return r.projection }
6364

64-
func (r *filesTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
65-
return newRepositoryPartitionIter(ctx)
66-
}
67-
6865
func (r *filesTable) PartitionRows(
6966
ctx *sql.Context,
7067
p sql.Partition,

partition.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,27 @@ import (
77
"gopkg.in/src-d/go-mysql-server.v0/sql"
88
)
99

10+
// partitioned is an embeddable helper that contains the methods for a table
11+
// that is partitioned by repository.
12+
type partitioned struct{}
13+
14+
func (partitioned) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
15+
return newRepositoryPartitionIter(ctx)
16+
}
17+
18+
func (partitioned) PartitionCount(ctx *sql.Context) (int64, error) {
19+
s, err := getSession(ctx)
20+
if err != nil {
21+
return 0, err
22+
}
23+
24+
return int64(len(s.Pool.repositories)), nil
25+
}
26+
27+
// RepositoryPartition represents a partition which is a repository id.
1028
type RepositoryPartition string
1129

30+
// Key implements the sql.Partition interface.
1231
func (p RepositoryPartition) Key() []byte {
1332
return []byte(p)
1433
}
@@ -41,6 +60,8 @@ func (i *repositoryPartitionIter) Close() error {
4160
return nil
4261
}
4362

63+
// ErrNoRepositoryPartition is returned when the partition is not a valid
64+
// repository partition.
4465
var ErrNoRepositoryPartition = errors.NewKind("%T not a valid repository partition")
4566

4667
func getPartitionRepo(ctx *sql.Context, p sql.Partition) (*Repository, error) {

ref_commits.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
type refCommitsTable struct {
16+
partitioned
1617
filters []sql.Expression
1718
index sql.IndexLookup
1819
}
@@ -59,10 +60,6 @@ func (t *refCommitsTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
5960
func (t *refCommitsTable) IndexLookup() sql.IndexLookup { return t.index }
6061
func (t *refCommitsTable) Filters() []sql.Expression { return t.filters }
6162

62-
func (t *refCommitsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
63-
return newRepositoryPartitionIter(ctx)
64-
}
65-
6663
func (t *refCommitsTable) PartitionRows(
6764
ctx *sql.Context,
6865
p sql.Partition,

references.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
type referencesTable struct {
17+
partitioned
1718
filters []sql.Expression
1819
index sql.IndexLookup
1920
}
@@ -62,10 +63,6 @@ func (r *referencesTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
6263
func (r *referencesTable) IndexLookup() sql.IndexLookup { return r.index }
6364
func (r *referencesTable) Filters() []sql.Expression { return r.filters }
6465

65-
func (r *referencesTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
66-
return newRepositoryPartitionIter(ctx)
67-
}
68-
6966
func (r *referencesTable) PartitionRows(
7067
ctx *sql.Context,
7168
p sql.Partition,

remotes.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type remotesTable struct {
13+
partitioned
1314
filters []sql.Expression
1415
index sql.IndexLookup
1516
}
@@ -61,10 +62,6 @@ func (r *remotesTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {
6162
func (r *remotesTable) IndexLookup() sql.IndexLookup { return r.index }
6263
func (r *remotesTable) Filters() []sql.Expression { return r.filters }
6364

64-
func (r *remotesTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
65-
return newRepositoryPartitionIter(ctx)
66-
}
67-
6865
func (r *remotesTable) PartitionRows(
6966
ctx *sql.Context,
7067
p sql.Partition,

0 commit comments

Comments
 (0)