Skip to content

Commit 48d30c0

Browse files
authored
Merge branch 'master' into circleci
2 parents 188178c + 4fdf2ce commit 48d30c0

14 files changed

+227
-26
lines changed

blobs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ var _ Squashable = (*blobsTable)(nil)
5050
func (blobsTable) isSquashable() {}
5151
func (blobsTable) isGitbaseTable() {}
5252

53-
func (blobsTable) String() string {
54-
return printTable(BlobsTableName, BlobsSchema)
53+
func (r blobsTable) String() string {
54+
return printTable(
55+
BlobsTableName,
56+
BlobsSchema,
57+
r.projection,
58+
r.filters,
59+
r.index,
60+
)
5561
}
5662

5763
func (blobsTable) Name() string {

commit_blobs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ var _ Squashable = (*blobsTable)(nil)
3333
func (commitBlobsTable) isSquashable() {}
3434
func (commitBlobsTable) isGitbaseTable() {}
3535

36-
func (commitBlobsTable) String() string {
37-
return printTable(CommitBlobsTableName, CommitBlobsSchema)
36+
func (t commitBlobsTable) String() string {
37+
return printTable(
38+
CommitBlobsTableName,
39+
CommitBlobsSchema,
40+
nil,
41+
t.filters,
42+
t.index,
43+
)
3844
}
3945

4046
func (commitBlobsTable) Name() string { return CommitBlobsTableName }

commit_files.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ var _ Squashable = (*commitFilesTable)(nil)
3838
func (commitFilesTable) isSquashable() {}
3939
func (commitFilesTable) isGitbaseTable() {}
4040

41-
func (commitFilesTable) String() string {
42-
return printTable(CommitFilesTableName, CommitFilesSchema)
41+
func (t commitFilesTable) String() string {
42+
return printTable(
43+
CommitFilesTableName,
44+
CommitFilesSchema,
45+
nil,
46+
t.filters,
47+
t.index,
48+
)
4349
}
4450

4551
func (commitFilesTable) Name() string { return CommitFilesTableName }

commit_trees.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ var _ Squashable = (*commitTreesTable)(nil)
3434
func (commitTreesTable) isSquashable() {}
3535
func (commitTreesTable) isGitbaseTable() {}
3636

37-
func (commitTreesTable) String() string {
38-
return printTable(CommitTreesTableName, CommitTreesSchema)
37+
func (t commitTreesTable) String() string {
38+
return printTable(
39+
CommitTreesTableName,
40+
CommitTreesSchema,
41+
nil,
42+
t.filters,
43+
t.index,
44+
)
3945
}
4046

4147
func (commitTreesTable) Name() string { return CommitTreesTableName }

commits.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ var _ Squashable = (*commitsTable)(nil)
4040
func (commitsTable) isSquashable() {}
4141
func (commitsTable) isGitbaseTable() {}
4242

43-
func (commitsTable) String() string {
44-
return printTable(CommitsTableName, CommitsSchema)
43+
func (r commitsTable) String() string {
44+
return printTable(
45+
CommitsTableName,
46+
CommitsSchema,
47+
nil,
48+
r.filters,
49+
r.index,
50+
)
4551
}
4652

4753
func (commitsTable) Name() string {

files.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ func (filesTable) handledColumns() []string {
149149
return []string{"repository_id", "tree_hash", "blob_hash", "file_path"}
150150
}
151151

152-
func (filesTable) String() string {
153-
return printTable(FilesTableName, FilesSchema)
152+
func (r filesTable) String() string {
153+
return printTable(
154+
FilesTableName,
155+
FilesSchema,
156+
r.projection,
157+
r.filters,
158+
r.index,
159+
)
154160
}
155161

156162
// IndexKeyValues implements the sql.IndexableTable interface.

internal/rule/squashjoins.go

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,23 @@ func buildSquashedTable(
392392
}
393393
case nil:
394394
var f sql.Expression
395+
var refIt gitbase.RefsIter
396+
397+
if index == nil {
398+
f, filters, err = transferFilters(
399+
filters,
400+
gitbase.RefCommitsTableName,
401+
gitbase.ReferencesTableName,
402+
gitbase.RefsSchema,
403+
"ref_name", "repository_id",
404+
)
405+
if err != nil {
406+
return nil, err
407+
}
408+
409+
refIt = gitbase.NewAllRefsIter(f, true)
410+
}
411+
395412
f, filters, err = filtersForTable(
396413
gitbase.RefCommitsTableName,
397414
filters,
@@ -404,7 +421,7 @@ func buildSquashedTable(
404421
if index != nil {
405422
iter = gitbase.NewIndexRefCommitsIter(index, f)
406423
} else {
407-
iter = gitbase.NewAllRefCommitsIter(f)
424+
iter = gitbase.NewRefRefCommitsIter(refIt, f)
408425
}
409426
default:
410427
addUnsquashable(gitbase.RefCommitsTableName)
@@ -1141,6 +1158,35 @@ func filtersForTables(
11411158
return
11421159
}
11431160

1161+
func filtersForColumns(
1162+
filters []sql.Expression,
1163+
table string,
1164+
columns ...string,
1165+
) (columnFilters []sql.Expression, remaining []sql.Expression) {
1166+
var fTable []sql.Expression
1167+
fTable, remaining = filtersForTables(filters, table)
1168+
1169+
for _, f := range fTable {
1170+
valid := true
1171+
expression.Inspect(f, func(e sql.Expression) bool {
1172+
gf, ok := e.(*expression.GetField)
1173+
if ok && !stringInSlice(columns, gf.Name()) {
1174+
valid = false
1175+
return false
1176+
}
1177+
1178+
return true
1179+
})
1180+
1181+
if valid {
1182+
columnFilters = append(columnFilters, f)
1183+
} else {
1184+
remaining = append(remaining, f)
1185+
}
1186+
}
1187+
1188+
return
1189+
}
11441190
func stringInSlice(strs []string, str string) bool {
11451191
for _, s := range strs {
11461192
if s == str {
@@ -1572,6 +1618,51 @@ func fixFieldIndexes(e sql.Expression, schema sql.Schema) (sql.Expression, error
15721618
})
15731619
}
15741620

1621+
func transferFilters(
1622+
filters []sql.Expression,
1623+
from, to string,
1624+
schema sql.Schema,
1625+
columns ...string,
1626+
) (sql.Expression, []sql.Expression, error) {
1627+
f, r := filtersForColumns(filters, from, columns...)
1628+
fixed, err := fixFieldTable(expression.JoinAnd(f...), to, schema)
1629+
if err != nil {
1630+
return nil, nil, err
1631+
}
1632+
1633+
return fixed, r, err
1634+
}
1635+
1636+
func fixFieldTable(
1637+
e sql.Expression,
1638+
table string,
1639+
schema sql.Schema,
1640+
) (sql.Expression, error) {
1641+
if e == nil {
1642+
return nil, nil
1643+
}
1644+
return e.TransformUp(func(e sql.Expression) (sql.Expression, error) {
1645+
gf, ok := e.(*expression.GetField)
1646+
if !ok {
1647+
return e, nil
1648+
}
1649+
1650+
for idx, col := range schema {
1651+
if gf.Name() == col.Name {
1652+
return expression.NewGetFieldWithTable(
1653+
idx,
1654+
gf.Type(),
1655+
table,
1656+
gf.Name(),
1657+
gf.IsNullable(),
1658+
), nil
1659+
}
1660+
}
1661+
1662+
return nil, analyzer.ErrColumnTableNotFound.New(gf.Table(), gf.Name())
1663+
})
1664+
}
1665+
15751666
func filterDiff(a, b []sql.Expression) []sql.Expression {
15761667
var result []sql.Expression
15771668

ref_commits.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ var _ Squashable = (*refCommitsTable)(nil)
3737
func (refCommitsTable) isSquashable() {}
3838
func (refCommitsTable) isGitbaseTable() {}
3939

40-
func (refCommitsTable) String() string {
41-
return printTable(RefCommitsTableName, RefCommitsSchema)
40+
func (t refCommitsTable) String() string {
41+
return printTable(
42+
RefCommitsTableName,
43+
RefCommitsSchema,
44+
nil,
45+
t.filters,
46+
t.index,
47+
)
4248
}
4349

4450
func (refCommitsTable) Name() string { return RefCommitsTableName }

references.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ func (referencesTable) isSquashable() {}
3636
func (referencesTable) isGitbaseTable() {}
3737

3838
func (r referencesTable) String() string {
39-
return printTable(ReferencesTableName, RefsSchema)
39+
return printTable(
40+
ReferencesTableName,
41+
RefsSchema,
42+
nil,
43+
r.filters,
44+
r.index,
45+
)
4046
}
4147

4248
func (referencesTable) Name() string {

remotes.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ func (remotesTable) Schema() sql.Schema {
4444
}
4545

4646
func (r remotesTable) String() string {
47-
return printTable(RemotesTableName, RemotesSchema)
47+
return printTable(
48+
RemotesTableName,
49+
RemotesSchema,
50+
nil,
51+
r.filters,
52+
r.index,
53+
)
4854
}
4955

5056
func (r *remotesTable) WithFilters(filters []sql.Expression) sql.Table {

0 commit comments

Comments
 (0)