catalog

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package catalog is the commands over the local search catalog: ingest builds it from the repo's context sources, search queries it, and lineage traces fields through it.

Index

Constants

This section is empty.

Variables

View Source
var Ingest = command.Define(command.Def[IngestInput, string]{
	Name:       "ingest",
	Short:      "Build the local search catalog from context sources",
	Idempotent: true,
	Timeout:    30 * time.Minute,
	Needs:      func(IngestInput) command.Sidecars { return command.Sidecars{Node: true, CanalQuery: true} },
	Run: func(ctx context.Context, cc command.CommandContext, in IngestInput) (string, error) {
		if err := command.RequireSidecars(cc, command.Sidecars{Node: true, CanalQuery: true}); err != nil {
			return "", err
		}
		return ingest.Run(ctx, cc.Clients.Node, cc.Clients.CanalQuery, cc.Repo, in.Source)
	},
})

Ingest builds the local search catalog from context sources.

View Source
var Lineage = command.Define(command.Def[LineageInput, LineageResult]{
	Name:  "lineage",
	Short: "Trace fields through the local catalog: what each one is built from",
	Long: "Trace each field through the local catalog to what it is built from (the fields, models and\n" +
		"sources upstream of it), as a diagram: cards in layers, upstream first, linked by what uses it.",
	ReadOnly:   true,
	Idempotent: true,
	Needs:      func(LineageInput) command.Sidecars { return command.Sidecars{Node: true, CanalQuery: true} },
	Check:      LineageInput.check,
	Run: func(ctx context.Context, cc command.CommandContext, in LineageInput) (LineageResult, error) {
		if err := command.RequireSidecars(cc, command.Sidecars{Node: true, CanalQuery: true}); err != nil {
			return LineageResult{}, err
		}
		targets := in.targets()
		res, err := cc.Clients.Node.CatalogLineage(ctx, anfranode.CatalogLineageRequest{
			Context: anfranode.CatalogContextOf(cc.Repo, cc.Clients.CanalQuery.BaseURL()),
			Targets: targets, Limit: in.Limit, Offset: in.Offset,
		})
		if err != nil {
			return LineageResult{}, err
		}
		if len(res.Results) != len(targets) {
			return LineageResult{}, fmt.Errorf("anfra-node traced %d fields, asked %d", len(res.Results), len(targets))
		}
		out := LineageResult{Results: make([]FieldLineage, len(targets))}
		for i, r := range res.Results {
			if r.Target != targets[i] {
				return LineageResult{}, fmt.Errorf("anfra-node traced %s.%s where %s.%s was asked", r.Target.Parent, r.Target.Child, targets[i].Parent, targets[i].Child)
			}
			out.Results[i] = FieldLineage{Target: in.Targets[i], Query: r.Query, Diagram: r.Diagram, Error: r.Error}
		}
		return out, nil
	},
})

Lineage traces fields through the local catalog: what each one is built from.

View Source
var Search = command.Define(command.Def[SearchInput, anfranode.CatalogSearchResult]{
	Name:     "search",
	Short:    "Search the local catalog",
	ReadOnly: true,
	Needs:    func(SearchInput) command.Sidecars { return command.Sidecars{Node: true, CanalQuery: true} },
	Run: func(ctx context.Context, cc command.CommandContext, in SearchInput) (anfranode.CatalogSearchResult, error) {
		if err := command.RequireSidecars(cc, command.Sidecars{Node: true, CanalQuery: true}); err != nil {
			return nil, err
		}
		return search.Run(ctx, cc.Clients.Node, cc.Clients.CanalQuery, cc.Repo, strings.TrimSpace(strings.Join(in.Query, " ")))
	},
})

Search searches the local catalog.

Functions

This section is empty.

Types

type FieldLineage added in v0.9.0

type FieldLineage struct {
	Target  anfranode.LineageTarget `json:"target" doc:"the field, as asked"`
	Query   string                  `json:"query" doc:"the catalog search its lineage is, which search also takes; empty when the field could not be searched for"`
	Diagram *anfranode.Diagram      `json:"diagram,omitempty" doc:"the field's lineage; absent with error"`
	Error   string                  `json:"error,omitempty" doc:"why the field's lineage could not be traced"`
}

FieldLineage is one field's lineage, or why it could not be traced.

type IngestInput

type IngestInput struct {
	Source string `json:"source,omitempty" short:"s" doc:"optional context source key to ingest"`
}

IngestInput is ingest's input.

func (IngestInput) TransformSchema

func (IngestInput) TransformSchema(_ huma.Registry, s *huma.Schema) *huma.Schema

type LineageInput added in v0.9.0

type LineageInput struct {
	Targets []anfranode.LineageTarget `` /* 138-byte string literal not displayed */
	Limit   int                       `json:"limit,omitempty" minimum:"1" doc:"at most this many upstream entities per field; absent, all of them"`
	Offset  int                       `json:"offset,omitempty" minimum:"0" doc:"skip this many upstream entities first, to page with limit"`
}

LineageInput is lineage's input: the fields to trace, and the page of what each one is built from.

func (LineageInput) TransformSchema added in v0.9.0

func (LineageInput) TransformSchema(_ huma.Registry, s *huma.Schema) *huma.Schema

type LineageResult added in v0.9.0

type LineageResult struct {
	Results []FieldLineage `json:"results"`
}

LineageResult is lineage's answer: each field's lineage, in the order of the fields asked.

type SearchInput

type SearchInput struct {
	Query []string `json:"query,omitempty" cli:"positional" doc:"search query"`
}

SearchInput is search's input.

func (SearchInput) TransformSchema

func (SearchInput) TransformSchema(_ huma.Registry, s *huma.Schema) *huma.Schema

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL