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

Function appendSchemaTables

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

extract tables' metadata from 'tablesInfo' and store it in 'catalogMap'.

(catalogMap databricksCatalogMap, tablesInfo []catalog.TableInfo)

Source from the content-addressed store, hash-verified

139
140// extract tables' metadata from 'tablesInfo' and store it in 'catalogMap'.
141func appendSchemaTables(catalogMap databricksCatalogMap, tablesInfo []catalog.TableInfo) error {
142 for _, tableInfo := range tablesInfo {
143 table := tableUnion{
144 typeName: tableInfo.TableType,
145 name: tableInfo.Name,
146 }
147
148 switch tableInfo.TableType {
149 case catalog.TableTypeView:
150 table.view = &storepb.ViewMetadata{
151 Name: table.name,
152 Definition: tableInfo.ViewDefinition,
153 Comment: tableInfo.Comment,
154 DependencyColumns: convertToDependencyColumns(tableInfo.SchemaName, tableInfo.Name, tableInfo.Columns),
155 }
156 case catalog.TableTypeMaterializedView:
157 table.materialView = &storepb.MaterializedViewMetadata{
158 Name: table.name,
159 Definition: tableInfo.ViewDefinition,
160 Comment: tableInfo.Comment,
161 }
162 case catalog.TableTypeExternal:
163 table.externalTable = &storepb.ExternalTableMetadata{
164 Name: table.name,
165 }
166 case catalog.TableTypeManaged:
167 table.table = &storepb.TableMetadata{
168 Name: table.name,
169 Columns: convertToColumnMetadata(tableInfo.Columns),
170 Comment: tableInfo.Comment,
171 }
172 default:
173 // we do not sync streaming table.
174 continue
175 }
176
177 // catalogMap[tableInfo.CatalogName] must not be nil.
178 if tblList, ok := catalogMap[tableInfo.CatalogName][tableInfo.SchemaName]; ok {
179 tblList = append(tblList, &table)
180 catalogMap[tableInfo.CatalogName][tableInfo.SchemaName] = tblList
181 } else {
182 return errors.New("table list not initialized")
183 }
184 }
185 return nil
186}
187
188func convertToColumnMetadata(columnInfo []catalog.ColumnInfo) []*storepb.ColumnMetadata {
189 columns := []*storepb.ColumnMetadata{}

Callers 1

listCatologTablesMethod · 0.85

Calls 2

convertToColumnMetadataFunction · 0.85

Tested by

no test coverage detected