Documentation
¶
Overview ¶
Package bigquery provides a gollem.ToolSet for querying Google Cloud BigQuery, inspecting table schemas, and retrieving SQL runbook entries.
Package bigquery provides a gollem.ToolSet for querying Google Cloud BigQuery and inspecting table schemas and runbooks.
Index ¶
- type ColumnConfig
- type Config
- type Option
- func WithConfigFiles(paths []string) Option
- func WithCredentials(path string) Option
- func WithImpersonateServiceAccount(sa string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithRunbookPaths(paths []string) Option
- func WithScanLimit(s string) Option
- func WithStorageBucket(bucket string) Option
- func WithStoragePrefix(prefix string) Option
- func WithTimeout(d time.Duration) Option
- type PartitioningConfig
- type RunbookEntries
- type RunbookEntry
- type RunbookID
- type ToolSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnConfig ¶
type ColumnConfig struct {
Name string `yaml:"name" json:"name"`
Description string `yaml:"description" json:"description"`
ValueExample string `yaml:"value_example" json:"value_example"`
// Type is the BigQuery field type (STRING, INTEGER, FLOAT, BOOLEAN,
// TIMESTAMP, DATE, TIME, DATETIME, BYTES, RECORD).
Type string `yaml:"type" json:"type"`
// Fields holds nested column definitions for RECORD type columns.
Fields []ColumnConfig `yaml:"fields" json:"fields"`
}
ColumnConfig describes a single BigQuery table column.
type Config ¶
type Config struct {
DatasetID string `yaml:"dataset_id" json:"dataset_id"`
TableID string `yaml:"table_id" json:"table_id"`
Description string `yaml:"description" json:"description"`
Columns []ColumnConfig `yaml:"columns" json:"columns"`
Partitioning PartitioningConfig `yaml:"partitioning" json:"partitioning"`
// RunbookPaths is an optional per-config list of SQL runbook file paths or
// directories. These are merged with the top-level WithRunbookPaths option.
RunbookPaths []string `yaml:"runbook_paths" json:"runbook_paths"`
}
Config describes a BigQuery table's metadata for the tool. It is loaded from YAML configuration files at construction time.
type Option ¶
type Option func(*ToolSet)
Option configures a ToolSet.
func WithConfigFiles ¶
WithConfigFiles sets YAML configuration file or directory paths. Each entry may be a file (*.yaml / *.yml) or a directory that is walked recursively. At least one valid config file is required for most tool operations.
func WithCredentials ¶
WithCredentials sets the path to a Google Cloud service account credentials JSON file. When empty, Application Default Credentials are used.
func WithImpersonateServiceAccount ¶
WithImpersonateServiceAccount sets a service account email for impersonation. When set, the tool obtains short-lived credentials for that account.
func WithLogger ¶
WithLogger sets the structured logger. A nil logger keeps slog.Default().
func WithRunbookPaths ¶
WithRunbookPaths sets file or directory paths from which SQL runbook entries are loaded (*.sql files). Runbooks are loaded once during New.
func WithScanLimit ¶
WithScanLimit sets the maximum bytes a query may scan (parsed via go-humanize, e.g. "10GB"). Defaults to "10GB".
func WithStorageBucket ¶
WithStorageBucket sets the GCS bucket name used for storing intermediate query results. Required for bigquery_query / bigquery_result.
func WithStoragePrefix ¶
WithStoragePrefix sets an optional path prefix for GCS objects. For example, "tools/bq/" results in objects like "tools/bq/bigquery/<queryID>/data.json".
func WithTimeout ¶
WithTimeout sets the maximum time to wait for a BigQuery job to complete when calling bigquery_result. Defaults to 5 minutes.
type PartitioningConfig ¶
type PartitioningConfig struct {
Field string `yaml:"field" json:"field"`
Type string `yaml:"type" json:"type"`
TimeUnit string `yaml:"time_unit" json:"time_unit"`
}
PartitioningConfig describes BigQuery table partitioning settings.
type RunbookEntries ¶
type RunbookEntries []*RunbookEntry
RunbookEntries is a slice of RunbookEntry pointers.
type RunbookEntry ¶
type RunbookEntry struct {
ID RunbookID `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
SQLContent string `json:"sql_content"`
}
RunbookEntry represents a single SQL runbook loaded from a file.
type ToolSet ¶
type ToolSet struct {
// contains filtered or unexported fields
}
ToolSet implements gollem.ToolSet for Google Cloud BigQuery. All fields are unexported; configure via Option.
func New ¶
New constructs the ToolSet with the required projectID, applies opts, loads config files from disk, and loads runbook SQL files. No network I/O is performed; use Ping to verify connectivity.
func (*ToolSet) Ping ¶
Ping verifies connectivity by creating a BigQuery client. If the underlying client is a real *bigquery.Client, it calls Datasets to validate credentials and network access (iterating even a single entry proves the connection works; iterator.Done — no datasets — is also a success). If WithStorageBucket is set it also creates a GCS client.