Skip to content

Commit

Permalink
refactor: linter - fixed cognitive complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
solsticemj25 committed Nov 7, 2024
1 parent 2f85f66 commit d736ae2
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions plugins/extractors/maxcompute/maxcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,17 @@ func (e *Extractor) Extract(_ context.Context, emit plugins.Emit) error {
var counter int
for {
e.logger.Info("fetching tables", "marker", marker)
resp, err := apiClient.ListTables(&e.config.ProjectName, &maxcomputeclient.ListTablesRequest{
MaxItem: &e.config.MaxPageSize,
Marker: &marker,
})
resp, err := e.fetchTables(apiClient, marker)
if err != nil {
panic(err)
return err
}

counter += len(resp.Body.Data.Tables)
e.logger.Info("fetched tables", "count", counter)
wg.Add(len(resp.Body.Data.Tables))

for _, table := range resp.Body.Data.Tables {
go func(table *maxcomputeclient.ListTablesResponseBodyDataTables) {
defer wg.Done()
tableInfo, err := apiClient.GetTableInfo(&e.config.ProjectName, table.Name, &maxcomputeclient.GetTableInfoRequest{})
if err != nil {
panic(err)
}

asset, err := e.buildAsset(tableInfo)
if err != nil {
e.logger.Error("failed to build asset", "table", *table.Name, "error", err)
return
}

emit(models.NewRecord(asset))
}(table)
go e.processTable(apiClient, table, emit, &wg)
}
wg.Wait()
if len(resp.Body.Data.Tables) == 0 || len(resp.Body.Data.Tables) < int(e.config.MaxPageSize) || *resp.Body.Data.Marker == "" {
Expand All @@ -151,6 +134,32 @@ func (e *Extractor) Extract(_ context.Context, emit plugins.Emit) error {
return nil
}

func (e *Extractor) fetchTables(apiClient *maxcomputeclient.Client, marker string) (*maxcomputeclient.ListTablesResponse, error) {
return apiClient.ListTables(&e.config.ProjectName, &maxcomputeclient.ListTablesRequest{
MaxItem: &e.config.MaxPageSize,
Marker: &marker,
})
}

func (e *Extractor) processTable(apiClient *maxcomputeclient.Client, table *maxcomputeclient.ListTablesResponseBodyDataTables,
emit plugins.Emit, wg *sync.WaitGroup) {

Check failure on line 145 in plugins/extractors/maxcompute/maxcompute.go

View workflow job for this annotation

GitHub Actions / golangci

File is not `gofumpt`-ed with `-extra` (gofumpt)
defer wg.Done()

tableInfo, err := apiClient.GetTableInfo(&e.config.ProjectName, table.Name, &maxcomputeclient.GetTableInfoRequest{})
if err != nil {
e.logger.Error("failed to get table info", "table", *table.Name, "error", err)
return
}

asset, err := e.buildAsset(tableInfo)
if err != nil {
e.logger.Error("failed to build asset", "table", *table.Name, "error", err)
return
}

emit(models.NewRecord(asset))
}

func (e *Extractor) buildAsset(tableInfo *maxcomputeclient.GetTableInfoResponse) (*v1beta2.Asset, error) {
defaultSchema := "default"
if tableInfo.Body.Data.Schema == nil {
Expand Down

0 comments on commit d736ae2

Please sign in to comment.