Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
BUILD_DIR=dist
PROTON_COMMIT := "eefb04d"
PROTON_COMMIT := "115c256"

.PHONY: all build clean test tidy vet proto setup format generate lint install

Expand Down
18 changes: 0 additions & 18 deletions core/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ func (s *Service) Upsert(ctx context.Context, ns *namespace.Namespace, ent *Enti
return id, nil
}

func (s *Service) UpsertWithEdges(ctx context.Context, ns *namespace.Namespace, ent *Entity, upstreams, downstreams []string) (string, error) {
id, err := s.Upsert(ctx, ns, ent)
if err != nil {
return "", err
}

if s.edges != nil {
for _, us := range upstreams {
_ = s.edges.Upsert(ctx, ns, &Edge{SourceURN: us, TargetURN: ent.URN, Type: "lineage", Properties: map[string]interface{}{"root": ent.URN}})
}
for _, ds := range downstreams {
_ = s.edges.Upsert(ctx, ns, &Edge{SourceURN: ent.URN, TargetURN: ds, Type: "lineage", Properties: map[string]interface{}{"root": ent.URN}})
}
}

return id, nil
}

func (s *Service) GetByURN(ctx context.Context, ns *namespace.Namespace, urn string) (Entity, error) {
return s.repo.GetByURN(ctx, ns, urn)
}
Expand Down
65 changes: 10 additions & 55 deletions core/entity/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ func TestService_GetContext_DefaultDepth(t *testing.T) {
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:b", Type: TypeTable, Name: "b"})
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:c", Type: TypeTable, Name: "c"})
edges.edges = []Edge{
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "lineage"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "lineage"},
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "derived_from"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "derived_from"},
}

// depth=0 should default to 1 (only direct neighbors of B)
Expand Down Expand Up @@ -297,9 +297,9 @@ func TestService_GetContext_MultiHop(t *testing.T) {
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:c", Type: TypeTable, Name: "c"})
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:d", Type: TypeTable, Name: "d"})
edges.edges = []Edge{
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "lineage"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "lineage"},
{SourceURN: "urn:c", TargetURN: "urn:d", Type: "lineage"},
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "derived_from"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "derived_from"},
{SourceURN: "urn:c", TargetURN: "urn:d", Type: "derived_from"},
}

// depth=2 from B should reach A, C, and D
Expand Down Expand Up @@ -366,9 +366,9 @@ func TestService_GetContext_CycleHandling(t *testing.T) {
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:b", Type: TypeTable, Name: "b"})
_, _ = svc.Upsert(ctx, ns, &Entity{URN: "urn:c", Type: TypeTable, Name: "c"})
edges.edges = []Edge{
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "lineage"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "lineage"},
{SourceURN: "urn:c", TargetURN: "urn:a", Type: "lineage"},
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "derived_from"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "derived_from"},
{SourceURN: "urn:c", TargetURN: "urn:a", Type: "derived_from"},
}

// depth=3 should not infinite loop
Expand Down Expand Up @@ -421,57 +421,12 @@ func TestService_GetByID(t *testing.T) {
}
}

func TestService_UpsertWithEdges(t *testing.T) {
repo := newMockRepo()
edges := &mockEdgeRepo{}
svc := NewService(repo, edges, nil)
ctx := context.Background()
ns := namespace.DefaultNamespace

ent := &Entity{URN: "urn:table:main", Type: TypeTable, Name: "main"}
upstreams := []string{"urn:table:source1", "urn:table:source2"}
downstreams := []string{"urn:table:sink1"}

id, err := svc.UpsertWithEdges(ctx, ns, ent, upstreams, downstreams)
if err != nil {
t.Fatalf("UpsertWithEdges failed: %v", err)
}
if id == "" {
t.Fatal("expected non-empty ID")
}

// Should have 2 upstream edges + 1 downstream edge = 3 total
if len(edges.edges) != 3 {
t.Fatalf("expected 3 edges, got %d", len(edges.edges))
}

// Check upstream edges: source -> main
if edges.edges[0].SourceURN != "urn:table:source1" || edges.edges[0].TargetURN != "urn:table:main" {
t.Errorf("upstream edge 0: got source=%q target=%q", edges.edges[0].SourceURN, edges.edges[0].TargetURN)
}
if edges.edges[1].SourceURN != "urn:table:source2" || edges.edges[1].TargetURN != "urn:table:main" {
t.Errorf("upstream edge 1: got source=%q target=%q", edges.edges[1].SourceURN, edges.edges[1].TargetURN)
}

// Check downstream edge: main -> sink
if edges.edges[2].SourceURN != "urn:table:main" || edges.edges[2].TargetURN != "urn:table:sink1" {
t.Errorf("downstream edge: got source=%q target=%q", edges.edges[2].SourceURN, edges.edges[2].TargetURN)
}

// All edges should be lineage type
for i, e := range edges.edges {
if e.Type != "lineage" {
t.Errorf("edge %d: expected type 'lineage', got %q", i, e.Type)
}
}
}

func TestService_GetImpact(t *testing.T) {
repo := newMockRepo()
edges := &mockEdgeRepo{
downstreamEdges: []Edge{
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "lineage"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "lineage"},
{SourceURN: "urn:a", TargetURN: "urn:b", Type: "derived_from"},
{SourceURN: "urn:b", TargetURN: "urn:c", Type: "derived_from"},
},
}
svc := NewService(repo, edges, nil)
Expand Down
Loading