Skip to content

Commit 1035f4f

Browse files
authored
Merge pull request #8508 from dolthub/taylor/read-dtables
Update more system tables for doltgres
2 parents 1144c7f + 2fbdd5b commit 1035f4f

15 files changed

+429
-327
lines changed

go/libraries/doltcore/doltdb/system_table.go

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ var getWriteableSystemTables = func() []string {
151151
var getGeneratedSystemTables = func() []string {
152152
return []string{
153153
GetBranchesTableName(),
154-
RemoteBranchesTableName,
154+
GetRemoteBranchesTableName(),
155155
GetLogTableName(),
156-
TableOfTablesInConflictName,
157-
TableOfTablesWithViolationsName,
158-
CommitsTableName,
159-
CommitAncestorsTableName,
156+
GetTableOfTablesInConflictName(),
157+
GetTableOfTablesWithViolationsName(),
158+
GetCommitsTableName(),
159+
GetCommitAncestorsTableName(),
160160
GetStatusTableName(),
161-
RemotesTableName,
161+
GetRemotesTableName(),
162162
}
163163
}
164164

@@ -252,11 +252,61 @@ var GetBranchesTableName = func() string {
252252
return BranchesTableName
253253
}
254254

255+
// GetColumnDiffTableName returns the column diff system table name
256+
var GetColumnDiffTableName = func() string {
257+
return ColumnDiffTableName
258+
}
259+
260+
// GetCommitAncestorsTableName returns the commit_ancestors system table name
261+
var GetCommitAncestorsTableName = func() string {
262+
return CommitAncestorsTableName
263+
}
264+
265+
// GetCommitsTableName returns the commits system table name
266+
var GetCommitsTableName = func() string {
267+
return CommitsTableName
268+
}
269+
270+
// GetTableOfTablesWithViolationsName returns the conflicts system table name
271+
var GetTableOfTablesInConflictName = func() string {
272+
return TableOfTablesInConflictName
273+
}
274+
275+
// GetTableOfTablesWithViolationsName returns the constraint violations system table name
276+
var GetTableOfTablesWithViolationsName = func() string {
277+
return TableOfTablesWithViolationsName
278+
}
279+
280+
// GetDiffTableName returns the diff system table name
281+
var GetDiffTableName = func() string {
282+
return DiffTableName
283+
}
284+
255285
// GetLogTableName returns the log system table name
256286
var GetLogTableName = func() string {
257287
return LogTableName
258288
}
259289

290+
// GetMergeStatusTableName returns the merge status system table name
291+
var GetMergeStatusTableName = func() string {
292+
return MergeStatusTableName
293+
}
294+
295+
// GetRemoteBranchesTableName returns the all-branches system table name
296+
var GetRemoteBranchesTableName = func() string {
297+
return RemoteBranchesTableName
298+
}
299+
300+
// GetRemotesTableName returns the remotes system table name
301+
var GetRemotesTableName = func() string {
302+
return RemotesTableName
303+
}
304+
305+
// GetSchemaConflictsTableName returns the schema conflicts system table name
306+
var GetSchemaConflictsTableName = func() string {
307+
return SchemaConflictsTableName
308+
}
309+
260310
// GetStatusTableName returns the status system table name.
261311
var GetStatusTableName = func() string {
262312
return StatusTableName
@@ -310,6 +360,7 @@ const (
310360
// TagsTableName is the tags table name
311361
TagsTableName = "dolt_tags"
312362

363+
// IgnoreTableName is the ignore table name
313364
IgnoreTableName = "dolt_ignore"
314365

315366
// RebaseTableName is the rebase system table name.

go/libraries/doltcore/sqle/database.go

Lines changed: 97 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -435,50 +435,104 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
435435
}
436436
}
437437

438-
dt, found = dtables.NewLogTable(ctx, db.Name(), db.ddb, head), true
438+
dt, found = dtables.NewLogTable(ctx, db.Name(), lwrName, db.ddb, head), true
439439
}
440-
case doltdb.DiffTableName:
441-
if head == nil {
442-
var err error
443-
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
444-
if err != nil {
445-
return nil, false, err
446-
}
440+
case doltdb.DiffTableName, doltdb.GetDiffTableName():
441+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
442+
if err != nil {
443+
return nil, false, err
447444
}
448-
449-
dt, found = dtables.NewUnscopedDiffTable(ctx, db.Name(), db.ddb, head), true
450-
case doltdb.ColumnDiffTableName:
451-
if head == nil {
452-
var err error
453-
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
454-
if err != nil {
455-
return nil, false, err
445+
if !resolve.UseSearchPath || isDoltgresSystemTable {
446+
if head == nil {
447+
var err error
448+
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
449+
if err != nil {
450+
return nil, false, err
451+
}
456452
}
453+
454+
dt, found = dtables.NewUnscopedDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
455+
}
456+
case doltdb.ColumnDiffTableName, doltdb.GetColumnDiffTableName():
457+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
458+
if err != nil {
459+
return nil, false, err
457460
}
461+
if !resolve.UseSearchPath || isDoltgresSystemTable {
462+
if head == nil {
463+
var err error
464+
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
465+
if err != nil {
466+
return nil, false, err
467+
}
468+
}
458469

459-
dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), db.ddb, head), true
460-
case doltdb.TableOfTablesInConflictName:
461-
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), db.ddb), true
462-
case doltdb.TableOfTablesWithViolationsName:
463-
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, root), true
464-
case doltdb.SchemaConflictsTableName:
465-
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
470+
dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
471+
}
472+
case doltdb.TableOfTablesInConflictName, doltdb.GetTableOfTablesInConflictName():
473+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
474+
if err != nil {
475+
return nil, false, err
476+
}
477+
if !resolve.UseSearchPath || isDoltgresSystemTable {
478+
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), lwrName, db.ddb), true
479+
}
480+
case doltdb.TableOfTablesWithViolationsName, doltdb.GetTableOfTablesWithViolationsName():
481+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
482+
if err != nil {
483+
return nil, false, err
484+
}
485+
if !resolve.UseSearchPath || isDoltgresSystemTable {
486+
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, lwrName, root), true
487+
}
488+
case doltdb.SchemaConflictsTableName, doltdb.GetSchemaConflictsTableName():
489+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
490+
if err != nil {
491+
return nil, false, err
492+
}
493+
if !resolve.UseSearchPath || isDoltgresSystemTable {
494+
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), lwrName, db.ddb), true
495+
}
466496
case doltdb.GetBranchesTableName(), doltdb.BranchesTableName:
467497
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
468498
if err != nil {
469499
return nil, false, err
470500
}
471501
if !resolve.UseSearchPath || isDoltgresSystemTable {
472-
dt, found = dtables.NewBranchesTable(ctx, db), true
473-
}
474-
case doltdb.RemoteBranchesTableName:
475-
dt, found = dtables.NewRemoteBranchesTable(ctx, db), true
476-
case doltdb.RemotesTableName:
477-
dt, found = dtables.NewRemotesTable(ctx, db.ddb), true
478-
case doltdb.CommitsTableName:
479-
dt, found = dtables.NewCommitsTable(ctx, db.Name(), db.ddb), true
480-
case doltdb.CommitAncestorsTableName:
481-
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), db.ddb), true
502+
dt, found = dtables.NewBranchesTable(ctx, db, lwrName), true
503+
}
504+
case doltdb.RemoteBranchesTableName, doltdb.GetRemoteBranchesTableName():
505+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
506+
if err != nil {
507+
return nil, false, err
508+
}
509+
if !resolve.UseSearchPath || isDoltgresSystemTable {
510+
dt, found = dtables.NewRemoteBranchesTable(ctx, db, lwrName), true
511+
}
512+
case doltdb.RemotesTableName, doltdb.GetRemotesTableName():
513+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
514+
if err != nil {
515+
return nil, false, err
516+
}
517+
if !resolve.UseSearchPath || isDoltgresSystemTable {
518+
dt, found = dtables.NewRemotesTable(ctx, db.ddb, lwrName), true
519+
}
520+
case doltdb.CommitsTableName, doltdb.GetCommitsTableName():
521+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
522+
if err != nil {
523+
return nil, false, err
524+
}
525+
if !resolve.UseSearchPath || isDoltgresSystemTable {
526+
dt, found = dtables.NewCommitsTable(ctx, db.Name(), lwrName, db.ddb), true
527+
}
528+
case doltdb.CommitAncestorsTableName, doltdb.GetCommitAncestorsTableName():
529+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
530+
if err != nil {
531+
return nil, false, err
532+
}
533+
if !resolve.UseSearchPath || isDoltgresSystemTable {
534+
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), lwrName, db.ddb), true
535+
}
482536
case doltdb.GetStatusTableName(), doltdb.StatusTableName:
483537
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
484538
if err != nil {
@@ -496,17 +550,23 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
496550
return nil, false, err
497551
}
498552

