Skip to content

Commit 2fbdd5b

Browse files
committed
More system tables
1 parent ecf5425 commit 2fbdd5b

File tree

6 files changed

+131
-84
lines changed

6 files changed

+131
-84
lines changed

go/libraries/doltcore/doltdb/system_table.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ var getGeneratedSystemTables = func() []string {
153153
GetBranchesTableName(),
154154
GetRemoteBranchesTableName(),
155155
GetLogTableName(),
156-
TableOfTablesInConflictName,
157-
TableOfTablesWithViolationsName,
156+
GetTableOfTablesInConflictName(),
157+
GetTableOfTablesWithViolationsName(),
158158
GetCommitsTableName(),
159159
GetCommitAncestorsTableName(),
160160
GetStatusTableName(),
@@ -267,6 +267,16 @@ var GetCommitsTableName = func() string {
267267
return CommitsTableName
268268
}
269269

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+
270280
// GetDiffTableName returns the diff system table name
271281
var GetDiffTableName = func() string {
272282
return DiffTableName
@@ -277,6 +287,11 @@ var GetLogTableName = func() string {
277287
return LogTableName
278288
}
279289

290+
// GetMergeStatusTableName returns the merge status system table name
291+
var GetMergeStatusTableName = func() string {
292+
return MergeStatusTableName
293+
}
294+
280295
// GetRemoteBranchesTableName returns the all-branches system table name
281296
var GetRemoteBranchesTableName = func() string {
282297
return RemoteBranchesTableName
@@ -287,6 +302,11 @@ var GetRemotesTableName = func() string {
287302
return RemotesTableName
288303
}
289304

305+
// GetSchemaConflictsTableName returns the schema conflicts system table name
306+
var GetSchemaConflictsTableName = func() string {
307+
return SchemaConflictsTableName
308+
}
309+
290310
// GetStatusTableName returns the status system table name.
291311
var GetStatusTableName = func() string {
292312
return StatusTableName
@@ -340,6 +360,7 @@ const (
340360
// TagsTableName is the tags table name
341361
TagsTableName = "dolt_tags"
342362

363+
// IgnoreTableName is the ignore table name
343364
IgnoreTableName = "dolt_ignore"
344365

345366
// RebaseTableName is the rebase system table name.

go/libraries/doltcore/sqle/database.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,30 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
469469

470470
dt, found = dtables.NewColumnDiffTable(ctx, db.Name(), lwrName, db.ddb, head), true
471471
}
472-
case doltdb.TableOfTablesInConflictName:
473-
dt, found = dtables.NewTableOfTablesInConflict(ctx, db.RevisionQualifiedName(), db.ddb), true
474-
case doltdb.TableOfTablesWithViolationsName:
475-
dt, found = dtables.NewTableOfTablesConstraintViolations(ctx, root), true
476-
case doltdb.SchemaConflictsTableName:
477-
dt, found = dtables.NewSchemaConflictsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
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+
}
478496
case doltdb.GetBranchesTableName(), doltdb.BranchesTableName:
479497
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
480498
if err != nil {
@@ -534,8 +552,14 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
534552

535553
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, adapter), true
536554
}
537-
case doltdb.MergeStatusTableName:
538-
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
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
562+
}
539563
case doltdb.GetTagsTableName(), doltdb.TagsTableName:
540564
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)
541565
if err != nil {

go/libraries/doltcore/sqle/dtables/merge_status_table.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,39 @@ import (
2929
// MergeStatusTable is a sql.Table implementation that implements a system table
3030
// which shows information about an active merge.
3131
type MergeStatusTable struct {
32-
dbName string
32+
dbName string
33+
tableName string
3334
}
3435

35-
func (s MergeStatusTable) Name() string {
36-
return doltdb.MergeStatusTableName
36+
func (mst MergeStatusTable) Name() string {
37+
return mst.tableName
3738
}
3839

39-
func (s MergeStatusTable) String() string {
40-
return doltdb.MergeStatusTableName
40+
func (mst MergeStatusTable) String() string {
41+
return mst.tableName
4142
}
4243

43-
func (s MergeStatusTable) Schema() sql.Schema {
44+
func (mst MergeStatusTable) Schema() sql.Schema {
4445
return []*sql.Column{
45-
{Name: "is_merging", Type: types.Boolean, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: false, DatabaseSource: s.dbName},
46-
{Name: "source", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
47-
{Name: "source_commit", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
48-
{Name: "target", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
49-
{Name: "unmerged_tables", Type: types.Text, Source: doltdb.MergeStatusTableName, PrimaryKey: false, Nullable: true, DatabaseSource: s.dbName},
46+
{Name: "is_merging", Type: types.Boolean, Source: mst.tableName, PrimaryKey: false, Nullable: false, DatabaseSource: mst.dbName},
47+
{Name: "source", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
48+
{Name: "source_commit", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
49+
{Name: "target", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
50+
{Name: "unmerged_tables", Type: types.Text, Source: mst.tableName, PrimaryKey: false, Nullable: true, DatabaseSource: mst.dbName},
5051
}
5152
}
5253

53-
func (s MergeStatusTable) Collation() sql.CollationID {
54+
func (mst MergeStatusTable) Collation() sql.CollationID {
5455
return sql.Collation_Default
5556
}
5657

57-
func (s MergeStatusTable) Partitions(*sql.Context) (sql.PartitionIter, error) {
58+
func (mst MergeStatusTable) Partitions(*sql.Context) (sql.PartitionIter, error) {
5859
return index.SinglePartitionIterFromNomsMap(nil), nil
5960
}
6061

61-
func (s MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.RowIter, error) {
62+
func (mst MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.RowIter, error) {
6263
sesh := dsess.DSessFromSess(ctx.Session)
63-
ws, err := sesh.WorkingSet(ctx, s.dbName)
64+
ws, err := sesh.WorkingSet(ctx, mst.dbName)
6465
if err != nil {
6566
return nil, err
6667
}
@@ -69,8 +70,8 @@ func (s MergeStatusTable) PartitionRows(ctx *sql.Context, _ sql.Partition) (sql.
6970
}
7071

7172
// NewMergeStatusTable creates a StatusTable
72-
func NewMergeStatusTable(dbName string) sql.Table {
73-
return &MergeStatusTable{dbName}
73+
func NewMergeStatusTable(dbName, tableName string) sql.Table {
74+
return &MergeStatusTable{dbName, tableName}
7475
}
7576

7677
// MergeStatusIter is a sql.RowItr implementation which iterates over each commit as if it's a row in the table.

go/libraries/doltcore/sqle/dtables/schema_conflicts_table.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,70 +34,70 @@ var _ sql.Table = (*SchemaConflictsTable)(nil)
3434

3535
// SchemaConflictsTable is a sql.Table implementation that implements a system table which shows the current conflicts
3636
type SchemaConflictsTable struct {
37-
dbName string
38-
ddb *doltdb.DoltDB
37+
dbName string
38+
tableName string
39+
ddb *doltdb.DoltDB
3940
}
4041

4142
// NewSchemaConflictsTable creates a SchemaConflictsTable
42-
func NewSchemaConflictsTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
43-
return &SchemaConflictsTable{dbName: dbName, ddb: ddb}
43+
func NewSchemaConflictsTable(_ *sql.Context, dbName, tableName string, ddb *doltdb.DoltDB) sql.Table {
44+
return &SchemaConflictsTable{dbName: dbName, tableName: tableName, ddb: ddb}
4445
}
4546

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

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

5857
// Schema is a sql.Table interface function that gets the sql.Schema of the log system table.
59-
func (dt *SchemaConflictsTable) Schema() sql.Schema {
58+
func (sct *SchemaConflictsTable) Schema() sql.Schema {
6059
return []*sql.Column{
61-
{Name: "table_name", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: true, DatabaseSource: dt.dbName},
62-
{Name: "base_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
63-
{Name: "our_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
64-
{Name: "their_schema", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
65-
{Name: "description", Type: types.Text, Source: doltdb.SchemaConflictsTableName, PrimaryKey: false, DatabaseSource: dt.dbName},
60+
{Name: "table_name", Type: types.Text, Source: sct.tableName, PrimaryKey: true, DatabaseSource: sct.dbName},
61+
{Name: "base_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
62+
{Name: "our_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
63+
{Name: "their_schema", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
64+
{Name: "description", Type: types.Text, Source: sct.tableName, PrimaryKey: false, DatabaseSource: sct.dbName},
6665
}
6766
}
6867

6968
// Collation implements the sql.Table interface.
70-
func (dt *SchemaConflictsTable) Collation() sql.CollationID {
69+
func (sct *SchemaConflictsTable) Collation() sql.CollationID {
7170
return sql.Collation_Default
7271
}
7372

7473
// Partitions is a sql.Table interface function that returns a partition of the data. Conflict data for all tables exists in a single partition.
75-
func (dt *SchemaConflictsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
74+
func (sct *SchemaConflictsTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
7675
sess := dsess.DSessFromSess(ctx.Session)
77-
ws, err := sess.WorkingSet(ctx, dt.dbName)
76+
ws, err := sess.WorkingSet(ctx, sct.dbName)
7877
if err != nil {
7978
return nil, err
8079
}
81-
dbd, _ := sess.GetDbData(ctx, dt.dbName)
80+
dbd, _ := sess.GetDbData(ctx, sct.dbName)
8281

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

87-
head, err := sess.GetHeadCommit(ctx, dt.dbName)
86+
head, err := sess.GetHeadCommit(ctx, sct.dbName)
8887
if err != nil {
8988
return nil, err
9089
}
9190

9291
return sql.PartitionsToPartitionIter(schemaConflictsPartition{
93-
state: ws.MergeState(),
94-
head: head,
95-
ddb: dbd.Ddb,
92+
tableName: sct.tableName,
93+
state: ws.MergeState(),
94+
head: head,
95+
ddb: dbd.Ddb,
9696
}), nil
9797
}
9898

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

138138
type schemaConflictsPartition struct {
139-
state *doltdb.MergeState
140-
head *doltdb.Commit
141-
ddb *doltdb.DoltDB
139+
tableName string
140+
state *doltdb.MergeState
141+
head *doltdb.Commit
142+
ddb *doltdb.DoltDB
142143
}
143144

144145
func (p schemaConflictsPartition) Key() []byte {
145-
return []byte(doltdb.SchemaConflictsTableName)
146+
return []byte(p.tableName)
146147
}
147148

148149
type schemaConflict struct {

go/libraries/doltcore/sqle/dtables/table_of_tables_in_conflict.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,36 @@ var _ sql.Table = (*TableOfTablesInConflict)(nil)
2828

2929
// TableOfTablesInConflict is a sql.Table implementation that implements a system table which shows the current conflicts
3030
type TableOfTablesInConflict struct {
31-
dbName string
32-
ddb *doltdb.DoltDB
31+
dbName string
32+
tableName string
33+
ddb *doltdb.DoltDB
3334
}
3435

3536
// NewTableOfTablesInConflict creates a TableOfTablesInConflict
36-
func NewTableOfTablesInConflict(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
37-
return &TableOfTablesInConflict{dbName: dbName, ddb: ddb}
37+
func NewTableOfTablesInConflict(_ *sql.Context, dbName, tableName string, ddb *doltdb.DoltDB) sql.Table {
38+
return &TableOfTablesInConflict{dbName: dbName, tableName: tableName, ddb: ddb}
3839
}
3940

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

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

5251
// Schema is a sql.Table interface function that gets the sql.Schema of the log system table.
53-
func (dt *TableOfTablesInConflict) Schema() sql.Schema {
52+
func (ct *TableOfTablesInConflict) Schema() sql.Schema {
5453
return []*sql.Column{
55-
{Name: "table", Type: types.Text, Source: doltdb.TableOfTablesInConflictName, PrimaryKey: true, DatabaseSource: dt.dbName},
56-
{Name: "num_conflicts", Type: types.Uint64, Source: doltdb.TableOfTablesInConflictName, PrimaryKey: false, DatabaseSource: dt.dbName},
54+
{Name: "table", Type: types.Text, Source: ct.tableName, PrimaryKey: true, DatabaseSource: ct.dbName},
55+
{Name: "num_conflicts", Type: types.Uint64, Source: ct.tableName, PrimaryKey: false, DatabaseSource: ct.dbName},
5756
}
5857
}
5958

6059
// Collation implements the sql.Table interface.
61-
func (dt *TableOfTablesInConflict) Collation() sql.CollationID {
60+
func (ct *TableOfTablesInConflict) Collation() sql.CollationID {
6261
return sql.Collation_Default
6362
}
6463

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

116115
// Partitions is a sql.Table interface function that returns a partition of the data. Conflict data is partitioned by table.
117-
func (dt *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
116+
func (ct *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
118117
sess := dsess.DSessFromSess(ctx.Session)
119-
ws, err := sess.WorkingSet(ctx, dt.dbName)
118+
ws, err := sess.WorkingSet(ctx, ct.dbName)
120119
if err != nil {
121120
return nil, err
122121
}
@@ -151,7 +150,7 @@ func (dt *TableOfTablesInConflict) Partitions(ctx *sql.Context) (sql.PartitionIt
151150
}
152151

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

0 commit comments

Comments
 (0)