list all tables in the workspace when catalogName is set to "".
(ctx context.Context, targetCatalogName string)
| 89 | |
| 90 | // list all tables in the workspace when catalogName is set to "". |
| 91 | func (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'. |
| 141 | func appendSchemaTables(catalogMap databricksCatalogMap, tablesInfo []catalog.TableInfo) error { |
no test coverage detected