@@ -18,13 +18,18 @@ import (
1818 "fmt"
1919 "github.com/DataBridgeTech/dbqcore"
2020 "github.com/DataBridgeTech/dbqctl/internal"
21- "log"
21+ "log/slog "
2222 "os"
2323 "strings"
2424
2525 "github.com/spf13/cobra"
2626)
2727
28+ type FailedCheckDetails struct {
29+ ID string
30+ Err error
31+ }
32+
2833func NewCheckCommand (app internal.DbqCliApp ) * cobra.Command {
2934 var checksFile string
3035
@@ -37,7 +42,8 @@ which outlines the rules and constraints that the data within the dataset should
3742By automating these checks, you can proactively identify and address data quality issues, ensuring that your datasets meet the required standards for analysis and decision-making.
3843` ,
3944 RunE : func (cmd * cobra.Command , args []string ) error {
40- log .Printf ("Reading checks configuration file: %s \n " , checksFile )
45+ slog .Debug ("Reading checks configuration file" ,
46+ "checks_config_path" , checksFile )
4147
4248 checksCfg , err := dbqcore .LoadChecksConfig (checksFile )
4349 if err != nil {
@@ -56,24 +62,35 @@ By automating these checks, you can proactively identify and address data qualit
5662 return fmt .Errorf ("specified data source not found in dbq configuration: %s" , dataSourceId )
5763 }
5864
59- for dsIdx , dataset := range datasets {
60- log .Printf ("[%d/%d] Running quality checks for: %s" , dsIdx + 1 , len (datasets ), dataset )
61- for cIdx , check := range rule .Checks {
62- pass , _ , err := app .RunCheck (& check , dataSource , dataset , rule .Where )
65+ var failedChecks []FailedCheckDetails
66+ for _ , dataset := range datasets {
67+ fmt .Printf ("running %d quality checks for '%s'\n " , len (rule .Checks ), dataset )
68+ for _ , check := range rule .Checks {
69+ pass , _ , _ := app .RunCheck (& check , dataSource , dataset , rule .Where )
70+ fmt .Printf (" check %s ('%s') ... %s\n " , check .Description , check .ID , getCheckResultLabel (pass ))
71+
6372 if err != nil {
64- log . Printf ( "Failed to run check: %s" , err . Error () )
73+ failedChecks = append ( failedChecks , FailedCheckDetails { ID : check . ID , Err : err } )
6574 }
6675
67- log .Printf (" [%d/%d] '%s': %s" , cIdx + 1 , len (rule .Checks ), check .ID , getCheckResultLabel (pass ))
6876 if ! pass && strGetOrDefault (string (check .OnFail ), dbqcore .OnFailActionError ) == dbqcore .OnFailActionError {
6977 exitCode = 1
7078 }
7179 }
7280 }
81+
82+ if len (failedChecks ) != 0 {
83+ for _ , result := range failedChecks {
84+ fmt .Println ()
85+ fmt .Printf ("--- %s ---\n " , result .ID )
86+ fmt .Printf ("error: %s\n " , result .Err )
87+ }
88+ }
7389 }
7490
7591 if exitCode != 0 {
76- log .Printf ("One or more checks with on_fail = 'error' action have failed, exiting." )
92+ // todo: print detailed report
93+ // fmt.Printf("\ncheck result: FAILED. 1 passed; 1 failed; \n")
7794 os .Exit (exitCode )
7895 }
7996
@@ -124,9 +141,9 @@ func parseDatasetString(input string) (datasource string, datasets []string, err
124141
125142func getCheckResultLabel (passed bool ) string {
126143 if passed {
127- return "passed "
144+ return "ok "
128145 } else {
129- return "failed "
146+ return "FAILED "
130147 }
131148}
132149
0 commit comments