fabric

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 29 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fabric implements a scrapper for Microsoft Fabric Warehouses and Lakehouse SQL analytics endpoints.

Fabric speaks T-SQL over TDS, so it shares the MSSQL executor and (mostly) the MSSQL dialect. It is a first-class scrapper rather than a thin MSSQL alias because Fabric Warehouse's metadata surface diverges meaningfully from SQL Server — no page-based storage stats, informational-only NOT ENFORCED constraints (including foreign keys), no extended properties, no NVARCHAR — so every metadata query here is written against the Fabric surface directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FabricQueryLogSchema

type FabricQueryLogSchema struct {
	Database      string     `db:"database_name"`
	QueryID       string     `db:"query_id"`
	LoginName     *string    `db:"login_name"`
	SubmitTime    *time.Time `db:"submit_time"`
	StartTime     *time.Time `db:"start_time"`
	EndTime       *time.Time `db:"end_time"`
	ElapsedMs     *int64     `db:"total_elapsed_time_ms"`
	RowCount      *int64     `db:"row_count"`
	Status        string     `db:"status"`
	StatementType *string    `db:"statement_type"`
	Command       *string    `db:"command"`

	SessionID                  *int64   `db:"session_id"`
	ConnectionID               *string  `db:"connection_id"`
	BatchID                    *string  `db:"batch_id"`
	RootBatchID                *string  `db:"root_batch_id"`
	ProgramName                *string  `db:"program_name"`
	QueryHash                  *string  `db:"query_hash"`
	Label                      *string  `db:"label"`
	SqlPoolName                *string  `db:"sql_pool_name"`
	ErrorCode                  *int64   `db:"error_code"`
	ResultCacheHit             *int64   `db:"result_cache_hit"`
	IsDistributed              *int64   `db:"is_distributed"`
	IsAccelerated              *int64   `db:"is_accelerated"`
	IsUsingExternalAPI         *int64   `db:"is_using_external_api"`
	AllocatedCpuTimeMs         *int64   `db:"allocated_cpu_time_ms"`
	DataScannedRemoteStorageMB *float64 `db:"data_scanned_remote_storage_mb"`
	DataScannedMemoryMB        *float64 `db:"data_scanned_memory_mb"`
	DataScannedDiskMB          *float64 `db:"data_scanned_disk_mb"`
}

FabricQueryLogSchema maps a row of queryinsights.exec_requests_history — Fabric Warehouse's query history surface (there is no Query Store). Each row is one request execution.

type FabricScrapper

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

func NewFabricScrapper

func NewFabricScrapper(ctx context.Context, conf *FabricScrapperConf) (*FabricScrapper, error)

func (*FabricScrapper) Capabilities

func (e *FabricScrapper) Capabilities() scrapper.Capabilities

func (*FabricScrapper) Close

func (e *FabricScrapper) Close() error

func (*FabricScrapper) DialectType

func (e *FabricScrapper) DialectType() string

func (*FabricScrapper) EstimateQuery

func (e *FabricScrapper) EstimateQuery(ctx context.Context, sql string) (*scrapper.QueryEstimate, error)

EstimateQuery is unsupported for Fabric Warehouse. Like SQL Server, the estimated plan is only available via the SHOWPLAN_XML session toggle (an XML document, not a queryable estimate) and depends on current statistics. Capabilities().EstimateQuery is left zero-valued so callers skip it.

func (*FabricScrapper) Executor

func (*FabricScrapper) FetchQueryLogs

func (e *FabricScrapper) FetchQueryLogs(
	ctx context.Context,
	from, to time.Time,
	obfuscator querylogs.QueryObfuscator,
) (querylogs.QueryLogIterator, error)

FetchQueryLogs streams query history from queryinsights.exec_requests_history.

Fabric has no Query Store; queryinsights is the query-history source (retained ~30 days). The schema exists only in Warehouses — a workspace SQL endpoint also exposes Lakehouse SQL endpoints, SQL databases and mirrored databases, none of which have queryinsights. So rather than one UNION ALL (which fails entirely the moment a single non-Warehouse database is in scope), this reads each in-scope database independently and skips any that raise the "Invalid object name" error for the queryinsights view. The [from, to] window is inlined as DATETIME2 literals rather than bound parameters.

func (*FabricScrapper) FetchTableChangeHistory added in v0.28.0

func (e *FabricScrapper) FetchTableChangeHistory(
	ctx context.Context,
	fqn scrapper.DwhFqn,
	from, to time.Time,
	limit int,
) ([]*scrapper.TableChangeEvent, error)

FetchTableChangeHistory returns the commits of the table's Delta log in OneLake that changed data and were written in [from, to], newest first, at most limit of them. The version is the Delta version of the commit. A commit that only compacts files or changes the table metadata is not an event.

It fails for a connection that cannot reach OneLake, for a database that no single storage item of the workspace names, and for a table with no Delta log.

func (*FabricScrapper) GetApiClient added in v0.28.0

func (e *FabricScrapper) GetApiClient() (*dwhexecfabric.APIClient, error)

GetApiClient returns the Fabric REST API client of the connection, built once with the same identity as the SQL connection. It returns dwhexecfabric.ErrNoAPICredential when the configuration holds only a pre-acquired SQL token.

func (*FabricScrapper) GetDatabasesToQuery

func (e *FabricScrapper) GetDatabasesToQuery(ctx context.Context) ([]string, error)

GetDatabasesToQuery returns the workspace databases each scrapper method should iterate — every database the connection can see (via sys.databases), narrowed by the effective (configured AND per-call) scope. This is the workspace-centric analogue of the Snowflake scrapper's method of the same name.

func (*FabricScrapper) GetExistingDbs

func (e *FabricScrapper) GetExistingDbs(ctx context.Context) ([]string, error)