499-
dt, found = dtables.NewStatusTable(ctx, db.ddb, ws, adapter), true
553+
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, adapter), true
554+
}
555+
case doltdb.MergeStatusTableName, doltdb.GetMergeStatusTableName():
556+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
557+
if err != nil {
558+
return nil, false, err
559+
}
560+
if !resolve.UseSearchPath || isDoltgresSystemTable {
561+
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName(), lwrName), true
500562
}
501-
case doltdb.MergeStatusTableName:
502-
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
503563
case doltdb.GetTagsTableName(), doltdb.TagsTableName:
504564
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
505565
if err != nil {
506566
return nil, false, err
507567
}
508568
if !resolve.UseSearchPath || isDoltgresSystemTable {
509-
dt, found = dtables.NewTagsTable(ctx, db.ddb), true
569+
dt, found = dtables.NewTagsTable(ctx, lwrName, db.ddb), true
510570
}
511571
case dtables.AccessTableName:
512572
basCtx := branch_control.GetBranchAwareSession(ctx)

go/libraries/doltcore/sqle/dtables/branches_table.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ var _ sql.ReplaceableTable = (*BranchesTable)(nil)
3939

4040
// BranchesTable is the system table that accesses branches
4141
type BranchesTable struct {
42-
db dsess.SqlDatabase
43-
remote bool
42+
db dsess.SqlDatabase
43+
remote bool
44+
tableName string
4445
}
4546

