client

package
v0.7.1 Latest Latest
Warning

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

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

Documentation

Overview

Package client provides a GraphQL client for DataHub. It handles authentication, retries, and provides methods for all DataHub operations used by the MCP tools.

Index

Constants

View Source
const (
	LineageDirectionUpstream   = "UPSTREAM"
	LineageDirectionDownstream = "DOWNSTREAM"
)

Constants for lineage directions.

View Source
const (
	// SearchQuery searches for entities.
	SearchQuery = `` /* 1711-byte string literal not displayed */

	// GetEntityQuery retrieves a single entity by URN.
	GetEntityQuery = `` /* 1647-byte string literal not displayed */

	// GetSchemaQuery retrieves schema for a dataset.
	GetSchemaQuery = `` /* 1189-byte string literal not displayed */

	// GetLineageQuery retrieves lineage for an entity.
	// Note: maxHops parameter was removed from DataHub's SearchAcrossLineageInput.
	// Depth filtering should be done client-side using the returned degree values.
	GetLineageQuery = `` /* 599-byte string literal not displayed */

	// GetQueriesQuery retrieves saved Query entities associated with a dataset.
	GetQueriesQuery = `` /* 387-byte string literal not displayed */

	// GetUsageStatsQueriesQuery retrieves queries from usage stats (fallback for older DataHub).
	GetUsageStatsQueriesQuery = `` /* 205-byte string literal not displayed */

	// GetGlossaryTermQuery retrieves a glossary term.
	GetGlossaryTermQuery = `` /* 488-byte string literal not displayed */

	// ListTagsQuery lists all tags.
	ListTagsQuery = `` /* 289-byte string literal not displayed */

	// ListDomainsQuery lists all domains.
	ListDomainsQuery = `` /* 425-byte string literal not displayed */

	// PingQuery is a simple query to test connectivity.
	PingQuery = `
query ping {
  __typename
}
`

	// ListDataProductsQuery lists all data products.
	ListDataProductsQuery = `` /* 637-byte string literal not displayed */

	// GetDataProductQuery retrieves a single data product by URN.
	GetDataProductQuery = `` /* 627-byte string literal not displayed */

	// GetColumnLineageQuery retrieves fine-grained column-level lineage for a dataset.
	// Uses SchemaFieldRef.urn (available in DataHub v1.3.x+) to get the dataset URN.
	GetColumnLineageQuery = `` /* 243-byte string literal not displayed */

	// BatchGetSchemasQuery retrieves schemas for multiple datasets by URN.
	BatchGetSchemasQuery = `` /* 1377-byte string literal not displayed */

)

GraphQL query templates for DataHub operations.

Variables

View Source
var (
	// ErrUnauthorized indicates invalid or missing authentication token.
	ErrUnauthorized = errors.New("unauthorized: invalid or missing token")

	// ErrForbidden indicates insufficient permissions.
	ErrForbidden = errors.New("forbidden: insufficient permissions")

	// ErrNotFound indicates the requested entity was not found.
	ErrNotFound = errors.New("entity not found")

	// ErrInvalidURN indicates the URN format is invalid.
	ErrInvalidURN = errors.New("invalid DataHub URN format")

	// ErrTimeout indicates the request timed out.
	ErrTimeout = errors.New("request timed out")

	// ErrRateLimited indicates rate limiting by DataHub.
	ErrRateLimited = errors.New("rate limited by DataHub")

	// ErrNotConfigured indicates the client is not properly configured.
	ErrNotConfigured = errors.New("datahub client not configured")

	// ErrWriteDisabled indicates write operations are not enabled.
	ErrWriteDisabled = errors.New("write operations are disabled: set WriteEnabled to true in config")
)

Sentinel errors for DataHub operations.

Functions

func BuildChartURN

func BuildChartURN(platform, chartID string) string

BuildChartURN constructs a chart URN.

func BuildDashboardURN

func BuildDashboardURN(platform, dashboardID string) string

BuildDashboardURN constructs a dashboard URN.

func BuildDataFlowURN

func BuildDataFlowURN(orchestrator, flowID, cluster string) string

BuildDataFlowURN constructs a data flow URN.

func BuildDataJobURN

func BuildDataJobURN(dataFlowURN, jobID string) string

BuildDataJobURN constructs a data job URN.

func BuildDatasetURN

func BuildDatasetURN(platform, qualifiedName, env string) string