GetExistingDbs returns the workspace databases visible to the connection, cached after the first call.

func (*FabricScrapper) IsPermissionError

func (e *FabricScrapper) IsPermissionError(err error) bool

func (*FabricScrapper) QueryCatalog

func (e *FabricScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)

func (*FabricScrapper) QueryCustomMetrics

func (e *FabricScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)

func (*FabricScrapper) QueryDatabases

func (e *FabricScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)

QueryDatabases lists the workspace databases in scope. The Fabric SQL endpoint is workspace-shared, so this returns every warehouse/lakehouse the connection can see (via sys.databases), narrowed by conf.Databases and the context scope filter — the same set the other scrapper methods iterate.

func (*FabricScrapper) QueryPlatformUsers added in v0.21.0

func (e *FabricScrapper) QueryPlatformUsers(ctx context.Context) (*scrapper.PlatformUsers, error)

QueryPlatformUsers reads two sources, each reported on its own:

  • fabric.workspace_role_assignments (Fabric REST API): Entra users by user principal name and service principals as <application id>@<tenant id>, which is how query history (queryinsights login_name) names them, with their workspace role. It needs the Member or Admin workspace role, and a credential that can call the API (not a pre-acquired SQL token).
  • fabric.sys.database_principals: the identities added to the connected database, with their database roles. A user of it carries the login the API source gives the same identity (matched by the GUID its SID encodes), so the two reconcile; without the API only the connection's own login is known, the others keep their database name.

A source that could not be read is reported refused when a grant would let it answer, unavailable when the connection's configuration cannot reach it (a pre-acquired SQL token, a host that names no workspace, a credential that cannot be built) or the SQL surface lacks the view, and failed otherwise (a 5xx, a timeout, a dropped connection).

func (*FabricScrapper) QueryRoutines added in v0.23.0

func (e *FabricScrapper) QueryRoutines(ctx context.Context) ([]*scrapper.RoutineRow, error)

QueryRoutines lists every in-scope database's routines. A database that fails fails the whole listing.

func (*FabricScrapper) QuerySchemas

func (e *FabricScrapper) QuerySchemas(ctx context.Context) ([]*scrapper.SchemaRow, error)

func (*FabricScrapper) QuerySegments

func (e *FabricScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)

func (*FabricScrapper) QueryShape

func (e *FabricScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)

func (*FabricScrapper) QuerySqlDefinitions

func (e *FabricScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)

func (*FabricScrapper) QueryTableConstraints

func (e *FabricScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)

func (*FabricScrapper) QueryTableMetrics

func (e *FabricScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)

QueryTableMetrics returns row counts for Fabric Warehouse tables.

This is intentionally NOT a metadata-level query: Fabric Warehouse exposes no working row-count metadata source. Verified live against the engine ("Azure SQL Data Warehouse 12.0.2000.8"):

  • sys.dm_db_partition_stats — "DMV is not supported"
  • sys.dm_pdw_nodes_db_partition_stats — invalid object name
  • sys.partitions.rows — NULL for user (columnar) tables
  • no sys.allocation_units / STATS_DATE (columnar parquet/Delta storage)

The official microsoft/dbt-fabric adapter's catalog macro likewise reads no row-count/size metadata (schema only) — there is no metadata source to read.

Row counts are therefore computed with a batched COUNT_BIG(*) over the in-scope base tables. COUNT is comparatively cheap on Fabric's columnar engine, but callers should still schedule this at a sane cadence. SizeBytes is left nil because Fabric surfaces no dependable value.

The SQL surface has no time of the last change either. With FetchLastLoadTime, UpdatedAt comes from the table's Delta log in OneLake (lastChanges). Without it, or if the log cannot be read, UpdatedAt is nil and the row count stays.

lastMetricsFetchTime is ignored: the row count has no cheaper read to skip, so every call recomputes counts.

Workspace-centric: the in-scope databases are iterated concurrently, and each table is counted with a three-part [db].[schema].[table] name. A database whose listing or any count fails is left out whole (readDatabases).

func (*FabricScrapper) QueryTables

func (e *FabricScrapper) QueryTables(ctx context.Context, opts ...scrapper.QueryTablesOption) ([]*scrapper.TableRow, error)

func (*FabricScrapper) RunRawQuery

func (*FabricScrapper) SqlDialect

func (e *FabricScrapper) SqlDialect() sqldialect.Dialect

func (*FabricScrapper) ValidateConfiguration

func (e *FabricScrapper) ValidateConfiguration(ctx context.Context) ([]string, error)

type FabricScrapperConf

type FabricScrapperConf struct {
	dwhexecfabric.FabricConf

	// Scope is the configured include/exclude filter over the workspace's
	// databases/schemas/tables (ScopeRule.database = Fabric database/warehouse,
	// .schema = schema, .table = table). It is the canonical scope encoding
	// (synq.common.v1.ScopeFilter, as Athena uses) rather than a legacy database
	// list. nil means the whole workspace. Per-call scope (scope.WithScope) can
	// only narrow within this configured scope, never escape it — see
	// effectiveScope.
	Scope *scope.ScopeFilter

	// FetchLastLoadTime makes QueryTableMetrics read the time of the last load
	// of each table (UpdatedAt) from its Delta log in OneLake. It costs about
	// three OneLake requests for each table on each call, and OneLake requests
	// use Fabric capacity, so it is off by default. FetchTableChangeHistory
	// reads the Delta log whatever its value.
	FetchLastLoadTime bool
}

FabricScrapperConf configures a Fabric scrapper. It embeds the executor conf (the connection surface) and adds scrapper-level options — keeping the scrape scope out of the connection config.

Jump to

Keyboard shortcuts

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