(ctx context.Context)
| 51 | } |
| 52 | |
| 53 | func (d *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, error) { |
| 54 | instanceMetadata := &db.InstanceMetadata{} |
| 55 | |
| 56 | // fetch version. |
| 57 | versionData, _, err := d.execStatementSync(ctx, "SELECT VERSION()", 0) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | if len(versionData) != 1 || len(versionData[0]) != 1 { |
| 62 | return nil, errors.New("invalid version format") |
| 63 | } |
| 64 | splitVersion := strings.Split(versionData[0][0], " ") |
| 65 | if len(splitVersion) != 2 { |
| 66 | return nil, errors.New("invalid version format") |
| 67 | } |
| 68 | instanceMetadata.Version = splitVersion[0] |
| 69 | |
| 70 | // fetch table data from databricks. |
| 71 | catalogMap, err := d.listCatologTables(ctx, "") |
| 72 | if err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | |
| 76 | for catalogName, schemaMap := range catalogMap { |
| 77 | dbMetadataMeta := storepb.DatabaseSchemaMetadata{} |
| 78 | schemas := convertToStorepbSchemas(schemaMap) |
| 79 | dbMetadataMeta.Name = catalogName |
| 80 | dbMetadataMeta.Schemas = schemas |
| 81 | instanceMetadata.Databases = append(instanceMetadata.Databases, &dbMetadataMeta) |
| 82 | } |
| 83 | |
| 84 | // fetch workspace users. |
| 85 | // TODO(tommy): complete this part when Permissions API for Golang is implemented. |
| 86 | |
| 87 | return instanceMetadata, nil |
| 88 | } |
| 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) { |
nothing calls this directly
no test coverage detected