Skip to content

Commit

Permalink
feat(compass): add filter to get all types and move gettypes to postg…
Browse files Browse the repository at this point in the history
…res (#146)

* feat(compass): add filter to get all types and move gettypes to postgres

* feat(compass): create filter builder in asset filter

* fix(asset): lint

* feat: add EmitUnpopulated option to grpc gateway
  • Loading branch information
mabdh authored Jun 10, 2022
1 parent 609ce4d commit 526edc0
Show file tree
Hide file tree
Showing 29 changed files with 1,995 additions and 1,511 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME="github.com/odpf/compass"
VERSION=$(shell git describe --always --tags 2>/dev/null)
COVERFILE="/tmp/compass.coverprofile"
PROTON_COMMIT := "7c803a39c176855b255401a700c2970bfeac1d58"
PROTON_COMMIT := "a5cae3d372dc9741659b19f20a203b9278431356"
.PHONY: all build test clean install proto

all: build
Expand Down
2,636 changes: 1,356 additions & 1,280 deletions api/proto/odpf/compass/v1beta1/service.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions api/proto/odpf/compass/v1beta1/service.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions api/proto/odpf/compass/v1beta1/service.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Repository interface {
Find(ctx context.Context, urn string, typ Type, service string) (Asset, error)
GetVersionHistory(ctx context.Context, flt Filter, id string) ([]Asset, error)
GetByVersion(ctx context.Context, id string, version string) (Asset, error)
GetTypes(ctx context.Context, flt Filter) (map[Type]int, error)
Upsert(ctx context.Context, ast *Asset) (string, error)
Delete(ctx context.Context, id string) error
}
Expand Down
5 changes: 0 additions & 5 deletions core/asset/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
type DiscoveryRepository interface {
Upsert(context.Context, Asset) error
Delete(ctx context.Context, assetID string) error

// GetTypes fetches types with assets count for all available types
// and returns them as a map[typeName]count
GetTypes(context.Context) (map[Type]int, error)

Search(ctx context.Context, cfg SearchConfig) (results []SearchResult, err error)
Suggest(ctx context.Context, cfg SearchConfig) (suggestions []string, err error)
}
Expand Down
94 changes: 94 additions & 0 deletions core/asset/filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package asset

import (
"strings"

"github.com/odpf/compass/core/validator"
)

Expand All @@ -19,3 +21,95 @@ type Filter struct {
func (f *Filter) Validate() error {
return validator.ValidateStruct(f)
}

type filterBuilder struct {
types string
services string
q string
qFields string
data map[string]string
size int
offset int
sortBy string
sortDirection string
}

func NewFilterBuilder() *filterBuilder {
return &filterBuilder{}
}

func (fb *filterBuilder) Types(types string) *filterBuilder {
fb.types = types
return fb
}

func (fb *filterBuilder) Services(services string) *filterBuilder {
fb.services = services
return fb
}

func (fb *filterBuilder) Q(q string) *filterBuilder {
fb.q = q
return fb
}

func (fb *filterBuilder) QFields(qFields string) *filterBuilder {
fb.qFields = qFields
return fb
}

func (fb *filterBuilder) Data(data map[string]string) *filterBuilder {
fb.data = data
return fb
}

func (fb *filterBuilder) Size(size int) *filterBuilder {
fb.size = size
return fb
}

func (fb *filterBuilder) Offset(offset int) *filterBuilder {
fb.offset = offset
return fb
}

func (fb *filterBuilder) SortBy(sortBy string) *filterBuilder {
fb.sortBy = sortBy
return fb
}

func (fb *filterBuilder) SortDirection(sortDirection string) *filterBuilder {
fb.sortDirection = sortDirection
return fb
}

func (fb *filterBuilder) Build() (Filter, error) {
flt := Filter{
Size: fb.size,
Offset: fb.offset,
SortBy: fb.sortBy,
SortDirection: fb.sortDirection,
Query: fb.q,
Data: fb.data,
}

if fb.types != "" {
typs := strings.Split(fb.types, ",")
for _, typeVal := range typs {
flt.Types = append(flt.Types, Type(typeVal))
}
}
if fb.services != "" {
flt.Services = strings.Split(fb.services, ",")
}

if fb.qFields != "" {
flt.QueryFields = strings.Split(fb.qFields, ",")
}

if err := flt.Validate(); err != nil {
return Filter{}, err
}

return flt, nil
}
61 changes: 60 additions & 1 deletion core/asset/mocks/asset_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 13 additions & 47 deletions core/asset/mocks/discovery_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion core/asset/mocks/lineage_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 526edc0

Please sign in to comment.