Skip to content

Commit

Permalink
Merge pull request #8508 from dolthub/taylor/read-dtables
Browse files Browse the repository at this point in the history
Update more system tables for doltgres
  • Loading branch information
tbantle22 authored Oct 30, 2024
2 parents 1144c7f + 2fbdd5b commit 1035f4f
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 327 deletions.
63 changes: 57 additions & 6 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ var getWriteableSystemTables = func() []string {
var getGeneratedSystemTables = func() []string {
return []string{
GetBranchesTableName(),
RemoteBranchesTableName,
GetRemoteBranchesTableName(),
GetLogTableName(),
TableOfTablesInConflictName,
TableOfTablesWithViolationsName,
CommitsTableName,
CommitAncestorsTableName,
GetTableOfTablesInConflictName(),
GetTableOfTablesWithViolationsName(),
GetCommitsTableName(),
GetCommitAncestorsTableName(),
GetStatusTableName(),
RemotesTableName,
GetRemotesTableName(),
}
}

Expand Down Expand Up @@ -252,11 +252,61 @@ var GetBranchesTableName = func() string {
return BranchesTableName
}

// GetColumnDiffTableName returns the column diff system table name
var GetColumnDiffTableName = func() string {
return ColumnDiffTableName
}

// GetCommitAncestorsTableName returns the commit_ancestors system table name
var GetCommitAncestorsTableName = func() string {
return CommitAncestorsTableName
}

// GetCommitsTableName returns the commits system table name
var GetCommitsTableName = func() string {
return CommitsTableName
}

// GetTableOfTablesWithViolationsName returns the conflicts system table name
var GetTableOfTablesInConflictName = func() string {
return TableOfTablesInConflictName
}

// GetTableOfTablesWithViolationsName returns the constraint violations system table name
var GetTableOfTablesWithViolationsName = func() string {
return TableOfTablesWithViolationsName
}

// GetDiffTableName returns the diff system table name
var GetDiffTableName = func() string {
return DiffTableName
}

// GetLogTableName returns the log system table name
var GetLogTableName = func() string {
return LogTableName
}

// GetMergeStatusTableName returns the merge status system table name
var GetMergeStatusTableName = func() string {
return MergeStatusTableName
}

// GetRemoteBranchesTableName returns the all-branches system table name
var GetRemoteBranchesTableName = func() string {
return RemoteBranchesTableName
}

// GetRemotesTableName returns the remotes system table name
var GetRemotesTableName = func() string {
return RemotesTableName
}

// GetSchemaConflictsTableName returns the schema conflicts system table name
var GetSchemaConflictsTableName = func() string {
return SchemaConflictsTableName
}

// GetStatusTableName returns the status system table name.
var GetStatusTableName = func() string {
return StatusTableName
Expand Down Expand Up @@ -310,6 +360,7 @@ const (
// TagsTableName is the tags table name
TagsTableName = "dolt_tags"

// IgnoreTableName is the ignore table name
IgnoreTableName = "dolt_ignore"

// RebaseTableName is the rebase system table name.
Expand Down
134 changes: 97 additions & 37 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,50 +435,104 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
}
}

dt, found = dtables.NewLogTable(ctx, db.Name(), db.ddb, head), true
dt, found = dtables.NewLogTable(ctx, db.Name(), lwrName, db.ddb, head), true
}
case doltdb.DiffTableName:
if head == nil {
var err error
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
if err != nil {
return nil, false, err
}
case doltdb.DiffTableName, doltdb.GetDiffTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}

dt, found = dtables.NewUnscopedDiffTable(ctx, db.Name(), db.ddb, head), true
case doltdb.ColumnDiffTableName:
if head == nil {
var err error
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
if err != nil {
return nil, false, err
if !resolve.UseSearchPath || isDoltgresSystemTable {
if head == nil {
var err error
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
if err != nil {
return nil, false, err
}
}

dt, found = dtables.NewUnscopedDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
}
case doltdb.ColumnDiffTableName, doltdb.GetColumnDiffTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
if head == nil {
var err error
head, err = ds.GetHeadCommit(ctx, db.RevisionQualifiedName())
if err != nil {
return nil, false, err
}
}

dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), db.ddb, head), true
case doltdb.TableOfTablesInConflictName:
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), db.ddb), true
case doltdb.TableOfTablesWithViolationsName:
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, root), true
case doltdb.SchemaConflictsTableName:
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
}
case doltdb.TableOfTablesInConflictName, doltdb.GetTableOfTablesInConflictName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), lwrName, db.ddb), true
}
case doltdb.TableOfTablesWithViolationsName, doltdb.GetTableOfTablesWithViolationsName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, lwrName, root), true
}
case doltdb.SchemaConflictsTableName, doltdb.GetSchemaConflictsTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), lwrName, db.ddb), true
}
case doltdb.GetBranchesTableName(), doltdb.BranchesTableName:
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewBranchesTable(ctx, db), true
}
case doltdb.RemoteBranchesTableName:
dt, found = dtables.NewRemoteBranchesTable(ctx, db), true
case doltdb.RemotesTableName:
dt, found = dtables.NewRemotesTable(ctx, db.ddb), true
case doltdb.CommitsTableName:
dt, found = dtables.NewCommitsTable(ctx, db.Name(), db.ddb), true
case doltdb.CommitAncestorsTableName:
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), db.ddb), true
dt, found = dtables.NewBranchesTable(ctx, db, lwrName), true
}
case doltdb.RemoteBranchesTableName, doltdb.GetRemoteBranchesTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewRemoteBranchesTable(ctx, db, lwrName), true
}
case doltdb.RemotesTableName, doltdb.GetRemotesTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewRemotesTable(ctx, db.ddb, lwrName), true
}
case doltdb.CommitsTableName, doltdb.GetCommitsTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewCommitsTable(ctx, db.Name(), lwrName, db.ddb), true
}
case doltdb.CommitAncestorsTableName, doltdb.GetCommitAncestorsTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), lwrName, db.ddb), true
}
case doltdb.GetStatusTableName(), doltdb.StatusTableName:
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
Expand All @@ -496,17 +550,23 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
return nil, false, err
}

