Skip to content

Commit ecf5425

Browse files
committed
Update more system tables for doltgres, fix column aliases
1 parent b4fda6b commit ecf5425

File tree

11 files changed

+298
-243
lines changed

11 files changed

+298
-243
lines changed

go/libraries/doltcore/doltdb/system_table.go

Lines changed: 34 additions & 4 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(),
156156
TableOfTablesInConflictName,
157157
TableOfTablesWithViolationsName,
158-
CommitsTableName,
159-
CommitAncestorsTableName,
158+
GetCommitsTableName(),
159+
GetCommitAncestorsTableName(),
160160
GetStatusTableName(),
161-
RemotesTableName,
161+
GetRemotesTableName(),
162162
}
163163
}
164164

@@ -252,11 +252,41 @@ 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+
// GetDiffTableName returns the diff system table name
271+
var GetDiffTableName = func() string {
272+
return DiffTableName
273+
}
274+
255275
// GetLogTableName returns the log system table name
256276
var GetLogTableName = func() string {
257277
return LogTableName
258278
}
259279

280+
// GetRemoteBranchesTableName returns the all-branches system table name
281+
var GetRemoteBranchesTableName = func() string {
282+
return RemoteBranchesTableName
283+
}
284+
285+
// GetRemotesTableName returns the remotes system table name
286+
var GetRemotesTableName = func() string {
287+
return RemotesTableName
288+
}
289+
260290
// GetStatusTableName returns the status system table name.
261291
var GetStatusTableName = func() string {
262292
return StatusTableName

go/libraries/doltcore/sqle/database.go

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -435,28 +435,40 @@ 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
457455
}
456+
case doltdb.ColumnDiffTableName, doltdb.GetColumnDiffTableName():
457+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
458+
if err != nil {
459+
return nil, false, err
460+
}
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
470+
dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
471+
}
460472
case doltdb.TableOfTablesInConflictName:
461473
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), db.ddb), true
462474
case doltdb.TableOfTablesWithViolationsName:
@@ -469,16 +481,40 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
469481
return nil, false, err
470482
}
471483
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
484+
dt, found = dtables.NewBranchesTable(ctx, db, lwrName), true
485+
}
486+
case doltdb.RemoteBranchesTableName, doltdb.GetRemoteBranchesTableName():
487+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
488+
if err != nil {
489+
return nil, false, err
490+
}
491+
if !resolve.UseSearchPath || isDoltgresSystemTable {
492+
dt, found = dtables.NewRemoteBranchesTable(ctx, db, lwrName), true
493+
}
494+
case doltdb.RemotesTableName, doltdb.GetRemotesTableName():
495+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
496+
if err != nil {
497+
return nil, false, err
498+
}
499+
if !resolve.UseSearchPath || isDoltgresSystemTable {
500+
dt, found = dtables.NewRemotesTable(ctx, db.ddb, lwrName), true
501+
}
502+
case doltdb.CommitsTableName, doltdb.GetCommitsTableName():
503+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
504+
if err != nil {
505+
return nil, false, err
506+
}
507+
if !resolve.UseSearchPath || isDoltgresSystemTable {
508+
dt, found = dtables.NewCommitsTable(ctx, db.Name(), lwrName, db.ddb), true
509+
}
510+
case doltdb.CommitAncestorsTableName, doltdb.GetCommitAncestorsTableName():
511+
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
512+
if err != nil {
513+
return nil, false, err
514+
}
515+
if !resolve.UseSearchPath || isDoltgresSystemTable {
516+
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), lwrName, db.ddb), true
517+
}
482518
case doltdb.GetStatusTableName(), doltdb.StatusTableName:
483519
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
484520
if err != nil {
@@ -496,7 +532,7 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
496532
return nil, false, err
497533
}
498534

499-
dt, found = dtables.NewStatusTable(ctx, db.ddb, ws, adapter), true
535+
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, adapter), true
500536
}
501537
case doltdb.MergeStatusTableName:
502538
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
@@ -506,7 +542,7 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
506542
return nil, false, err
507543
}
508544
if !resolve.UseSearchPath || isDoltgresSystemTable {
509-
dt, found = dtables.NewTagsTable(ctx, db.ddb), true
545+
dt, found = dtables.NewTagsTable(ctx, lwrName, db.ddb), true
510546
}
511547
case dtables.AccessTableName:
512548
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
}

