Skip to content

Commit

Permalink
Move dolt_tags and dolt_status, fix filter on all tables
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Oct 24, 2024
1 parent aee5383 commit 64e2692
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 47 deletions.
18 changes: 11 additions & 7 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var getGeneratedSystemTables = func() []string {
TableOfTablesWithViolationsName,
CommitsTableName,
CommitAncestorsTableName,
StatusTableName,
GetStatusTableName(),
RemotesTableName,
}
}
Expand Down Expand Up @@ -255,6 +255,16 @@ var GetLogTableName = func() string {
return "dolt_log"
}

// GetStatusTableName returns the status system table name.
var GetStatusTableName = func() string {
return "dolt_status"
}

// GetTagsTableName returns the tags table name
var GetTagsTableName = func() string {
return "dolt_tags"
}

const (
// DiffTableName is the name of the table with a map of commits to tables changed
DiffTableName = "dolt_diff"
Expand Down Expand Up @@ -283,15 +293,9 @@ const (
// CommitAncestorsTableName is the commit_ancestors system table name
CommitAncestorsTableName = "dolt_commit_ancestors"

// StatusTableName is the status system table name.
StatusTableName = "dolt_status"

// MergeStatusTableName is the merge status system table name.
MergeStatusTableName = "dolt_merge_status"

// TagsTableName is the tags table name
TagsTableName = "dolt_tags"

IgnoreTableName = "dolt_ignore"

// RebaseTableName is the rebase system table name.
Expand Down
63 changes: 38 additions & 25 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
dt, found = dtables.NewCommitsTable(ctx, db.Name(), db.ddb), true
case doltdb.CommitAncestorsTableName:
dt, found = dtables.NewCommitAncestorsTable(ctx, db.Name(), db.ddb), true
case doltdb.StatusTableName:
case doltdb.GetStatusTableName():
// TODO: This should be moved once all the system tables are moved to the dolt schema
if resolve.UseSearchPath && db.schemaName != "dolt" {
return nil, false, nil
}
sess := dsess.DSessFromSess(ctx.Session)
adapter := dsess.NewSessionStateAdapter(
sess, db.RevisionQualifiedName(),
Expand All @@ -489,7 +493,11 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
dt, found = dtables.NewStatusTable(ctx, db.ddb, ws, adapter), true
case doltdb.MergeStatusTableName:
dt, found = dtables.NewMergeStatusTable(db.RevisionQualifiedName()), true
case doltdb.TagsTableName:
case doltdb.GetTagsTableName():
// TODO: This should be moved once all the system tables are moved to the dolt schema
if resolve.UseSearchPath && db.schemaName != "dolt" {
return nil, false, nil
}
dt, found = dtables.NewTagsTable(ctx, db.ddb), true
case dtables.AccessTableName:
basCtx := branch_control.GetBranchAwareSession(ctx)
Expand Down Expand Up @@ -703,11 +711,12 @@ func (db Database) GetTableNamesAsOf(ctx *sql.Context, time interface{}) ([]stri
return nil, nil
}

tblNames, err := root.GetTableNames(ctx, doltdb.DefaultSchemaName)
tblNames, err := db.getAllTableNames(ctx, root, false)
if err != nil {
return nil, err
}
return filterDoltInternalTables(tblNames), nil

return filterDoltInternalTables(tblNames, db.schemaName), nil
}

// getTable returns the user table with the given baseName from the root given
Expand Down Expand Up @@ -848,7 +857,7 @@ func (db Database) tableInsensitive(ctx *sql.Context, root doltdb.RootValue, tab
}
}

tableNames, err := db.getAllTableNames(ctx, root)
tableNames, err := db.getAllTableNames(ctx, root, true)
if err != nil {
return doltdb.TableName{}, nil, false, err
}
Expand Down Expand Up @@ -901,20 +910,23 @@ func (db Database) newDoltTable(tableName string, sch schema.Schema, tbl *doltdb
// name resolution in queries is handled by GetTableInsensitive. Use GetAllTableNames for an unfiltered list of all
// tables in user space.
func (db Database) GetTableNames(ctx *sql.Context) ([]string, error) {
tblNames, err := db.GetAllTableNames(ctx)
showSystemTablesVar, err := ctx.GetSessionVariable(ctx, dsess.ShowSystemTables)
if err != nil {
return nil, err
}
// TODO: should just elide system table gathering if we don't need them
showSystemTables, err := ctx.GetSessionVariable(ctx, dsess.ShowSystemTables)

showSystemTables := showSystemTablesVar.(int8) == 1
tblNames, err := db.GetAllTableNames(ctx, showSystemTables)
if err != nil {
return nil, err
}
if showSystemTables.(int8) == 1 {

if showSystemTables {
return tblNames, nil
} else {
return filterDoltInternalTables(tblNames), nil
}

// TODO: Figure out way to remove filterDoltInternalTables
return filterDoltInternalTables(tblNames, db.schemaName), nil
}

func (db Database) SchemaName() string {
Expand All @@ -923,22 +935,17 @@ func (db Database) SchemaName() string {

// GetAllTableNames returns all user-space tables, including system tables in user space
// (e.g. dolt_docs, dolt_query_catalog).
func (db Database) GetAllTableNames(ctx *sql.Context) ([]string, error) {
func (db Database) GetAllTableNames(ctx *sql.Context, showSystemTables bool) ([]string, error) {
root, err := db.GetRoot(ctx)

if err != nil {
return nil, err
}

return db.getAllTableNames(ctx, root)
return db.getAllTableNames(ctx, root, showSystemTables)
}

func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([]string, error) {
systemTables, err := doltdb.GetGeneratedSystemTables(ctx, root)
if err != nil {
return nil, err
}

func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue, showSystemTables bool) ([]string, error) {
var err error
var result []string
// If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all
// schemas in the search_path
Expand All @@ -957,15 +964,21 @@ func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([]
}
}

result = append(result, systemTables...)
if showSystemTables {
systemTables, err := doltdb.GetGeneratedSystemTables(ctx, root)
if err != nil {
return nil, err
}
result = append(result, systemTables...)
}

return result, nil
}

func filterDoltInternalTables(tblNames []string) []string {
func filterDoltInternalTables(tblNames []string, schemaName string) []string {
result := []string{}
for _, tbl := range tblNames {
// TODO: Need to consider dolt schema
if !doltdb.HasDoltPrefix(tbl) && tbl != doltdb.GetBranchesTableName() && tbl != doltdb.GetLogTableName() {
if !doltdb.HasDoltPrefix(tbl) && schemaName != "dolt" {
result = append(result, tbl)
}
}
Expand Down Expand Up @@ -1185,7 +1198,7 @@ func (db Database) CreateIndexedTable(ctx *sql.Context, tableName string, sch sq

// CreateFulltextTableNames returns a set of names that will be used to create Full-Text pseudo-index tables.
func (db Database) CreateFulltextTableNames(ctx *sql.Context, parentTableName string, parentIndexName string) (fulltext.IndexTableNames, error) {
allTableNames, err := db.GetAllTableNames(ctx)
allTableNames, err := db.GetAllTableNames(ctx, true)
if err != nil {
return fulltext.IndexTableNames{}, err
}
Expand Down
10 changes: 5 additions & 5 deletions go/libraries/doltcore/sqle/dtables/status_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ func (s StatusTable) RowCount(_ *sql.Context) (uint64, bool, error) {
}

func (s StatusTable) Name() string {
return doltdb.StatusTableName
return doltdb.GetStatusTableName()
}

func (s StatusTable) String() string {
return doltdb.StatusTableName
return doltdb.GetStatusTableName()
}

func (s StatusTable) Schema() sql.Schema {
return []*sql.Column{
{Name: "table_name", Type: types.Text, Source: doltdb.StatusTableName, PrimaryKey: true, Nullable: false},
{Name: "staged", Type: types.Boolean, Source: doltdb.StatusTableName, PrimaryKey: true, Nullable: false},
{Name: "status", Type: types.Text, Source: doltdb.StatusTableName, PrimaryKey: true, Nullable: false},
{Name: "table_name", Type: types.Text, Source: doltdb.GetStatusTableName(), PrimaryKey: true, Nullable: false},
{Name: "staged", Type: types.Boolean, Source: doltdb.GetStatusTableName(), PrimaryKey: true, Nullable: false},
{Name: "status", Type: types.Text, Source: doltdb.GetStatusTableName(), PrimaryKey: true, Nullable: false},
}
}

Expand Down
20 changes: 10 additions & 10 deletions go/libraries/doltcore/sqle/dtables/tags_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ func (dt *TagsTable) 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 constant
// TagsTableName
// GetTagsTableName()
func (dt *TagsTable) Name() string {
return doltdb.TagsTableName
return doltdb.GetTagsTableName()
}

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

// Schema is a sql.Table interface function that gets the sql.Schema of the tags system table.
func (dt *TagsTable) Schema() sql.Schema {
return []*sql.Column{
{Name: "tag_name", Type: types.Text, Source: doltdb.TagsTableName, PrimaryKey: true},
{Name: "tag_hash", Type: types.Text, Source: doltdb.TagsTableName, PrimaryKey: true},
{Name: "tagger", Type: types.Text, Source: doltdb.TagsTableName, PrimaryKey: false},
{Name: "email", Type: types.Text, Source: doltdb.TagsTableName, PrimaryKey: false},
{Name: "date", Type: types.Datetime, Source: doltdb.TagsTableName, PrimaryKey: false},
{Name: "message", Type: types.Text, Source: doltdb.TagsTableName, PrimaryKey: false},
{Name: "tag_name", Type: types.Text, Source: doltdb.GetTagsTableName(), PrimaryKey: true},
{Name: "tag_hash", Type: types.Text, Source: doltdb.GetTagsTableName(), PrimaryKey: true},
{Name: "tagger", Type: types.Text, Source: doltdb.GetTagsTableName(), PrimaryKey: false},
{Name: "email", Type: types.Text, Source: doltdb.GetTagsTableName(), PrimaryKey: false},
{Name: "date", Type: types.Datetime, Source: doltdb.GetTagsTableName(), PrimaryKey: false},
{Name: "message", Type: types.Text, Source: doltdb.GetTagsTableName(), PrimaryKey: false},
}
}

Expand Down

0 comments on commit 64e2692

Please sign in to comment.