Skip to content

Commit 3043b95

Browse files
committed
dbqcore v0.1.0
1 parent 07ea65a commit 3043b95

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

cmd/check.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ By automating these checks, you can proactively identify and address data qualit
4646
slog.Debug("Reading checks configuration file",
4747
"checks_config_path", checksFile)
4848

49-
checksCfg, err := dbqcore.LoadChecksConfig(checksFile)
49+
checksCfg, err := dbqcore.LoadChecksFileConfig(checksFile)
5050
if err != nil {
5151
return fmt.Errorf("error while loading checks configuration file: %w", err)
5252
}
@@ -72,7 +72,7 @@ By automating these checks, you can proactively identify and address data qualit
7272
pass, _, err := app.RunCheck(&check, dataSource, dataset, rule.Where)
7373

7474
fmt.Printf(" check %s ... %s\n", check.Description, getCheckResultLabel(pass))
75-
if err == nil {
75+
if pass {
7676
passedCount += 1
7777
} else {
7878
failedChecks = append(failedChecks, FailedCheckDetails{
@@ -82,7 +82,7 @@ By automating these checks, you can proactively identify and address data qualit
8282
})
8383
}
8484

85-
if !pass && strGetOrDefault(string(check.OnFail), dbqcore.OnFailActionError) == dbqcore.OnFailActionError {
85+
if !pass && strGetOrDefault(string(check.OnFail), string(dbqcore.OnFailActionError)) == string(dbqcore.OnFailActionError) {
8686
exitCode = 1
8787
}
8888
}

cmd/version.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ package cmd
1717
import (
1818
"fmt"
1919

20-
"github.com/DataBridgeTech/dbqcore"
20+
"github.com/DataBridgeTech/dbqcore/dbq"
2121
"github.com/spf13/cobra"
2222
)
2323

2424
const (
25-
DbqCtlVersion = "v0.1.1"
25+
DbqCtlVersion = "v0.1.2"
2626
)
2727

2828
func NewVersionCommand() *cobra.Command {
@@ -31,7 +31,7 @@ func NewVersionCommand() *cobra.Command {
3131
Short: "Prints dbqctl and core lib version",
3232
Run: func(cmd *cobra.Command, args []string) {
3333
fmt.Printf("DataBridge Quality CLI: %s\n", DbqCtlVersion)
34-
fmt.Printf("DataBridge dbqcore lib version: %s\n", dbqcore.GetDbqCoreLibVersion())
34+
fmt.Printf("DataBridge dbqcore lib version: %s\n", dbq.GetDbqCoreLibVersion())
3535
},
3636
}
3737

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module github.com/DataBridgeTech/dbqctl
33
go 1.24.5
44

55
require (
6-
github.com/DataBridgeTech/dbqcore v0.0.8
6+
github.com/DataBridgeTech/dbqcore v0.1.0
77
github.com/spf13/cobra v1.9.1
88
github.com/spf13/pflag v1.0.7
99
github.com/spf13/viper v1.20.1
1010
gopkg.in/yaml.v3 v3.0.1
1111
)
1212

13-
//replace github.com/DataBridgeTech/dbqcore => ../dbqcore
13+
replace github.com/DataBridgeTech/dbqcore => ../dbqcore
1414

1515
require (
1616
github.com/ClickHouse/ch-go v0.67.0 // indirect

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ github.com/DataBridgeTech/dbqcore v0.0.3/go.mod h1:U2++eavpf8oSKxukSEJpKGfPaOtkA
1212
github.com/DataBridgeTech/dbqcore v0.0.5 h1:fvGtZNZRyUCAq7IM0bVfpZ/FlsGXMq0LmDf1vOoR1nU=
1313
github.com/DataBridgeTech/dbqcore v0.0.5/go.mod h1:U2++eavpf8oSKxukSEJpKGfPaOtkApA7AUpzwkrXmVM=
1414
github.com/DataBridgeTech/dbqcore v0.0.6/go.mod h1:kIYXBoNZyLQ02lCkTHJTl5Lu5Y28R2LMJrpNvTL+ySQ=
15+
github.com/DataBridgeTech/dbqcore v0.0.8/go.mod h1:kIYXBoNZyLQ02lCkTHJTl5Lu5Y28R2LMJrpNvTL+ySQ=
1516
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
1617
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
1718
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=

internal/app.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
package internal
1616

1717
import (
18-
"fmt"
18+
"context"
1919
"log/slog"
2020
"os"
2121

2222
"github.com/DataBridgeTech/dbqcore"
23+
"github.com/DataBridgeTech/dbqcore/dbq"
2324

2425
"github.com/spf13/cobra"
2526
"github.com/spf13/viper"
@@ -30,7 +31,7 @@ type DbqCliApp interface {
3031
PingDataSource(srcId string) (string, error)
3132
ImportDatasets(srcId string, filter string) ([]string, error)
3233
ProfileDataset(srcId string, dataset string, sample bool, maxConcurrent int) (*dbqcore.TableMetrics, error)
33-
RunCheck(check *dbqcore.Check, dataSource *dbqcore.DataSource, dataset string, defaultWhere string) (bool, string, error)
34+
RunCheck(check *dbqcore.DataQualityCheck, dataSource *dbqcore.DataSource, dataset string, defaultWhere string) (bool, string, error)
3435
GetDbqConfig() *dbqcore.DbqConfig
3536
SaveDbqConfig() error
3637
SetLogLevel(level slog.Level)
@@ -41,26 +42,29 @@ type DbqAppImpl struct {
4142
dbqConfigPath string
4243
dbqConfig *dbqcore.DbqConfig
4344
logLevel slog.Level
45+
logger *slog.Logger
4446
}
4547

4648
func NewDbqCliApp(dbqConfigPath string) DbqCliApp {
4749
dbqConfig, dbqConfigUsedPath := initConfig(dbqConfigPath)
50+
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelError}))
4851
return &DbqAppImpl{
4952
dbqConfigPath: dbqConfigUsedPath,
5053
dbqConfig: dbqConfig,
5154
logLevel: slog.LevelError,
55+
logger: logger, // todo: fix logger init
5256
}
5357
}
5458

5559
func (app *DbqAppImpl) PingDataSource(srcId string) (string, error) {
5660
var dataSource = app.FindDataSourceById(srcId)
5761

58-
cnn, err := getDbqConnector(*dataSource, app.logLevel)
62+
cnn, err := dbq.NewDbqConnector(dataSource, app.logger)
5963
if err != nil {
6064
return "", err
6165
}
6266

63-
info, err := cnn.Ping()
67+
info, err := cnn.Ping(context.Background()) // todo: ctx propagation
6468
if err != nil {
6569
return "", err
6670
}
@@ -71,23 +75,23 @@ func (app *DbqAppImpl) PingDataSource(srcId string) (string, error) {
7175
func (app *DbqAppImpl) ImportDatasets(srcId string, filter string) ([]string, error) {
7276
var dataSource = app.FindDataSourceById(srcId)
7377

74-
cnn, err := getDbqConnector(*dataSource, app.logLevel)
78+
cnn, err := dbq.NewDbqConnector(dataSource, app.logger)
7579
if err != nil {
7680
return []string{}, err
7781
}
7882

79-
return cnn.ImportDatasets(filter)
83+
return cnn.ImportDatasets(context.Background(), filter) // todo: ctx propagation
8084
}
8185

8286
func (app *DbqAppImpl) ProfileDataset(srcId string, dataset string, sample bool, maxConcurrent int) (*dbqcore.TableMetrics, error) {
8387
var dataSource = app.FindDataSourceById(srcId)
8488

85-
cnn, err := getDbqConnector(*dataSource, app.logLevel)
89+
dbqProfiler, err := dbq.NewDbqProfiler(dataSource, app.logger)
8690
if err != nil {
8791
return nil, err
8892
}
8993

90-
return cnn.ProfileDataset(dataset, sample, maxConcurrent)
94+
return dbqProfiler.ProfileDataset(context.Background(), dataset, sample, maxConcurrent) // todo: ctx propagation
9195
}
9296

9397
func (app *DbqAppImpl) GetDbqConfig() *dbqcore.DbqConfig {
@@ -117,12 +121,13 @@ func (app *DbqAppImpl) FindDataSourceById(srcId string) *dbqcore.DataSource {
117121
return nil
118122
}
119123

120-
func (app *DbqAppImpl) RunCheck(check *dbqcore.Check, dataSource *dbqcore.DataSource, dataset string, defaultWhere string) (bool, string, error) {
121-
cnn, err := getDbqConnector(*dataSource, app.logLevel)
124+
func (app *DbqAppImpl) RunCheck(check *dbqcore.DataQualityCheck, dataSource *dbqcore.DataSource, dataset string, defaultWhere string) (bool, string, error) {
125+
dbqValidator, err := dbq.NewDbqValidator(dataSource, app.logger)
122126
if err != nil {
123127
return false, "", err
124128
}
125-
return cnn.RunCheck(check, dataset, defaultWhere)
129+
130+
return dbqValidator.RunCheck(context.Background(), check, dataset, defaultWhere) // todo: ctx propagation
126131
}
127132

128133
func (app *DbqAppImpl) SetLogLevel(logLevel slog.Level) {
@@ -154,13 +159,3 @@ func initConfig(dbqConfigPath string) (*dbqcore.DbqConfig, string) {
154159

155160
return &dbqConfig, v.ConfigFileUsed()
156161
}
157-
158-
func getDbqConnector(ds dbqcore.DataSource, logLevel slog.Level) (dbqcore.DbqConnector, error) {
159-
logHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})
160-
switch ds.Type {
161-
case dbqcore.DataSourceTypeClickhouse:
162-
return dbqcore.NewClickhouseDbqConnector(ds, slog.New(logHandler))
163-
default:
164-
return nil, fmt.Errorf("data source type '%s' is not supported", ds.Type)
165-
}
166-
}

0 commit comments

Comments
 (0)