Skip to content

Commit

Permalink
More system tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Oct 30, 2024
1 parent ecf5425 commit 2fbdd5b
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 84 deletions.
25 changes: 23 additions & 2 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ var getGeneratedSystemTables = func() []string {
GetBranchesTableName(),
GetRemoteBranchesTableName(),
GetLogTableName(),
TableOfTablesInConflictName,
TableOfTablesWithViolationsName,
GetTableOfTablesInConflictName(),
GetTableOfTablesWithViolationsName(),
GetCommitsTableName(),
GetCommitAncestorsTableName(),
GetStatusTableName(),
Expand Down Expand Up @@ -267,6 +267,16 @@ 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
Expand All @@ -277,6 +287,11 @@ 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
Expand All @@ -287,6 +302,11 @@ 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 @@ -340,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
40 changes: 32 additions & 8 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,30 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds

dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), lwrName, 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
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 {
Expand Down Expand Up @@ -534,8 +552,14 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds

dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, adapter), true
}
case doltdb.MergeStatusTableName:
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), 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.GetTagsTableName(), doltdb.TagsTableName:
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
if err != nil {
Expand Down
35 changes: 18 additions & 17 deletions go/libraries/doltcore/sqle/dtables/merge_status_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,39 @@ import (
// MergeStatusTable is a sql.Table implementation that implements a system table
// which shows information about an active merge.
type MergeStatusTable struct {
dbName string
dbName string
tableName string
}

func (s MergeStatusTable) Name() string {
return doltdb.MergeStatusTableName
func (mst MergeStatusTable) Name() string {
return mst.tableName
}

func (s MergeStatusTable) String() string {
return doltdb.MergeStatusTableName
func (mst MergeStatusTable) String() string {
return mst.tableName
}

func (s MergeStatusTable) Schema() sql.Schema {
func (mst MergeStatusTable) Schema() sql.Schema {
return []*sql.Column{
{Name: "is_merging", Type: types.Boolean, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: false, DatabaseSource: s.dbName},
{Name: "source", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
{Name: "source_commit", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
{Name: "target", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
{Name: "unmerged_tables", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
{Name: "is_merging", Type: types.Boolean, Source: mst.tableName, PrimaryKey: false, Nullable: false, DatabaseSource: mst.dbName},
{Name: "source", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
{Name: "source_commit", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
{Name: "target", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
{Name: "unmerged_tables", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
}
}

func (s MergeStatusTable) Collation() sql.CollationID {
func (mst MergeStatusTable) Collation() sql.CollationID {
return sql.Collation_Default
}

func (s MergeStatusTable) Partitions(*sql.Context) (sql.PartitionIter, error) {
func (mst MergeStatusTable) Partitions(*sql.Context) (sql.PartitionIter, error) {
return index.SinglePartitionIterFromNomsMap(nil), nil
}

func (s MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.RowIter, error) {
func (mst MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.RowIter, error) {
sesh := dsess.DSessFromSess(ctx.Session)
ws, err := sesh.WorkingSet(ctx, s.dbName)
ws, err := sesh.WorkingSet(ctx, mst.dbName)
if err != nil {
return nil, err
}
Expand All @@ -69,8 +70,8 @@ func (s MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.
}

// NewMergeStatusTable creates a StatusTable
func NewMergeStatusTable(dbName string) sql.Table {
return &MergeStatusTable{dbName}
func NewMergeStatusTable(dbName, tableName string) sql.Table {
return &MergeStatusTable{dbName, tableName}
}

// MergeStatusIter is a sql.RowItr implementation which iterates over each commit as if it's a row in the table.
Expand Down
63 changes: 32 additions & 31 deletions go/libraries/doltcore/sqle/dtables/schema_conflicts_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,70 @@ var _ sql.Table = (*SchemaConflictsTable)(nil)

// SchemaConflictsTable is a sql.Table implementation that implements a system table which shows the current conflicts
type SchemaConflictsTable struct {
dbName string
ddb *doltdb.DoltDB
dbName string
tableName string
ddb *doltdb.DoltDB
}

// NewSchemaConflictsTable creates a SchemaConflictsTable
func NewSchemaConflictsTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
return &SchemaConflictsTable{dbName: dbName, ddb: ddb}
func NewSchemaConflictsTable(_ *sql.Context, dbName, tableName string, ddb *doltdb.DoltDB) sql.Table {
return &SchemaConflictsTable{dbName: dbName, tableName: tableName, ddb: ddb}
}

// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
// SchemaConflictsTableName
func (dt *SchemaConflictsTable) Name() string {
return doltdb.SchemaConflictsTableName
// Name is a sql.Table interface function which returns the name of the table
func (sct *SchemaConflictsTable) Name() string {
return sct.tableName
}

// String is a sql.Table interface function which returns the name of the table which is defined by the constant
// SchemaConflictsTableName
func (dt *SchemaConflictsTable) String() string {
return doltdb.SchemaConflictsTableName
// String is a sql.Table interface function which returns the name of the table
func (sct *SchemaConflictsTable) String() string {
return sct.tableName
}

// Schema is a sql.Table interface function that gets the sql.Schema of the log system table.
func (dt *SchemaConflictsTable) Schema() sql.Schema {
func (sct *SchemaConflictsTable) Schema() sql.Schema {
return []*sql.Column{
{Name: "table_name", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
{Name: "base_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "our_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "their_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "description", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "table_name", Type: types.Text, Source: sct.tableName, PrimaryKey: true, DatabaseSource: sct.dbName},
{Name: "base_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
{Name: "our_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
{Name: "their_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
{Name: "description", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
}
}

// Collation implements the sql.Table interface.
func (dt *SchemaConflictsTable) Collation() sql.CollationID {
func (sct *SchemaConflictsTable) Collation() sql.CollationID {
return sql.Collation_Default
}

// Partitions is a sql.Table interface function that returns a partition of the data. Conflict data for all tables exists in a single partition.
func (dt *SchemaConflictsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
func (sct *SchemaConflictsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
sess := dsess.DSessFromSess(ctx.Session)
ws, err := sess.WorkingSet(ctx, dt.dbName)
ws, err := sess.WorkingSet(ctx, sct.dbName)
if err != nil {
return nil, err
}
dbd, _ := sess.GetDbData(ctx, dt.dbName)
dbd, _ := sess.GetDbData(ctx, sct.dbName)

if ws.MergeState() == nil || !ws.MergeState().HasSchemaConflicts() {
return sql.PartitionsToPartitionIter(), nil
}

head, err := sess.GetHeadCommit(ctx, dt.dbName)
head, err := sess.GetHeadCommit(ctx, sct.dbName)
if err != nil {
return nil, err
}

return sql.PartitionsToPartitionIter(schemaConflictsPartition{
state: ws.MergeState(),
head: head,
ddb: dbd.Ddb,
tableName: sct.tableName,
state: ws.MergeState(),
head: head,
ddb: dbd.Ddb,
}), nil
}

// PartitionRows is a sql.Table interface function that gets a row iterator for a partition
func (dt *SchemaConflictsTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
func (sct *SchemaConflictsTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
p, ok := part.(schemaConflictsPartition)
if !ok {
return nil, errors.New("unexpected partition for schema conflicts table")
Expand Down Expand Up @@ -136,13 +136,14 @@ func (dt *SchemaConflictsTable) PartitionRows(ctx *sql.Context, part sql.Partiti
}

type schemaConflictsPartition struct {
state *doltdb.MergeState
head *doltdb.Commit
ddb *doltdb.DoltDB
tableName string
state *doltdb.MergeState
head *doltdb.Commit
ddb *doltdb.DoltDB
}

func (p schemaConflictsPartition) Key() []byte {
return []byte(doltdb.SchemaConflictsTableName)
return []byte(p.tableName)
}

type schemaConflict struct {
Expand Down
37 changes: 18 additions & 19 deletions go/libraries/doltcore/sqle/dtables/table_of_tables_in_conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,36 @@ var _ sql.Table = (*TableOfTablesInConflict)(nil)

// TableOfTablesInConflict is a sql.Table implementation that implements a system table which shows the current conflicts
type TableOfTablesInConflict struct {
dbName string
ddb *doltdb.DoltDB
dbName string
tableName string
ddb *doltdb.DoltDB
}

// NewTableOfTablesInConflict creates a TableOfTablesInConflict
func NewTableOfTablesInConflict(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
return &TableOfTablesInConflict{dbName: dbName, ddb: ddb}
func NewTableOfTablesInConflict(_ *sql.Context, dbName, tableName string, ddb *doltdb.DoltDB) sql.Table {
return &TableOfTablesInConflict{dbName: dbName, tableName: tableName, ddb: ddb}
}

// Name is a sql.Table interface function which returns the name of the table which is defined by the constant
// TableOfTablesInConflictName
func (dt *TableOfTablesInConflict) Name() string {
return doltdb.TableOfTablesInConflictName
// Name is a sql.Table interface function which returns the name of the table
func (ct *TableOfTablesInConflict) Name() string {
return ct.tableName
}

// String is a sql.Table interface function which returns the name of the table which is defined by the constant
// TableOfTablesInConflictName
func (dt *TableOfTablesInConflict) String() string {
return doltdb.TableOfTablesInConflictName
// String is a sql.Table interface function which returns the name of the table
func (ct *TableOfTablesInConflict) String() string {
return ct.tableName
}

// Schema is a sql.Table interface function that gets the sql.Schema of the log system table.
func (dt *TableOfTablesInConflict) Schema() sql.Schema {
func (ct *TableOfTablesInConflict) Schema() sql.Schema {
return []*sql.Column{
{Name: "table", Type: types.Text, Source: doltdb.TableOfTablesInConflictName, PrimaryKey: true, DatabaseSource: dt.dbName},
{Name: "num_conflicts", Type: types.Uint64, Source: doltdb.TableOfTablesInConflictName, PrimaryKey: false, DatabaseSource: dt.dbName},
{Name: "table", Type: types.Text, Source: ct.tableName, PrimaryKey: true, DatabaseSource: ct.dbName},
{Name: "num_conflicts", Type: types.Uint64, Source: ct.tableName, PrimaryKey: false, DatabaseSource: ct.dbName},
}
}

// Collation implements the sql.Table interface.
func (dt *TableOfTablesInConflict) Collation() sql.CollationID {
func (ct *TableOfTablesInConflict) Collation() sql.CollationID {
return sql.Collation_Default
}

Expand Down Expand Up @@ -114,9 +113,9 @@ func (p *tablesInConflict) Close(*sql.Context) error {
}

// Partitions is a sql.Table interface function that returns a partition of the data. Conflict data is partitioned by table.
func (dt *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
func (ct *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
sess := dsess.DSessFromSess(ctx.Session)
ws, err := sess.WorkingSet(ctx, dt.dbName)
ws, err := sess.WorkingSet(ctx, ct.dbName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -151,7 +150,7 @@ func (dt *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIt
}

// PartitionRows is a sql.Table interface function that gets a row iterator for a partition
func (dt *TableOfTablesInConflict) PartitionRows(_ *sql.Context, part sql.Partition) (sql.RowIter, error) {
func (ct *TableOfTablesInConflict) PartitionRows(_ *sql.Context, part sql.Partition) (sql.RowIter, error) {
cp := part.(*tableInConflict)
return cp, nil
}
Loading

0 comments on commit 2fbdd5b

Please sign in to comment.