loadCatalogMetadata copies one database's schemas, tables and views (with their column lists and view definitions) into the omni catalog under the given normalized catalog name, returning the view definitions it loaded. Views carry their defining query so omni's analysis can resolve lineage through
(cat *catalog.Catalog, norm string, meta *model.DatabaseMetadata)
| 108 | // through them (GetQuerySpanWithCatalog); an empty definition leaves the view |
| 109 | // opaque. Shared by the completion and query-span catalog builders. |
| 110 | func loadCatalogMetadata(cat *catalog.Catalog, norm string, meta *model.DatabaseMetadata) []string { |
| 111 | var definitions []string |
| 112 | database := cat.EnsureCatalog(norm) |
| 113 | for _, schemaName := range meta.ListSchemaNames() { |
| 114 | schemaMeta := meta.GetSchemaMetadata(schemaName) |
| 115 | if schemaMeta == nil { |
| 116 | continue |
| 117 | } |
| 118 | sc := database.EnsureSchema(catalog.Normalize(schemaName)) |
| 119 | for _, tableName := range schemaMeta.ListTableNames() { |
| 120 | tableMeta := schemaMeta.GetTable(tableName) |
| 121 | if tableMeta == nil { |
| 122 | continue |
| 123 | } |
| 124 | sc.AddTable(catalog.Normalize(tableName), columnsOf(tableMeta.GetProto().GetColumns())...) |
| 125 | } |
| 126 | for _, viewName := range schemaMeta.ListViewNames() { |
| 127 | viewMeta := schemaMeta.GetView(viewName) |
| 128 | if viewMeta == nil { |
| 129 | continue |
| 130 | } |
| 131 | v := sc.AddView(catalog.Normalize(viewName), columnsOf(viewMeta.GetColumns())...) |
| 132 | v.Definition = viewMeta.GetDefinition() |
| 133 | if def := viewMeta.GetDefinition(); def != "" { |
| 134 | definitions = append(definitions, def) |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | return definitions |
| 139 | } |
| 140 | |
| 141 | // catalogNeeded reports whether the current completion statement needs this |
| 142 | // catalog's full schema/table/column metadata loaded: true for the session |
no test coverage detected