BuildDatasetURN constructs a dataset URN.

func BuildDomainURN

func BuildDomainURN(domainID string) string

BuildDomainURN constructs a domain URN.

func BuildGlossaryTermURN

func BuildGlossaryTermURN(termPath string) string

BuildGlossaryTermURN constructs a glossary term URN.

func BuildTagURN

func BuildTagURN(tagName string) string

BuildTagURN constructs a tag URN.

func ParseURN

func ParseURN(urn string) (*types.ParsedURN, error)

ParseURN parses a DataHub URN into its components.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a GraphQL client for DataHub.

func New

func New(cfg Config) (*Client, error)

New creates a new DataHub client with the given configuration.

func NewFromEnv

func NewFromEnv() (*Client, error)

NewFromEnv creates a new DataHub client from environment variables.

func (*Client) AddGlossaryTerm added in v0.5.0

func (c *Client) AddGlossaryTerm(ctx context.Context, urn, termURN string) error

AddGlossaryTerm adds a glossary term to an entity using read-modify-write.

func (c *Client) AddLink(ctx context.Context, urn, linkURL, description string) error

AddLink adds a link to an entity using read-modify-write on institutionalMemory.

func (*Client) AddTag added in v0.5.0

func (c *Client) AddTag(ctx context.Context, urn, tagURN string) error

AddTag adds a tag to an entity using read-modify-write on the globalTags aspect.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) Config

func (c *Client) Config() Config

Config returns the client configuration.

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, query string, variables map[string]any, result any) error

Execute executes a GraphQL query and unmarshals the response into result.

func (*Client) GetColumnLineage added in v0.4.0

func (c *Client) GetColumnLineage(ctx context.Context, urn string) (*types.ColumnLineage, error)

GetColumnLineage retrieves fine-grained column-level lineage for a dataset. Returns empty result if fine-grained lineage is not available for the dataset.

func (*Client) GetDataProduct

func (c *Client) GetDataProduct(ctx context.Context, urn string) (*types.DataProduct, error)

GetDataProduct retrieves a data product by URN.

func (*Client) GetEntity

func (c *Client) GetEntity(ctx context.Context, urn string) (*types.Entity, error)

GetEntity retrieves a single entity by URN.

func (*Client) GetGlossaryTerm

func (c *Client) GetGlossaryTerm(ctx context.Context, urn string) (*types.GlossaryTerm, error)

GetGlossaryTerm retrieves a glossary term by URN.

func (*Client) GetLineage

func (c *Client) GetLineage(ctx context.Context, urn string, opts ...LineageOption) (*types.LineageResult, error)

GetLineage retrieves lineage for an entity.

func (*Client) GetQueries

func (c *Client) GetQueries(ctx context.Context, urn string) (*types.QueryList, error)

GetQueries retrieves saved Query entities associated with a dataset. Falls back to usage stats queries if the listQueries API is not available.

func (*Client) GetSchema

func (c *Client) GetSchema(ctx context.Context, urn string) (*types.SchemaMetadata, error)

GetSchema retrieves schema metadata for a dataset.

func (*Client) GetSchemas added in v0.4.0

func (c *Client) GetSchemas(ctx context.Context, urns []string) (map[string]*types.SchemaMetadata, error)

GetSchemas retrieves schema metadata for multiple datasets by URN. Returns a map of URN to schema metadata. Datasets without schemas are omitted.

func (*Client) ListDataProducts

func (c *Client) ListDataProducts(ctx context.Context) ([]types.DataProduct, error)

ListDataProducts lists all data products. Uses search API as fallback if listDataProducts query is not available.

func (*Client) ListDomains

func (c *Client) ListDomains(ctx context.Context) ([]types.Domain, error)

ListDomains lists all domains.

func (*Client) ListTags

func (c *Client) ListTags(ctx context.Context, filter string) ([]types.Tag, error)

ListTags lists all tags, optionally filtered.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping tests the connection to DataHub.

func (*Client) RemoveGlossaryTerm added in v0.5.0

func (c *Client) RemoveGlossaryTerm(ctx context.Context, urn, termURN string) error

RemoveGlossaryTerm removes a glossary term from an entity using read-modify-write.

func (c *Client) RemoveLink(ctx context.Context, urn, linkURL string) error

RemoveLink removes a link from an entity by URL using read-modify-write.

func (*Client) RemoveTag added in v0.5.0

