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

Function loadCatalogMetadata

backend/plugin/parser/trino/completion.go:110–139  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

108// through them (GetQuerySpanWithCatalog); an empty definition leaves the view
109// opaque. Shared by the completion and query-span catalog builders.
110func 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

Callers 2

buildCompletionCatalogFunction · 0.85
buildSpanCatalogMethod · 0.85

Calls 11

columnsOfFunction · 0.85
ListSchemaNamesMethod · 0.80
GetSchemaMetadataMethod · 0.80
ListTableNamesMethod · 0.80
AddTableMethod · 0.80
ListViewNamesMethod · 0.80
GetTableMethod · 0.45
GetColumnsMethod · 0.45
GetProtoMethod · 0.45
GetViewMethod · 0.45
GetDefinitionMethod · 0.45

Tested by

no test coverage detected