MCPcopy Create free account
hub / github.com/bytebase/bytebase / listCatologTables

Method listCatologTables

backend/plugin/db/databricks/sync.go:91–138  ·  view source on GitHub ↗

list all tables in the workspace when catalogName is set to "".

(ctx context.Context, targetCatalogName string)

Source from the content-addressed store, hash-verified

89
90// list all tables in the workspace when catalogName is set to "".
91func (d *Driver) listCatologTables(ctx context.Context, targetCatalogName string) (databricksCatalogMap, error) {
92 catalogMap := make(databricksCatalogMap)
93
94 catalogsInfo, err := d.Client.Catalogs.ListAll(ctx, catalog.ListCatalogsRequest{})
95 if err != nil {
96 return nil, err
97 }
98
99 for _, catalogInfo := range catalogsInfo {
100 if targetCatalogName != "" && targetCatalogName != catalogInfo.Name {
101 continue
102 }
103 schemasInfo, err := d.Client.Schemas.ListAll(ctx, catalog.ListSchemasRequest{
104 CatalogName: catalogInfo.Name,
105 })
106 if err != nil {
107 return nil, err
108 }
109 for _, schemaInfo := range schemasInfo {
110 // init map.
111 scMap, ok := catalogMap[catalogInfo.Name]
112 if !ok {
113 catalogMap[catalogInfo.Name] = databricksSchemaMap{
114 schemaInfo.Name: []*tableUnion{},
115 }
116 } else {
117 _, ok := scMap[schemaInfo.Name]
118 if !ok {
119 scMap[schemaInfo.Name] = []*tableUnion{}
120 }
121 catalogMap[catalogInfo.Name] = scMap
122 }
123 // list tables in the schema.
124 tablesInfo, err := d.Client.Tables.ListAll(ctx, catalog.ListTablesRequest{
125 CatalogName: catalogInfo.Name,
126 SchemaName: schemaInfo.Name,
127 })
128 if err != nil {
129 return nil, err
130 }
131 if err := appendSchemaTables(catalogMap, tablesInfo); err != nil {
132 return nil, err
133 }
134 }
135 }
136
137 return catalogMap, nil
138}
139
140// extract tables' metadata from 'tablesInfo' and store it in 'catalogMap'.
141func appendSchemaTables(catalogMap databricksCatalogMap, tablesInfo []catalog.TableInfo) error {

Callers 3

SyncDBSchemaMethod · 0.95
SyncInstanceMethod · 0.95
DumpMethod · 0.95

Implementers 15

MockDriverbackend/plugin/advisor/utils_for_tests
Driverbackend/plugin/db/bigquery/bigquery.go
Driverbackend/plugin/db/mongodb/mongodb.go
Driverbackend/plugin/db/trino/trino.go
Driverbackend/plugin/db/redshift/redshift.go
Driverbackend/plugin/db/oracle/oracle.go
Driverbackend/plugin/db/dynamodb/dynamodb.go
Driverbackend/plugin/db/cosmosdb/cosmosdb.go
Driverbackend/plugin/db/spanner/spanner.go
Driverbackend/plugin/db/mssql/mssql.go
Driverbackend/plugin/db/mysql/mysql.go
Driverbackend/plugin/db/pg/pg.go

Calls 1

appendSchemaTablesFunction · 0.85

Tested by

no test coverage detected