Documentation
¶
Index ¶
- Constants
- func AppendSchemaScopeConditions(ctx context.Context, sql, dbCol, schemaCol string) string
- func AppendScopeConditions(ctx context.Context, sql, dbCol, schemaCol, tableCol string) string
- func FilterDatabaseRows(rows []*scrapper.DatabaseRow, filter *ScopeFilter) []*scrapper.DatabaseRow
- func FilterRows[T scrapper.HasTableFqn](rows []T, filter *ScopeFilter) []T
- func WithScope(ctx context.Context, filter *ScopeFilter) context.Context
- type ScopeFilter
- func (f *ScopeFilter) DatabaseSQL(dbCol string) (string, []any)
- func (f *ScopeFilter) InlineDatabaseSQL(dbCol string) string
- func (f *ScopeFilter) InlineSchemaSQL(dbCol, schemaCol string) string
- func (f *ScopeFilter) InlineTableSQL(dbCol, schemaCol, tableCol string) string
- func (f *ScopeFilter) IsDatabaseAccepted(database string) bool
- func (f *ScopeFilter) IsFqnAccepted(fqn scrapper.DwhFqn) bool
- func (f *ScopeFilter) IsObjectAccepted(database, schema, table string) bool
- func (f *ScopeFilter) IsSchemaAccepted(database, schema string) bool
- func (f *ScopeFilter) SchemaSQL(dbCol, schemaCol string) (string, []any)
- func (f *ScopeFilter) TableSQL(dbCol, schemaCol, tableCol string) (string, []any)
- type ScopeRule
- type ScopedScrapper
- func (s *ScopedScrapper) BaseScope() *ScopeFilter
- func (s *ScopedScrapper) Close() error
- func (s *ScopedScrapper) DialectType() string
- func (s *ScopedScrapper) IsPermissionError(err error) bool
- func (s *ScopedScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)
- func (s *ScopedScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)
- func (s *ScopedScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)
- func (s *ScopedScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)
- func (s *ScopedScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)
- func (s *ScopedScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)
- func (s *ScopedScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)
- func (s *ScopedScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)
- func (s *ScopedScrapper) QueryTables(ctx context.Context) ([]*scrapper.TableRow, error)
- func (s *ScopedScrapper) SqlDialect() sqldialect.Dialect
- func (s *ScopedScrapper) ValidateConfiguration(ctx context.Context) (warnings []string, err error)
Constants ¶
const ScopeFilterPlaceholder = "/* SYNQ_SCOPE_FILTER */"
ScopeFilterPlaceholder is the marker placed in SQL queries at the exact point where scope filter conditions should be injected. It must appear inside an existing WHERE clause. When scope filtering is active it gets replaced with "AND <conditions>"; when inactive it is replaced with an empty string.
Variables ¶
This section is empty.
Functions ¶
func AppendSchemaScopeConditions ¶
AppendSchemaScopeConditions is like AppendScopeConditions but only generates schema-level conditions (no table filtering). Useful for queries that don't have table-level columns.
func AppendScopeConditions ¶
AppendScopeConditions replaces the ScopeFilterPlaceholder in a SQL query with scope filter conditions derived from the context.
schemaCol and tableCol are the column expressions in the SQL query. dbCol can be empty if the query has no database column.
Returns the original SQL unchanged if no scope is set or no conditions apply.
func FilterDatabaseRows ¶
func FilterDatabaseRows(rows []*scrapper.DatabaseRow, filter *ScopeFilter) []*scrapper.DatabaseRow
FilterDatabaseRows filters DatabaseRow entries using the given ScopeFilter. DatabaseRow doesn't implement HasTableFqn, so this uses IsDatabaseAccepted. Returns all rows unchanged if filter is nil.
func FilterRows ¶
func FilterRows[T scrapper.HasTableFqn](rows []T, filter *ScopeFilter) []T
FilterRows filters rows that implement HasTableFqn using the given ScopeFilter. Returns all rows unchanged if filter is nil.
Types ¶
type ScopeFilter ¶
type ScopeFilter struct {
Include []ScopeRule `yaml:"include,omitempty" json:"include,omitempty"`
Exclude []ScopeRule `yaml:"exclude,omitempty" json:"exclude,omitempty"`
// contains filtered or unexported fields
}
ScopeFilter defines include/exclude rules for scoping scrapper queries.
Matching semantics:
- If Include is non-empty, the tuple (database, schema, table) must match at least one include rule.
- If Exclude is non-empty, the tuple must NOT match any exclude rule.
- Exclude takes precedence over include (exclude wins).
- Empty field in a rule = wildcard (matches anything at that level).
- nil ScopeFilter = accept all (all methods return true on nil receiver).
func GetScope ¶
func GetScope(ctx context.Context) *ScopeFilter
GetScope returns the effective composed filter from context. Returns nil if no scope is set.
func Merge ¶
func Merge(filters ...*ScopeFilter) *ScopeFilter
Merge combines multiple filters into one. The merged filter accepts a value only if it passes ALL input filters (AND semantics).
For include rules across filters: a value must match at least one include from each filter that has includes (AND of ORs). For exclude rules across filters: a value matched by any exclude from any filter is rejected.
Nil filters are skipped.
func (*ScopeFilter) DatabaseSQL ¶
func (f *ScopeFilter) DatabaseSQL(dbCol string) (string, []any)
DatabaseSQL generates a SQL WHERE condition fragment for database-level filtering. Returns empty string and nil args if no applicable rules exist. The condition uses parameterized placeholders (%s for column names, values in args).
func (*ScopeFilter) InlineDatabaseSQL ¶
func (f *ScopeFilter) InlineDatabaseSQL(dbCol string) string
InlineDatabaseSQL generates an inline SQL WHERE fragment for database-level filtering. Unlike DatabaseSQL, this produces literal SQL with no placeholders, suitable for appending to any SQL dialect without needing parameterized query support. Returns empty string if no applicable rules exist.
func (*ScopeFilter) InlineSchemaSQL ¶
func (f *ScopeFilter) InlineSchemaSQL(dbCol, schemaCol string) string
InlineSchemaSQL generates an inline SQL WHERE fragment for schema-level filtering. Returns empty string if no applicable rules exist.
func (*ScopeFilter) InlineTableSQL ¶
func (f *ScopeFilter) InlineTableSQL(dbCol, schemaCol, tableCol string) string
InlineTableSQL generates an inline SQL WHERE fragment for table-level filtering. Returns empty string if no applicable rules exist.
func (*ScopeFilter) IsDatabaseAccepted ¶
func (f *ScopeFilter) IsDatabaseAccepted(database string) bool
IsDatabaseAccepted performs conservative partial evaluation at the database level. Returns false only when it can definitively say no tuple (db, *, *) would ever pass. Returns true (conservative) when uncertain. Returns true on nil receiver.
func (*ScopeFilter) IsFqnAccepted ¶
func (f *ScopeFilter) IsFqnAccepted(fqn scrapper.DwhFqn) bool
IsFqnAccepted is a convenience wrapper for IsObjectAccepted using a DwhFqn. Returns true on nil receiver.
func (*ScopeFilter) IsObjectAccepted ¶
func (f *ScopeFilter) IsObjectAccepted(database, schema, table string) bool
IsObjectAccepted checks if a (database, schema, table) tuple passes the filter. All three levels are evaluated against all rules. Returns true on nil receiver.
func (*ScopeFilter) IsSchemaAccepted ¶
func (f *ScopeFilter) IsSchemaAccepted(database, schema string) bool
IsSchemaAccepted performs conservative partial evaluation at the schema level. Returns false only when it can definitively say no tuple (db, schema, *) would ever pass. Returns true (conservative) when uncertain. Returns true on nil receiver.
func (*ScopeFilter) SchemaSQL ¶
func (f *ScopeFilter) SchemaSQL(dbCol, schemaCol string) (string, []any)
SchemaSQL generates a SQL WHERE condition fragment for schema-level filtering. Handles cross-level rules that involve both database and schema. Returns empty string and nil args if no applicable rules exist.
func (*ScopeFilter) TableSQL ¶
func (f *ScopeFilter) TableSQL(dbCol, schemaCol, tableCol string) (string, []any)
TableSQL generates a SQL WHERE condition fragment for table-level filtering. Handles cross-level rules that involve database, schema, and table. Returns empty string and nil args if no applicable rules exist.
type ScopeRule ¶
type ScopeRule struct {
Database string `yaml:"database,omitempty" json:"database,omitempty"`
Schema string `yaml:"schema,omitempty" json:"schema,omitempty"`
Table string `yaml:"table,omitempty" json:"table,omitempty"`
}
ScopeRule is a multi-level pattern. All non-empty fields must match for the rule to apply. Empty field = match anything at that level. Patterns support glob syntax where * matches zero or more characters.
type ScopedScrapper ¶
type ScopedScrapper struct {
// contains filtered or unexported fields
}
ScopedScrapper wraps a Scrapper with a base ScopeFilter. It injects the base scope into every call's context and post-filters results. Callers can further narrow the scope via WithScope on the context.
func NewScopedScrapper ¶
func NewScopedScrapper(inner scrapper.Scrapper, baseScope *ScopeFilter) *ScopedScrapper
NewScopedScrapper creates a ScopedScrapper wrapping inner with the given base scope. If baseScope is nil, the wrapper still implements Scrapper but does no filtering.
func (*ScopedScrapper) BaseScope ¶
func (s *ScopedScrapper) BaseScope() *ScopeFilter
BaseScope returns the base scope filter configured for this scrapper.
func (*ScopedScrapper) Close ¶
func (s *ScopedScrapper) Close() error
func (*ScopedScrapper) DialectType ¶
func (s *ScopedScrapper) DialectType() string
func (*ScopedScrapper) IsPermissionError ¶
func (s *ScopedScrapper) IsPermissionError(err error) bool
func (*ScopedScrapper) QueryCatalog ¶
func (s *ScopedScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)
func (*ScopedScrapper) QueryCustomMetrics ¶
func (s *ScopedScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)
func (*ScopedScrapper) QueryDatabases ¶
func (s *ScopedScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)
func (*ScopedScrapper) QuerySegments ¶
func (s *ScopedScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)
func (*ScopedScrapper) QueryShape ¶
func (s *ScopedScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)
func (*ScopedScrapper) QuerySqlDefinitions ¶
func (s *ScopedScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)
func (*ScopedScrapper) QueryTableConstraints ¶
func (s *ScopedScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)
func (*ScopedScrapper) QueryTableMetrics ¶
func (s *ScopedScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)
func (*ScopedScrapper) QueryTables ¶
func (*ScopedScrapper) SqlDialect ¶
func (s *ScopedScrapper) SqlDialect() sqldialect.Dialect
func (*ScopedScrapper) ValidateConfiguration ¶
func (s *ScopedScrapper) ValidateConfiguration(ctx context.Context) (warnings []string, err error)