4647
// NewBranchesTable creates a BranchesTable
47-
func NewBranchesTable(_ *sql.Context, db dsess.SqlDatabase) sql.Table {
48-
return &BranchesTable{db: db}
48+
func NewBranchesTable(_ *sql.Context, db dsess.SqlDatabase, tableName string) sql.Table {
49+
return &BranchesTable{db: db, tableName: tableName}
4950
}
5051

5152
// NewRemoteBranchesTable creates a BranchesTable with only remote refs
52-
func NewRemoteBranchesTable(_ *sql.Context, ddb dsess.SqlDatabase) sql.Table {
53-
return &BranchesTable{ddb, true}
53+
func NewRemoteBranchesTable(_ *sql.Context, ddb dsess.SqlDatabase, tableName string) sql.Table {
54+
return &BranchesTable{ddb, true, tableName}
5455
}
5556

5657
func (bt *BranchesTable) DataLength(ctx *sql.Context) (uint64, error) {
@@ -67,41 +68,28 @@ func (bt *BranchesTable) RowCount(_ *sql.Context) (uint64, bool, error) {
6768
}
6869

6970
// Name is a sql.Table interface function which returns the name of the table
70-
// which is defined by the function GetBranchesTableName()
7171
func (bt *BranchesTable) Name() string {
72-
if bt.remote {
73-
return doltdb.RemoteBranchesTableName
74-
}
75-
return doltdb.GetBranchesTableName()
72+
return bt.tableName
7673
}
7774

7875
// String is a sql.Table interface function which returns the name of the table
79-
// which is defined by the function GetBranchesTableName()
8076
func (bt *BranchesTable) String() string {
81-
if bt.remote {
82-
return doltdb.RemoteBranchesTableName
83-
}
84-
return doltdb.GetBranchesTableName()
77+
return bt.tableName
8578
}
8679

8780
// Schema is a sql.Table interface function that gets the sql.Schema of the branches system table
8881
func (bt *BranchesTable) Schema() sql.Schema {
89-
tableName := doltdb.GetBranchesTableName()
90-
if bt.remote {
91-
tableName = doltdb.RemoteBranchesTableName
92-
}
93-
9482
columns := []*sql.Column{
95-
{Name: "name", Type: types.Text, Source: tableName, PrimaryKey: true, Nullable: false, DatabaseSource: bt.db.Name()},
96-
{Name: "hash", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: false, DatabaseSource: bt.db.Name()},
97-
{Name: "latest_committer", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
98-
{Name: "latest_committer_email", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
99-
{Name: "latest_commit_date", Type: types.Datetime, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
100-
{Name: "latest_commit_message", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
83+
{Name: "name", Type: types.Text, Source: bt.tableName, PrimaryKey: true, Nullable: false, DatabaseSource: bt.db.Name()},
84+
{Name: "hash", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: false, DatabaseSource: bt.db.Name()},
85+
{Name: "latest_committer", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
86+
{Name: "latest_committer_email", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
87+
{Name: "latest_commit_date", Type: types.Datetime, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
88+
{Name: "latest_commit_message", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
10189
}
10290
if !bt.remote {
103-
columns = append(columns, &sql.Column{Name: "remote", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true})
104-
columns = append(columns, &sql.Column{Name: "branch", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true})
91+
columns = append(columns, &sql.Column{Name: "remote", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true})
92+
columns = append(columns, &sql.Column{Name: "branch", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true})
10593
}
10694
return columns
10795
}

0 commit comments

Comments
 (0)