Skip to content

Commit b621a68

Browse files
committed
initial commit
1 parent 926ddd3 commit b621a68

20 files changed

Lines changed: 848 additions & 2 deletions

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.idea
2+
3+
### Go template
4+
# If you prefer the allow list template instead of the deny list, see community template:
5+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
6+
#
7+
# Binaries for programs and plugins
8+
*.exe
9+
*.exe~
10+
*.dll
11+
*.so
12+
*.dylib
13+
14+
# Test binary, built with `go test -c`
15+
*.test
16+
17+
# Output of the go coverage tool, specifically when used with LiteIDE
18+
*.out
19+
20+
# Dependency directories (remove the comment below to include it)
21+
# vendor/
22+
23+
# Go workspace file
24+
go.work
25+
go.work.sum
26+
27+
# env file
28+
.env
29+

LICENSE

Whitespace-only changes.

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

checks.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 0.1
2+
validations:
3+
- dataset: clickhouse-prod-euw:ads.my_table_1
4+
checks:
5+
- id: row number between 0 and 100
6+
severity: warn
7+
type: row_count
8+
params:
9+
filter: "timestamp > '2023-01-01'"
10+
min: 0
11+
max: 100
12+
13+
- id: "no null values"
14+
description: "Check if table_1 has the correct number of columns"
15+
severity: error
16+
type: custom
17+
params:
18+
query: SELECT COUNT(*) FROM table_1 WHERE column_name IS NULL
19+
expected: 0
20+
21+
- id: "no duplicates"
22+
description: "Check if table_1 has no duplicates"
23+
severity: error
24+
type: no_duplicates
25+
params:
26+
columns: ["column_1", "column_2"]
27+
filter: "timestamp > '2023-01-01'"
28+
29+
- dataset: pgsql-staging@[public.table_1, public.table_2]
30+
checks:
31+
- id: "row count between 0 and 100"
32+
severity: warn
33+
type: row_count
34+
params:
35+
min: 0
36+
max: 1000

cmd/check.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cmd
2+
3+
import (
4+
"dbq/internal"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func NewCheckCommand(app internal.DbqApp) *cobra.Command {
11+
var checksFile string
12+
var dataSource string
13+
14+
cmd := &cobra.Command{
15+
Use: "check",
16+
Short: "A brief description of your command",
17+
Long: `A longer description that spans multiple lines and likely contains examples
18+
and usage of using your command. For example:
19+
20+
Cobra is a CLI library for Go that empowers applications.
21+
This application is a tool to generate the needed files
22+
to quickly create a Cobra application.`,
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
fmt.Println("Reading checks from " + checksFile)
25+
if dataSource != "" {
26+
fmt.Println("Data source is not empty: " + dataSource)
27+
}
28+
app.GetDbqConfig()
29+
return nil
30+
},
31+
}
32+
33+
cmd.Flags().StringVarP(&dataSource, "datasource", "d", "", "Datasource")
34+
cmd.Flags().StringVarP(&checksFile, "checks", "c", "", "Validation checks")
35+
_ = cmd.MarkFlagRequired("checks")
36+
37+
return cmd
38+
}

