Documentation
¶
Index ¶
- Variables
- func IsAnonymousResultTable(datasetId, tableId string) bool
- func QueryAndProcessMany[T any](ctx context.Context, conn Executor, sql string, ...) error
- func QueryMany[T any](ctx context.Context, conn Executor, sql string, ...) ([]*T, error)
- func ScopeFromConf(conf *BigQueryScrapperConf) *scope.ScopeFilter
- type BigQueryQueryLogSchema
- type BigQueryScrapper
- func (e *BigQueryScrapper) Capabilities() scrapper.Capabilities
- func (e *BigQueryScrapper) Close() error
- func (e *BigQueryScrapper) DialectType() string
- func (e *BigQueryScrapper) EstimateQuery(ctx context.Context, sql string) (*scrapper.QueryEstimate, error)
- func (e *BigQueryScrapper) Executor() *dwhexecbigquery.BigQueryExecutor
- func (s *BigQueryScrapper) FetchQueryLogs(ctx context.Context, from, to time.Time, obfuscator querylogs.QueryObfuscator) (querylogs.QueryLogIterator, error)
- func (e *BigQueryScrapper) FetchTableChangeHistory(ctx context.Context, fqn scrapper.DwhFqn, from, to time.Time, limit int) ([]*scrapper.TableChangeEvent, error)
- func (e *BigQueryScrapper) IsPermissionError(err error) bool
- func (e *BigQueryScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)
- func (e *BigQueryScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)
- func (e *BigQueryScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)
- func (e *BigQueryScrapper) QueryPlatformUsers(ctx context.Context) (*scrapper.PlatformUsers, error)
- func (e *BigQueryScrapper) QuerySchemas(ctx context.Context) ([]*scrapper.SchemaRow, error)
- func (e *BigQueryScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)
- func (e *BigQueryScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)
- func (e *BigQueryScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)
- func (e *BigQueryScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)
- func (e *BigQueryScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)
- func (e *BigQueryScrapper) QueryTables(ctx context.Context, opts ...scrapper.QueryTablesOption) ([]*scrapper.TableRow, error)
- func (e *BigQueryScrapper) RunRawQuery(ctx context.Context, sql string) (scrapper.RawQueryRowIterator, error)
- func (e *BigQueryScrapper) SqlDialect() sqldialect.Dialect
- func (e *BigQueryScrapper) ValidateConfiguration(ctx context.Context) ([]string, error)
- type BigQueryScrapperConf
- type BqQueryTable
- type Executor
- type RateLimitConfig
- type ShardedTable
Constants ¶
This section is empty.
Variables ¶
var BaseExpectedPermissions = []string{
"bigquery.datasets.get",
"bigquery.datasets.getIamPolicy",
"bigquery.jobs.create",
"bigquery.jobs.get",
"bigquery.jobs.list",
"bigquery.jobs.listAll",
"bigquery.routines.get",
"bigquery.routines.list",
"bigquery.tables.get",
"bigquery.tables.list",
"resourcemanager.projects.get",
}
var DefaultRateLimitConfig = RateLimitConfig{ MaxRetries: 5, BaseDelay: 1 * time.Second, MaxDelay: 30 * time.Second, MetadataConcurrency: 20, CallTimeout: 60 * time.Second, }
Functions ¶
func IsAnonymousResultTable ¶ added in v0.21.0
IsAnonymousResultTable says whether a job's destination table is the anonymous table BigQuery writes a result into when the job names no destination of its own. It expires with the cached result and is never written by anything else, so it is no output of the job. A customer's dataset starting with an underscore, and a script's temporary tables (`_script…`), are tables.
func QueryAndProcessMany ¶
func ScopeFromConf ¶ added in v0.10.0
func ScopeFromConf(conf *BigQueryScrapperConf) *scope.ScopeFilter
ScopeFromConf translates the BigQuery config's Datasets allowlist and Blocklist into a ScopeFilter.
- Datasets (allowlist) maps to Include rules at the schema level.
- Blocklist (comma-separated patterns) maps to Exclude rules at the schema level.
Returns nil if neither field is configured — callers treat nil as accept-all.
Types ¶
type BigQueryQueryLogSchema ¶ added in v0.5.0
type BigQueryQueryLogSchema struct {
CreationTime time.Time `bigquery:"creation_time"`
ProjectId bigquery.NullString `bigquery:"project_id"`
ProjectNumber bigquery.NullInt64 `bigquery:"project_number"`
UserEmail bigquery.NullString `bigquery:"user_email"`
JobId bigquery.NullString `bigquery:"job_id"`
JobType bigquery.NullString `bigquery:"job_type"`
StatementType bigquery.NullString `bigquery:"statement_type"`
Priority bigquery.NullString `bigquery:"priority"`
StartTime time.Time `bigquery:"start_time"`
EndTime time.Time `bigquery:"end_time"`
Query bigquery.NullString `bigquery:"query"`
State bigquery.NullString `bigquery:"state"`
ReservationId bigquery.NullString `bigquery:"reservation_id"`
TotalBytesProcessed bigquery.NullInt64 `bigquery:"total_bytes_processed"`
TotalSlotMs bigquery.NullInt64 `bigquery:"total_slot_ms"`
ErrorResult *struct {
Reason bigquery.NullString `bigquery:"reason"`
Message bigquery.NullString `bigquery:"message"`
} `bigquery:"error_result"`
CacheHit bigquery.NullBool `bigquery:"cache_hit"`
DestinationTable *BqQueryTable `bigquery:"destination_table"`
ReferencedTables []*BqQueryTable `bigquery:"referenced_tables"`
Labels []*struct {
Key bigquery.NullString `bigquery:"key"`
Value bigquery.NullString `bigquery:"value"`
} `bigquery:"labels"`
JobStages []*struct {
Name bigquery.NullString `bigquery:"name"`
RecordsRead bigquery.NullInt64 `bigquery:"records_read"`
RecordsWritten bigquery.NullInt64 `bigquery:"records_written"`
Status bigquery.NullString `bigquery:"status"`
} `bigquery:"job_stages"`
TotalBytesBilled bigquery.NullInt64 `bigquery:"total_bytes_billed"`
TransactionId bigquery.NullString `bigquery:"transaction_id"`
ParentJobId bigquery.NullString `bigquery:"parent_job_id"`
TransferredBytes bigquery.NullInt64 `bigquery:"transferred_bytes"`
// QueryHashes is read from query_info (see queryLogColumnExpressions).
QueryHashes *struct {
NormalizedLiterals bigquery.NullString `bigquery:"normalized_literals"`
} `bigquery:"query_hashes"`
// SessionId is read from session_info (see queryLogColumnExpressions).
SessionId bigquery.NullString `bigquery:"session_id"`
// BiEngineMode is read from bi_engine_statistics (see queryLogColumnExpressions). NULL for a job
// BI Engine did not see.
BiEngineMode bigquery.NullString `bigquery:"bi_engine_mode"`
}
type BigQueryScrapper ¶
type BigQueryScrapper struct {
// contains filtered or unexported fields
}
func NewBigQueryScrapper ¶
func NewBigQueryScrapper(ctx context.Context, conf *BigQueryScrapperConf) (*BigQueryScrapper, error)
func (*BigQueryScrapper) Capabilities ¶ added in v0.10.6
func (e *BigQueryScrapper) Capabilities() scrapper.Capabilities
func (*BigQueryScrapper) Close ¶
func (e *BigQueryScrapper) Close() error
func (*BigQueryScrapper) DialectType ¶ added in v0.1.8
func (e *BigQueryScrapper) DialectType() string
func (*BigQueryScrapper) EstimateQuery ¶ added in v0.16.0
func (e *BigQueryScrapper) EstimateQuery(ctx context.Context, sql string) (*scrapper.QueryEstimate, error)
EstimateQuery uses a BigQuery dry-run job to obtain an authoritative estimate of the bytes the query would process. A dry run does not execute the query and is not billed; BigQuery bills on TotalBytesProcessed, so this doubles as a cost estimate.
The dry-run job must be created with DryRun=true and read via query.Run only — job.Read errors on a dry-run job, so this cannot reuse RunRawQuery/QueryShape.
func (*BigQueryScrapper) Executor ¶
func (e *BigQueryScrapper) Executor() *dwhexecbigquery.BigQueryExecutor
func (*BigQueryScrapper) FetchQueryLogs ¶ added in v0.5.0
func (s *BigQueryScrapper) FetchQueryLogs( ctx context.Context, from, to time.Time, obfuscator querylogs.QueryObfuscator, ) (querylogs.QueryLogIterator, error)
func (*BigQueryScrapper) FetchTableChangeHistory ¶ added in v0.9.2
func (*BigQueryScrapper) IsPermissionError ¶ added in v0.1.1
func (e *BigQueryScrapper) IsPermissionError(err error) bool
func (*BigQueryScrapper) QueryCatalog ¶
func (e *BigQueryScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)
func (*BigQueryScrapper) QueryCustomMetrics ¶
func (e *BigQueryScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)
func (*BigQueryScrapper) QueryDatabases ¶
func (e *BigQueryScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)
func (*BigQueryScrapper) QueryPlatformUsers ¶ added in v0.21.0
func (e *BigQueryScrapper) QueryPlatformUsers(ctx context.Context) (*scrapper.PlatformUsers, error)
QueryPlatformUsers reads two sources, kept apart:
- bigquery.service_accounts, every service account of the project, bound or not (an unbound one can still be granted access on a dataset), with its unique id, display name, description and disabled state;
- bigquery.iam_policy, the users and service accounts bound in the project's IAM policy, with the roles bound to each.
Neither fills in the other's facts; Reconcile does that. A source that could not be read is a state of the result (see platformUserSourceError), so a missing grant or a disabled API never fails the fetch.
func (*BigQueryScrapper) QuerySchemas ¶ added in v0.14.5
QuerySchemas lists BigQuery datasets as schemas. BigQuery has no instance concept: the GCP project is the database and a dataset is a schema, so SchemaRow.Instance stays empty, Database is the project and Schema is the dataset — consistent with QueryTables.
func (*BigQueryScrapper) QuerySegments ¶
func (e *BigQueryScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)
func (*BigQueryScrapper) QueryShape ¶ added in v0.8.3
func (e *BigQueryScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)
func (*BigQueryScrapper) QuerySqlDefinitions ¶
func (e *BigQueryScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)
func (*BigQueryScrapper) QueryTableConstraints ¶ added in v0.9.0
func (e *BigQueryScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)
func (*BigQueryScrapper) QueryTableMetrics ¶
func (e *BigQueryScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)
QueryTableMetrics collects table metrics (row counts, sizes, freshness) via the BigQuery Tables.Get API. Covers all table types including materialized views. Requires bigquery.tables.get + bigquery.tables.list (metadata permissions).
func (*BigQueryScrapper) QueryTables ¶
func (e *BigQueryScrapper) QueryTables(ctx context.Context, opts ...scrapper.QueryTablesOption) ([]*scrapper.TableRow, error)
func (*BigQueryScrapper) RunRawQuery ¶ added in v0.13.7
func (e *BigQueryScrapper) RunRawQuery(ctx context.Context, sql string) (scrapper.RawQueryRowIterator, error)
func (*BigQueryScrapper) SqlDialect ¶ added in v0.1.8
func (e *BigQueryScrapper) SqlDialect() sqldialect.Dialect
func (*BigQueryScrapper) ValidateConfiguration ¶
func (e *BigQueryScrapper) ValidateConfiguration(ctx context.Context) ([]string, error)
type BigQueryScrapperConf ¶
type BigQueryScrapperConf struct {
dwhexecbigquery.BigQueryConf
// Blocklist is a comma-separated list of dataset name patterns to exclude.
Blocklist string
// RateLimitCfg overrides the default rate limit configuration for BQ API calls.
RateLimitCfg *RateLimitConfig
// Datasets is an explicit list of dataset names to scrape. When set, only these
// datasets are queried instead of listing all datasets in the project via API.
// This is required for customers who grant permissions at the dataset level and
// lack project-level bigquery.datasets.list permission.
Datasets []string
}
BigQueryScrapperConf configures BigQuery metadata scrapping.
type BqQueryTable ¶ added in v0.5.0
type BqQueryTable struct {
ProjectId bigquery.NullString `bigquery:"project_id"`
DatasetId bigquery.NullString `bigquery:"dataset_id"`
TableId bigquery.NullString `bigquery:"table_id"`
}
type RateLimitConfig ¶ added in v0.12.7
type RateLimitConfig struct {
// MaxRetries is the maximum number of retry attempts for rate-limited requests.
MaxRetries int
// BaseDelay is the initial backoff delay before the first retry.
BaseDelay time.Duration
// MaxDelay caps the exponential backoff.
MaxDelay time.Duration
// MetadataConcurrency limits the number of concurrent table.Metadata() calls.
MetadataConcurrency int
// CallTimeout bounds each individual BigQuery API call — including the
// client's own internal retries. It is the real guard against a stalled
// metadata call hanging a scrape: the BigQuery client retries a fast-failing
// request forever, so only a context deadline stops it. Without this a single
// blackholed call blocks until the caller's context (e.g. a 2h job timeout)
// fires, wedging the whole concurrent fan-out behind it. Zero disables the
// per-call bound.
//
// The default is generous on purpose: in practice these calls run ~100ms
// (p99.9 ~0.6s; the slowest observed across ~10M calls/day was ~29s), so 60s
// is ~2x the real-world worst case — it never trips a healthy call but still
// catches a hang within a minute instead of hours.
CallTimeout time.Duration
}
RateLimitConfig controls retry behavior for BigQuery API rate limits.
Source Files
¶
- bigquery.go
- query.go
- query_catalog.go
- query_custom_metrics.go
- query_databases.go
- query_estimate.go
- query_logs.go
- query_platform_users.go
- query_schemas.go
- query_segments.go
- query_shape.go
- query_sql_definitions.go
- query_table_constraints.go
- query_table_metrics.go
- query_tables.go
- retry.go
- run_raw_query.go
- scope.go
- scrape_error.go
- shape_columns.go
- shards.go
- table_change_history.go