in internal/enricher/enricher.go [491:575]
func (mc *MetadataCollector) GetComments(ctx context.Context) ([]*ColumnComment, error) {
tables, err := mc.db.ListTables()
if err != nil {
return nil, fmt.Errorf("failed to list tables: %w", err)
}
var allComments []*ColumnComment
var wg sync.WaitGroup
errorChannel := make(chan error, len(tables))
for _, table := range tables {
wg.Add(1)
go func(table string) {
defer wg.Done()
tableComment, err := withRetry[string](ctx, DefaultRetryOptions, func(ctx context.Context) (string, error) {
return mc.db.GetTableComment(ctx, table)
})
if err != nil {
log.Printf("WARN: Failed to get table comment for table: %s, error: %v", table, err)
errorChannel <- err
return
}
if tableComment != "" {
mc.mu.Lock()
allComments = append(allComments, &ColumnComment{
Table: table,
Column: "", // Leave Column empty for table comments
Comment: tableComment,
})
mc.mu.Unlock()
}
columnInfos, err := mc.db.ListColumns(table)
if err != nil {
log.Printf("ERROR: Failed to list columns for table: %s, error: %v", table, err)
errorChannel <- err
return
}
for _, colInfo := range columnInfos {
wg.Add(1)
go func(colInfo database.ColumnInfo) {
defer wg.Done()
comment, err := withRetry[string](ctx, DefaultRetryOptions, func(ctx context.Context) (string, error) {
return mc.db.GetColumnComment(ctx, table, colInfo.Name)
})
if err != nil {
log.Printf("WARN: Failed to get comment for column: %s in table: %s, error: %v", colInfo.Name, table, err)
errorChannel <- err
return
}
if comment != "" {
mc.mu.Lock()
allComments = append(allComments, &ColumnComment{
Table: table,
Column: colInfo.Name,
Comment: comment,
})
mc.mu.Unlock()
}
}(colInfo)
}
}(table)
}
wg.Wait()
close(errorChannel)
var combinedErr error
for err := range errorChannel {
if err != nil {
if combinedErr == nil {
combinedErr = err
} else {
combinedErr = fmt.Errorf("%w; %v", combinedErr, err)
}
}
}
if combinedErr != nil {
return nil, combinedErr
}
return allComments, nil
}