cmd/import.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cmd
2+
3+
import (
4+
"dbq/internal"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func NewImportCommand(app internal.DbqApp) *cobra.Command {
11+
var dataSource string
12+
var filter string
13+
var updateCfg bool
14+
15+
cmd := &cobra.Command{
16+
Use: "import",
17+
Short: "A brief description of your command",
18+
Long: `A longer description that spans multiple lines and likely contains examples
19+
and usage of using your command. For example:
20+
21+
Cobra is a CLI library for Go that empowers applications.
22+
This application is a tool to generate the needed files
23+
to quickly create a Cobra application.`,
24+
RunE: func(cmd *cobra.Command, args []string) error {
25+
datasets, err := app.ImportDatasets(dataSource, filter)
26+
if err != nil {
27+
fmt.Println("Failed to fetch datasets: " + err.Error())
28+
return nil
29+
}
30+
31+
for _, dataset := range datasets {
32+
fmt.Println("Imported dataset: ", dataset)
33+
}
34+
35+
if updateCfg {
36+
fmt.Println("Updating dbq config...")
37+
}
38+
39+
return nil
40+
},
41+
}
42+
43+
cmd.Flags().StringVarP(&dataSource, "datasource", "d", "", "Datasource")
44+
cmd.Flags().StringVarP(&filter, "filter", "f", "", "Filter")
45+
cmd.Flags().BoolVarP(&updateCfg, "update-checks", "u", false, "Update checks config in place")
46+
47+
return cmd
48+
}

cmd/ping.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cmd
2+
3+
import (
4+
"dbq/internal"
5+
"fmt"
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewPingCommand(app internal.DbqApp) *cobra.Command {
10+
var dataSource string
11+
12+
cmd := &cobra.Command{
13+
Use: "ping",
14+
Short: "A brief description of your command",
15+
Long: `A longer description that spans multiple lines and likely contains examples
16+
and usage of using your command. For example:
17+
18+
Cobra is a CLI library for Go that empowers applications.
19+
This application is a tool to generate the needed files
20+
to quickly create a Cobra application.`,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
err := app.PingDataSource(dataSource)
23+
if err != nil {
24+
fmt.Printf("Connection failed: %s\n", err.Error())
25+
} else {
26+
fmt.Println("Connection works")
27+
}
28+
},
29+
}
30+
31+
cmd.Flags().StringVarP(&dataSource, "datasource", "d", "", "Datasource")
32+
//_ = cmd.MarkFlagRequired("dataSource")
33+
34+
return cmd
35+
}

cmd/profile.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cmd
2+
3+
import (
4+
"dbq/internal"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func NewProfileCommand(app internal.DbqApp) *cobra.Command {
11+
var dataSource string
12+
var dataSet string
13+
14+
cmd := &cobra.Command{
15+
Use: "profile",
16+
Short: "A brief description of your command",
17+
Long: `A longer description that spans multiple lines and likely contains examples
18+
and usage of using your command. For example:
19+
20+
Cobra is a CLI library for Go that empowers applications.
21+
This application is a tool to generate the needed files
22+
to quickly create a Cobra application.`,
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
fmt.Printf("profiling %s in %s\n", dataSet, dataSource)
25+
return nil
26+
},
27+
}
28+
29+
cmd.Flags().StringVarP(&dataSource, "datasource", "d", "", "Datasource")
30+
_ = cmd.MarkFlagRequired("datasource")
31+
32+
cmd.Flags().StringVarP(&dataSet, "dataset", "s", "", "Dataset")
33+
34+
return cmd
35+
}

cmd/root.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cmd
2+
3+
import (
4+
"dbq/internal"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "dbq",
12+
Short: "A brief description of your application",
13+
Long: `A longer description that spans multiple lines and likely contains
14+
examples and usage of using your application. For example:
15+
16+
Cobra is a CLI library for Go that empowers applications.
17+
This application is a tool to generate the needed files
18+
to quickly create a Cobra application.`,
19+
}
20+
21+
func Execute() {
22+
err := rootCmd.Execute()
23+
if err != nil {
24+
os.Exit(1)
25+
}
26+
}
27+
28+
func AddCommands(app internal.DbqApp) {
29+
rootCmd.AddCommand(NewPingCommand(app))
30+
rootCmd.AddCommand(NewImportCommand(app))
31+
rootCmd.AddCommand(NewCheckCommand(app))
32+
rootCmd.AddCommand(NewProfileCommand(app))
33+
rootCmd.AddCommand(NewVersionCommand())
34+
}
35+
36+
func init() {
37+
// todo: workaround for bootstrap config flag & unsupported flag issue
38+
var dbqConfigFile string
39+
rootCmd.PersistentFlags().StringVar(&dbqConfigFile, "config", "", "config file (default is $HOME/.dbq.yaml or ./dbq.yaml)")
40+
}

cmd/version.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func NewVersionCommand() *cobra.Command {
9+
cmd := &cobra.Command{
10+
Use: "version",
11+
Short: "A brief description of your command",
12+
Long: `A longer description that spans multiple lines and likely contains examples
13+
and usage of using your command. For example:
14+
15+
Cobra is a CLI library for Go that empowers applications.
16+
This application is a tool to generate the needed files
17+
to quickly create a Cobra application.`,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
fmt.Println("DataBridge Quality Core: 0.0.1")
20+
},
21+
}
22+
23+
return cmd
24+
}

0 commit comments

Comments
 (0)