Skip to content

Commit

Permalink
Merge pull request #408 from yokofly/bugfix/followup-refactor-writetodb
Browse files Browse the repository at this point in the history
correct err usage if err is nil
  • Loading branch information
flarco authored Oct 20, 2024
2 parents 1c320de + 3c88020 commit d952a23
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions core/sling/task_run_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (t *TaskExecution) WriteToFile(cfg *Config, df *iop.Dataflow) (cnt uint64,
}
}
} else {
err = g.Error(err, "target for output is not specified")
err = g.Error("target for output is not specified")
return
}

Expand All @@ -136,7 +136,7 @@ func (t *TaskExecution) WriteToDb(cfg *Config, df *iop.Dataflow, tgtConn databas

// Detect empty columns
if len(df.Columns) == 0 {
err = g.Error(err, "no stream columns detected")
err = g.Error("no stream columns detected")
return 0, err
}

Expand Down Expand Up @@ -252,15 +252,16 @@ func (t *TaskExecution) WriteToDb(cfg *Config, df *iop.Dataflow, tgtConn databas
// Validate data
tCnt, err := tgtConn.GetCount(tableTmp.FullName())
if err != nil {
err = g.Error(err, "could not get count from temp table %s", tableTmp.FullName())
return 0, err
}
if cnt != tCnt {
err = g.Error(err, "inserted in temp table but table count (%d) != stream count (%d). Records missing/mismatch. Aborting", tCnt, cnt)
return 0, err
} else if tCnt == 0 && len(sampleData.Rows) > 0 {
err = g.Error(err, "Loaded 0 records while sample data has %d records. Exiting.", len(sampleData.Rows))
err = g.Error(err, "could not get count for temp table "+tableTmp.FullName())
return 0, err
} else {
if cnt != tCnt {
err = g.Error("inserted in temp table but table count (%d) != stream count (%d). Records missing/mismatch. Aborting", tCnt, cnt)
return 0, err
} else if tCnt == 0 && len(sampleData.Rows) > 0 {
err = g.Error("Loaded 0 records while sample data has %d records. Exiting.", len(sampleData.Rows))
return 0, err
}
}

// Execute pre-SQL
Expand Down Expand Up @@ -367,7 +368,7 @@ func initializeTargetTable(cfg *Config, tgtConn database.Connection) (database.T

// check table ddl
if targetTable.DDL != "" && !strings.Contains(targetTable.DDL, targetTable.Raw) {
err = g.Error(err, "The Table DDL provided needs to contains the exact object table name: %s\nProvided:\n%s", targetTable.Raw, targetTable.DDL)
err = g.Error("The Table DDL provided needs to contains the exact object table name: %s\nProvided:\n%s", targetTable.Raw, targetTable.DDL)
return database.Table{}, err
}

Expand Down

0 comments on commit d952a23

Please sign in to comment.