func (c *Client) RemoveTag(ctx context.Context, urn, tagURN string) error

RemoveTag removes a tag from an entity using read-modify-write on the globalTags aspect.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, opts ...SearchOption) (*types.SearchResult, error)

Search searches for entities in DataHub.

func (*Client) UpdateDescription added in v0.5.0

func (c *Client) UpdateDescription(ctx context.Context, urn, description string) error

UpdateDescription sets the editable description for any entity using read-modify-write.

type Config

type Config struct {
	// URL is the DataHub GMS URL (required).
	URL string

	// Token is the personal access token (required).
	Token string

	// Timeout is the request timeout. Default: 30s.
	Timeout time.Duration

	// RetryMax is the maximum retry attempts. Default: 3.
	RetryMax int

	// DefaultLimit is the default search result limit. Default: 10.
	DefaultLimit int

	// MaxLimit is the maximum allowed limit. Default: 100.
	MaxLimit int

	// MaxLineageDepth is the maximum lineage traversal depth. Default: 5.
	MaxLineageDepth int

	// Debug enables debug logging. Default: false.
	Debug bool

	// Logger is the logger for debug output. If nil, a NopLogger is used.
	// When Debug is true and Logger is nil, a StdLogger is created automatically.
	Logger Logger
}

Config holds the DataHub client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with default values.

func FromEnv

func FromEnv() (Config, error)

FromEnv creates a Config from environment variables.

func (Config) Validate

func (c Config) Validate() error

Validate checks if the configuration is valid.

type LineageOption

type LineageOption func(*lineageOptions)

LineageOption configures lineage queries.

func WithDepth

func WithDepth(depth int) LineageOption

WithDepth sets the maximum lineage traversal depth.

func WithDirection

func WithDirection(dir string) LineageOption

WithDirection sets the lineage direction (UPSTREAM or DOWNSTREAM). The direction is normalized to uppercase.

type Logger added in v0.4.2

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger defines the interface for debug logging. Compatible with slog.Logger and other structured loggers.

type NopLogger added in v0.4.2

type NopLogger struct{}

NopLogger is a logger that discards all output.

func (NopLogger) Debug added in v0.4.2

func (NopLogger) Debug(_ string, _ ...any)

Debug implements Logger.

func (NopLogger) Error added in v0.4.2

func (NopLogger) Error(_ string, _ ...any)

Error implements Logger.

func (NopLogger) Info added in v0.4.2

func (NopLogger) Info(_ string, _ ...any)

Info implements Logger.

func (NopLogger) Warn added in v0.4.2

func (NopLogger) Warn(_ string, _ ...any)

Warn implements Logger.

type SearchOption

type SearchOption func(*searchOptions)

SearchOption configures search behavior.

func WithEntityType

func WithEntityType(entityType string) SearchOption

WithEntityType filters search by entity type. Valid types: DATASET, DASHBOARD, DATA_FLOW, DATA_JOB, CONTAINER, DOMAIN, TAG, GLOSSARY_TERM, CORP_USER, CORP_GROUP, DATA_PRODUCT, etc. The entity type is normalized to SCREAMING_SNAKE_CASE (e.g., glossaryTerm -> GLOSSARY_TERM).

func WithFilters

func WithFilters(filters map[string][]string) SearchOption

WithFilters adds search filters.

func WithLimit

func WithLimit(limit int) SearchOption

WithLimit sets the maximum number of results.

func WithOffset

func WithOffset(offset int) SearchOption

WithOffset sets the result offset for pagination.

type StdLogger added in v0.4.2

type StdLogger struct {
	// contains filtered or unexported fields
}

StdLogger wraps the standard library logger.

func NewStdLogger added in v0.4.2

func NewStdLogger(debug bool) *StdLogger

NewStdLogger creates a new StdLogger. If debug is true, Debug messages are logged; otherwise they are discarded.

func (*StdLogger) Debug added in v0.4.2

func (l *StdLogger) Debug(msg string, args ...any)

Debug implements Logger.

func (*StdLogger) Error added in v0.4.2

func (l *StdLogger) Error(msg string, args ...any)

Error implements Logger.

func (*StdLogger) Info added in v0.4.2

func (l *StdLogger) Info(msg string, args ...any)

Info implements Logger.

func (*StdLogger) Warn added in v0.4.2

func (l *StdLogger) Warn(msg string, args ...any)

Warn implements Logger.

Jump to

Keyboard shortcuts

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