bigquerycommon

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BQTypeStringFromToolType

func BQTypeStringFromToolType(toolType string) (string, error)

BQTypeStringFromToolType converts a tool parameter type string to a BigQuery standard SQL type string.

func DryRunQuery

func DryRunQuery(ctx context.Context, restService *bigqueryrestapi.Service, projectID string, location string, sql string, params []*bigqueryrestapi.QueryParameter, connProps []*bigqueryapi.ConnectionProperty, maximumBytesBilled int64) (*bigqueryrestapi.Job, error)

DryRunQuery performs a dry run of the SQL query to validate it and get metadata.

func InitializeDatasetParameters

func InitializeDatasetParameters(
	allowedDatasets []string,
	defaultProjectID string,
	projectKey, datasetKey string,
	projectDescription, datasetDescription string,
) (projectParam, datasetParam parameters.Parameter)

InitializeDatasetParameters generates project and dataset tool parameters based on allowedDatasets.

func StripSingleQuotes added in v1.4.0

func StripSingleQuotes(s string) string

StripSingleQuotes removes leading and trailing single quotes from a string if both are present.

func TableParser

func TableParser(sql, defaultProjectID string) ([]string, error)

TableParser is the main entry point for parsing a SQL string to find all referenced table IDs. It handles multi-statement SQL, comments, and recursive parsing of EXECUTE IMMEDIATE statements.

func ValidColumnName added in v1.4.0

func ValidColumnName(s string) bool

ValidColumnName returns true if s is a safe BigQuery column name. Values that fail this check must not be interpolated as SQL identifiers or into single-quoted SQL string arguments that represent column references.

func ValidColumnParam added in v1.4.0

func ValidColumnParam(s string) bool

ValidColumnParam returns true if s (stripped of leading/trailing single quotes) is a safe column name.

func ValidContributionMetricParam added in v1.4.0

func ValidContributionMetricParam(s string) bool

ValidContributionMetricParam returns true if s (stripped of leading/trailing single quotes) is a safe contribution metric (does not contain single quotes).

func ValidTableID added in v1.4.0

func ValidTableID(s string) bool

ValidTableID returns true if s is a safe BigQuery table identifier of the form 'dataset.table' or 'project.dataset.table'. Values that fail this check must not be interpolated into backtick-quoted SQL.

Types

type MockSource added in v1.4.0

type MockSource struct {
	sources.Source
	CalledSQL       string
	Client          *bigqueryapi.Client
	AllowedDatasets []string
	RunSQLResult    any
	RunSQLError     error
}

MockSource is a reusable mock implementation of sources.Source for BigQuery tool tests.

func (*MockSource) BigQueryAllowedDatasets added in v1.4.0

func (m *MockSource) BigQueryAllowedDatasets() []string

func (*MockSource) BigQueryClient added in v1.4.0

func (m *MockSource) BigQueryClient() *bigqueryapi.Client

func (*MockSource) BigQuerySession added in v1.4.0

func (m *MockSource) BigQuerySession() bigqueryds.BigQuerySessionProvider

func (*MockSource) GetAuthTokenHeaderName added in v1.4.0

func (m *MockSource) GetAuthTokenHeaderName() string

func (*MockSource) GetMaximumBytesBilled added in v1.4.0

func (m *MockSource) GetMaximumBytesBilled() int64

func (*MockSource) IsDatasetAllowed added in v1.4.0

func (m *MockSource) IsDatasetAllowed(projectID, datasetID string) bool

func (*MockSource) RetrieveClientAndService added in v1.4.0

func (m *MockSource) RetrieveClientAndService(tools.AccessToken) (*bigqueryapi.Client, *bigqueryrestapi.Service, error)

func (*MockSource) RunSQL added in v1.4.0

func (m *MockSource) RunSQL(ctx context.Context, client *bigqueryapi.Client, sql string, queryType string, params []bigqueryapi.QueryParameter, connProps []*bigqueryapi.ConnectionProperty) (any, error)

func (*MockSource) UseClientAuthorization added in v1.4.0

func (m *MockSource) UseClientAuthorization() bool

type MockSourceProvider added in v1.4.0

type MockSourceProvider struct {
	tools.SourceProvider
	Source sources.Source
}

MockSourceProvider is a reusable mock implementation of tools.SourceProvider.

func (*MockSourceProvider) GetSource added in v1.4.0

func (m *MockSourceProvider) GetSource(name string) (sources.Source, bool)

Jump to

Keyboard shortcuts

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