go/libraries/doltcore/sqle/dtables/column_diff_table.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const columnDiffDefaultRowCount = 100
4141
// changed in each commit, across all branches.
4242
type ColumnDiffTable struct {
4343
dbName string
44+
tableName string
4445
ddb *doltdb.DoltDB
4546
head *doltdb.Commit
4647
partitionFilters []sql.Expression
@@ -53,14 +54,14 @@ var _ sql.StatisticsTable = (*ColumnDiffTable)(nil)
5354
// var _ sql.IndexAddressable = (*ColumnDiffTable)(nil)
5455

5556
// NewColumnDiffTable creates an ColumnDiffTable
56-
func NewColumnDiffTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Table {
57-
return &ColumnDiffTable{dbName: dbName, ddb: ddb, head: head}
57+
func NewColumnDiffTable(_ *sql.Context, dbName, tableName string, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Table {
58+
return &ColumnDiffTable{dbName: dbName, tableName: tableName, ddb: ddb, head: head}
5859
}
5960

6061
// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
61-
// ColumnDiffTableName
62+
// GetColumnDiffTableName()
6263
func (dt *ColumnDiffTable) Name() string {
63-
return doltdb.ColumnDiffTableName
64+
return dt.tableName
6465
}
6566

6667
func (dt *ColumnDiffTable) DataLength(ctx *sql.Context) (uint64, error) {
@@ -77,22 +78,22 @@ func (dt *ColumnDiffTable) RowCount(_ *sql.Context) (uint64, bool, error) {
7778
}
7879

7980
// String is a sql.Table interface function which returns the name of the table which is defined by the constant
80-
// ColumnDiffTableName
81+
// GetColumnDiffTableName()
8182
func (dt *ColumnDiffTable) String() string {
82-
return doltdb.ColumnDiffTableName
83+
return dt.tableName
8384
}
8485

8586
// Schema is a sql.Table interface function that returns the sql.Schema for this system table.
8687
func (dt *ColumnDiffTable) Schema() sql.Schema {
8788
return []*sql.Column{
88-
{Name: "commit_hash", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
89-
{Name: "table_name", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
90-
{Name: "column_name", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
91-
{Name: "committer", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
92-
{Name: "email", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
93-
{Name: "date", Type: types.Datetime, Source: doltdb.ColumnDiffTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
94-
{Name: "message", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
95-
{Name: "diff_type", Type: types.Text, Source: doltdb.ColumnDiffTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
89+
{Name: "commit_hash", Type: types.Text, Source: dt.tableName, PrimaryKey: true, DatabaseSource: dt.dbName},
90+
{Name: "table_name", Type: types.Text, Source: dt.tableName, PrimaryKey: true, DatabaseSource: dt.dbName},
91+
{Name: "column_name", Type: types.Text, Source: dt.tableName, PrimaryKey: true, DatabaseSource: dt.dbName},
92+
{Name: "committer", Type: types.Text, Source: dt.tableName, PrimaryKey: false, DatabaseSource: dt.dbName},
93+
{Name: "email", Type: types.Text, Source: dt.tableName, PrimaryKey: false, DatabaseSource: dt.dbName},
94+
{Name: "date", Type: types.Datetime, Source: dt.tableName, PrimaryKey: false, DatabaseSource: dt.dbName},
95+
{Name: "message", Type: types.Text, Source: dt.tableName, PrimaryKey: false, DatabaseSource: dt.dbName},
96+
{Name: "diff_type", Type: types.Text, Source: dt.tableName, PrimaryKey: false, DatabaseSource: dt.dbName},
9697
}
9798
}
9899

@@ -637,7 +638,7 @@ func calculateColSchemaDiff(toCols *schema.ColCollection, fromCols *schema.ColCo
637638
}
638639

639640
if fromCols != nil {
640-
for tag, _ := range fromColTags {
641+
for tag := range fromColTags {
641642
// all remaining tags are columns not in toColumnTags, i.e. dropped columns
642643
droppedCols = append(droppedCols, fromCols.TagToCol[tag].Name)
643644
allCols = append(allCols, fromCols.TagToCol[tag].Name)

0 commit comments

Comments
 (0)