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
- Variables
- func BuildChartURN(platform, chartID string) string
- func BuildDashboardURN(platform, dashboardID string) string
- func BuildDataFlowURN(orchestrator, flowID, cluster string) string
- func BuildDataJobURN(dataFlowURN, jobID string) string
- func BuildDatasetURN(platform, qualifiedName, env string) string
- func BuildDomainURN(domainID string) string
- func BuildGlossaryTermURN(termPath string) string
- func BuildTagURN(tagName string) string
- func ParseURN(urn string) (*types.ParsedURN, error)
- type Client
- func (c *Client) AddGlossaryTerm(ctx context.Context, urn, termURN string) error
- func (c *Client) AddLink(ctx context.Context, urn, linkURL, description string) error
- func (c *Client) AddTag(ctx context.Context, urn, tagURN string) error
- func (c *Client) Close() error
- func (c *Client) Config() Config
- func (c *Client) Execute(ctx context.Context, query string, variables map[string]any, result any) error
- func (c *Client) GetColumnLineage(ctx context.Context, urn string) (*types.ColumnLineage, error)
- func (c *Client) GetDataProduct(ctx context.Context, urn string) (*types.DataProduct, error)
- func (c *Client) GetEntity(ctx context.Context, urn string) (*types.Entity, error)
- func (c *Client) GetGlossaryTerm(ctx context.Context, urn string) (*types.GlossaryTerm, error)
- func (c *Client) GetLineage(ctx context.Context, urn string, opts ...LineageOption) (*types.LineageResult, error)
- func (c *Client) GetQueries(ctx context.Context, urn string) (*types.QueryList, error)
- func (c *Client) GetSchema(ctx context.Context, urn string) (*types.SchemaMetadata, error)
- func (c *Client) GetSchemas(ctx context.Context, urns []string) (map[string]*types.SchemaMetadata, error)
- func (c *Client) ListDataProducts(ctx context.Context) ([]types.DataProduct, error)
- func (c *Client) ListDomains(ctx context.Context) ([]types.Domain, error)
- func (c *Client) ListTags(ctx context.Context, filter string) ([]types.Tag, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) RemoveGlossaryTerm(ctx context.Context, urn, termURN string) error
- func (c *Client) RemoveLink(ctx context.Context, urn, linkURL string) error
- func (c *Client) RemoveTag(ctx context.Context, urn, tagURN string) error
- func (c *Client) Search(ctx context.Context, query string, opts ...SearchOption) (*types.SearchResult, error)
- func (c *Client) UpdateDescription(ctx context.Context, urn, description string) error
- type Config
- type LineageOption
- type Logger
- type NopLogger
- type SearchOption
- type StdLogger
Constants ¶
const ( LineageDirectionUpstream = "UPSTREAM" LineageDirectionDownstream = "DOWNSTREAM" )
Constants for lineage directions.
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 ¶
var ( 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 ¶
BuildChartURN constructs a chart URN.
func BuildDashboardURN ¶
BuildDashboardURN constructs a dashboard URN.
func BuildDataFlowURN ¶
BuildDataFlowURN constructs a data flow URN.
func BuildDataJobURN ¶
BuildDataJobURN constructs a data job URN.
func BuildDatasetURN ¶
BuildDatasetURN constructs a dataset URN.
func BuildDomainURN ¶
BuildDomainURN constructs a domain URN.
func BuildGlossaryTermURN ¶
BuildGlossaryTermURN constructs a glossary term URN.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GraphQL client for DataHub.
func NewFromEnv ¶
NewFromEnv creates a new DataHub client from environment variables.
func (*Client) AddGlossaryTerm ¶ added in v0.5.0
AddGlossaryTerm adds a glossary term to an entity using read-modify-write.
func (*Client) AddLink ¶ added in v0.5.0
AddLink adds a link to an entity using read-modify-write on institutionalMemory.
func (*Client) AddTag ¶ added in v0.5.0
AddTag adds a tag to an entity using read-modify-write on the globalTags aspect.
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
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 ¶
GetDataProduct retrieves a data product by URN.
func (*Client) GetGlossaryTerm ¶
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 ¶
GetQueries retrieves saved Query entities associated with a dataset. Falls back to usage stats queries if the listQueries API is not available.
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 ¶
ListDataProducts lists all data products. Uses search API as fallback if listDataProducts query is not available.
func (*Client) ListDomains ¶
ListDomains lists all domains.
func (*Client) RemoveGlossaryTerm ¶ added in v0.5.0
RemoveGlossaryTerm removes a glossary term from an entity using read-modify-write.
func (*Client) RemoveLink ¶ added in v0.5.0
RemoveLink removes a link from an entity by URL using read-modify-write.
func (*Client) RemoveTag ¶ added in v0.5.0
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.
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.
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.
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
NewStdLogger creates a new StdLogger. If debug is true, Debug messages are logged; otherwise they are discarded.