dt, found = dtables.NewStatusTable(ctx, db.ddb, ws, adapter), true
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, adapter), true
}
case doltdb.MergeStatusTableName, doltdb.GetMergeStatusTableName():
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName(), lwrName), true
}
case doltdb.MergeStatusTableName:
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
case doltdb.GetTagsTableName(), doltdb.TagsTableName:
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
return nil, false, err
}
if !resolve.UseSearchPath || isDoltgresSystemTable {
dt, found = dtables.NewTagsTable(ctx, db.ddb), true
dt, found = dtables.NewTagsTable(ctx, lwrName, db.ddb), true
}
case dtables.AccessTableName:
basCtx := branch_control.GetBranchAwareSession(ctx)
Expand Down
46 changes: 17 additions & 29 deletions go/libraries/doltcore/sqle/dtables/branches_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ var _ sql.ReplaceableTable = (*BranchesTable)(nil)

// BranchesTable is the system table that accesses branches
type BranchesTable struct {
db dsess.SqlDatabase
remote bool
db dsess.SqlDatabase
remote bool
tableName string
}

// NewBranchesTable creates a BranchesTable
func NewBranchesTable(_ *sql.Context, db dsess.SqlDatabase) sql.Table {
return &BranchesTable{db: db}
func NewBranchesTable(_ *sql.Context, db dsess.SqlDatabase, tableName string) sql.Table {
return &BranchesTable{db: db, tableName: tableName}
}

// NewRemoteBranchesTable creates a BranchesTable with only remote refs
func NewRemoteBranchesTable(_ *sql.Context, ddb dsess.SqlDatabase) sql.Table {
return &BranchesTable{ddb, true}
func NewRemoteBranchesTable(_ *sql.Context, ddb dsess.SqlDatabase, tableName string) sql.Table {
return &BranchesTable{ddb, true, tableName}
}

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

// Name is a sql.Table interface function which returns the name of the table
// which is defined by the function GetBranchesTableName()
func (bt *BranchesTable) Name() string {
if bt.remote {
return doltdb.RemoteBranchesTableName
}
return doltdb.GetBranchesTableName()
return bt.tableName
}

// String is a sql.Table interface function which returns the name of the table
// which is defined by the function GetBranchesTableName()
func (bt *BranchesTable) String() string {
if bt.remote {
return doltdb.RemoteBranchesTableName
}
return doltdb.GetBranchesTableName()
return bt.tableName
}

// Schema is a sql.Table interface function that gets the sql.Schema of the branches system table
func (bt *BranchesTable) Schema() sql.Schema {
tableName := doltdb.GetBranchesTableName()
if bt.remote {
tableName = doltdb.RemoteBranchesTableName
}

columns := []*sql.Column{
{Name: "name", Type: types.Text, Source: tableName, PrimaryKey: true, Nullable: false, DatabaseSource: bt.db.Name()},
{Name: "hash", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: false, DatabaseSource: bt.db.Name()},
{Name: "latest_committer", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_committer_email", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_commit_date", Type: types.Datetime, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_commit_message", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "name", Type: types.Text, Source: bt.tableName, PrimaryKey: true, Nullable: false, DatabaseSource: bt.db.Name()},
{Name: "hash", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: false, DatabaseSource: bt.db.Name()},
{Name: "latest_committer", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_committer_email", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_commit_date", Type: types.Datetime, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
{Name: "latest_commit_message", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: bt.db.Name()},
}
if !bt.remote {
columns = append(columns, &sql.Column{Name: "remote", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true})
columns = append(columns, &sql.Column{Name: "branch", Type: types.Text, Source: tableName, PrimaryKey: false, Nullable: true})
columns = append(columns, &sql.Column{Name: "remote", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true})
columns = append(columns, &sql.Column{Name: "branch", Type: types.Text, Source: bt.tableName, PrimaryKey: false, Nullable: true})
}
return columns
}
Expand Down
Loading

0 comments on commit 1035f4f

Please sign in to comment.