Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
James Cor committed Oct 11, 2024
2 parents 8236654 + 459bc21 commit 688e831
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go/cmd/dolt/doltversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
package doltversion

const (
Version = "1.43.2"
Version = "1.43.3"
)
28 changes: 23 additions & 5 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,14 +923,32 @@ func (db Database) GetAllTableNames(ctx *sql.Context) ([]string, error) {
return db.getAllTableNames(ctx, root)
}

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

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
if resolve.UseSearchPath && db.schemaName == "" {
names, err := resolve.TablesOnSearchPath(ctx, root)
if err != nil {
return nil, err
}
// TODO: this method should probably return TableNames, but need to iron out the effective schema for system
// tables first
result = doltdb.FlattenTableNames(names)
} else {
result, err = root.GetTableNames(ctx, db.schemaName)
if err != nil {
return nil, err
}
}

result = append(result, systemTables...)
return result, err
return result, nil
}

func filterDoltInternalTables(tblNames []string) []string {
Expand Down Expand Up @@ -1351,6 +1369,7 @@ func (db Database) CreateSchema(ctx *sql.Context, schemaName string) error {
if err := dsess.CheckAccessForDb(ctx, db, branch_control.Permissions_Write); err != nil {
return err
}

root, err := db.GetRoot(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -1382,11 +1401,10 @@ func (db Database) GetSchema(ctx *sql.Context, schemaName string) (sql.DatabaseS
return newInformationSchemaDatabase(db.Name()), true, nil
}

ws, err := db.GetWorkingSet(ctx)
root, err := db.GetRoot(ctx)
if err != nil {
return nil, false, err
}
root := ws.WorkingRoot()

schemas, err := root.GetDatabaseSchemas(ctx)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions go/libraries/doltcore/sqle/resolve/resolve_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ func Table(
return tName, tbl, tblExists, err
}

// TablesOnSearchPath returns all the tables in the root value given that are in a schema in the search path
func TablesOnSearchPath(ctx *sql.Context, root doltdb.RootValue) ([]doltdb.TableName, error) {
schemasToSearch, err := SearchPath(ctx)
if err != nil {
return nil, err
}

var tableNames []doltdb.TableName
for _, schemaName := range schemasToSearch {
names, err := root.GetTableNames(ctx, schemaName)
if err != nil {
return nil, err
}
tableNames = append(tableNames, doltdb.ToTableNames(names, schemaName)...)
}

return tableNames, nil
}

// TableWithSearchPath resolves a table name to a table in the root value, searching through the schemas in the
func TableWithSearchPath(
ctx *sql.Context,
Expand Down

0 comments on commit 688e831

Please sign in to comment.