Skip to content

Commit ad541d7

Browse files
committed
Clean up
1 parent 674d29f commit ad541d7

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

go/libraries/doltcore/sqle/database.go

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -314,28 +314,6 @@ func (db Database) GetTableInsensitiveAsOf(ctx *sql.Context, tableName string, a
314314
}
315315
}
316316

317-
// isDoltSystemTable checks if the current table is a dolt system table. If
318-
// using the search path, also checks that dolt is the current schema or exists
319-
// on the search path.
320-
func (db Database) isDoltSystemTable(ctx *sql.Context, tableName string) bool {
321-
if doltdb.HasDoltPrefix(tableName) || !resolve.UseSearchPath || db.schemaName == "dolt" {
322-
return true
323-
}
324-
325-
if db.schemaName == "" {
326-
schemasToSearch, err := resolve.SearchPath(ctx)
327-
if err != nil {
328-
return false
329-
}
330-
for _, schemaName := range schemasToSearch {
331-
if schemaName == "dolt" {
332-
return true
333-
}
334-
}
335-
}
336-
return false
337-
}
338-
339317
func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds *dsess.DoltSession, root doltdb.RootValue, tblName string, asOf interface{}) (sql.Table, bool, error) {
340318
lwrName := strings.ToLower(tblName)
341319

@@ -441,10 +419,14 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
441419

442420
var dt sql.Table
443421
found := false
422+
tname := doltdb.TableName{Name: lwrName, Schema: db.schemaName}
444423
switch lwrName {
445424
case doltdb.GetLogTableName(), doltdb.LogTableName:
446-
// TODO: This should be moved once all the system tables are moved to the dolt schema
447-
if db.isDoltSystemTable(ctx, lwrName) {
425+
systemTable, err := resolve.SystemTable(ctx, tname, root)
426+
if err != nil {
427+
return nil, false, err
428+
}
429+
if systemTable {
448430
if head == nil {
449431
var err error
450432
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
@@ -482,8 +464,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
482464
case doltdb.SchemaConflictsTableName:
483465
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
484466
case doltdb.GetBranchesTableName(), doltdb.BranchesTableName:
485-
// TODO: This should be moved once all the system tables are moved to the dolt schema
486-
if db.isDoltSystemTable(ctx, lwrName) {
467+
systemTable, err := resolve.SystemTable(ctx, tname, root)
468+
if err != nil {
469+
return nil, false, err
470+
}
471+
if systemTable {
487472
dt, found = dtables.NewBranchesTable(ctx, db), true
488473
}
489474
case doltdb.RemoteBranchesTableName:
@@ -495,8 +480,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
495480
case doltdb.CommitAncestorsTableName:
496481
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), db.ddb), true
497482
case doltdb.GetStatusTableName(), doltdb.StatusTableName:
498-
// TODO: This should be moved once all the system tables are moved to the dolt schema
499-
if db.isDoltSystemTable(ctx, lwrName) {
483+
systemTable, err := resolve.SystemTable(ctx, tname, root)
484+
if err != nil {
485+
return nil, false, err
486+
}
487+
if systemTable {
500488
sess := dsess.DSessFromSess(ctx.Session)
501489
adapter := dsess.NewSessionStateAdapter(
502490
sess, db.RevisionQualifiedName(),
@@ -513,8 +501,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
513501
case doltdb.MergeStatusTableName:
514502
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
515503
case doltdb.GetTagsTableName(), doltdb.TagsTableName:
516-
// TODO: This should be moved once all the system tables are moved to the dolt schema
517-
if db.isDoltSystemTable(ctx, lwrName) {
504+
systemTable, err := resolve.SystemTable(ctx, tname, root)
505+
if err != nil {
506+
return nil, false, err
507+
}
508+
if systemTable {
518509
dt, found = dtables.NewTagsTable(ctx, db.ddb), true
519510
}
520511
case dtables.AccessTableName:
@@ -543,8 +534,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
543534
dt, found = dtables.NewIgnoreTable(ctx, versionableTable), true
544535
}
545536
case doltdb.GetDocTableName(), doltdb.DocTableName:
546-
// TODO: This should be moved once all the system tables are moved to the dolt schema
547-
if db.isDoltSystemTable(ctx, lwrName) {
537+
systemTable, err := resolve.SystemTable(ctx, tname, root)
538+
if err != nil {
539+
return nil, false, err
540+
}
541+
if systemTable {
548542
if resolve.UseSearchPath && lwrName == doltdb.DocTableName {
549543
db.schemaName = "dolt"
550544
}

go/libraries/doltcore/sqle/resolve/resolve_tables.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func TableWithSearchPath(
7878
continue
7979
}
8080

81-
// TODO: what schema name do we use for system tables?
8281
candidate := doltdb.TableName{Name: correctedTableName, Schema: schemaName}
8382
tbl, ok, err := root.GetTable(ctx, candidate)
8483
if err != nil {

go/libraries/doltcore/sqle/resolve/search_path.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,36 @@ func FirstExistingSchemaOnSearchPath(ctx *sql.Context, root doltdb.RootValue) (s
7878

7979
return schemaName, nil
8080
}
81+
82+
// SystemTable returns whether a table is a system table or not
83+
func SystemTable(ctx *sql.Context, tableName doltdb.TableName, root doltdb.RootValue) (bool, error) {
84+
if doltdb.HasDoltPrefix(tableName.Name) || !UseSearchPath || tableName.Schema == "dolt" {
85+
return true, nil
86+
}
87+
88+
if tableName.Schema == "" {
89+
schemasToSearch, err := SearchPath(ctx)
90+
if err != nil {
91+
return false, nil
92+
}
93+
for _, schemaName := range schemasToSearch {
94+
if schemaName != "dolt" {
95+
tablesInSchema, err := root.GetTableNames(ctx, schemaName)
96+
if err != nil {
97+
return false, err
98+
}
99+
for _, table := range tablesInSchema {
100+
if table == tableName.Name {
101+
return false, nil
102+
}
103+
}
104+
}
105+
106+
if schemaName == "dolt" {
107+
return true, nil
108+
}
109+
}
110+
}
111+
112+
return false, nil
113+
}

0 commit comments

Comments
 (0)