Documentation
¶
Index ¶
- Constants
- Variables
- func FirstSQLKeyword(sql string) string
- func IsDMLStatement(statementType string) bool
- func IsLikelyResultQuery(sql string) bool
- func IsNonResultStatement(summary *QueryExecutionSummary) bool
- func LogOrSinkQueryID(ctx context.Context, dbType string, queryID string)
- func LogQueryID(ctx context.Context, dbType string, queryID string)
- func QueryTypeFromContext(ctx context.Context) string
- func SQLStatementType(sql string) string
- func StatementTypeFromCommandTag(commandTag string) string
- func StripLeadingSQLComments(sql string) string
- func WithQueryIDSink(ctx context.Context, sink *string) context.Context
- func WithQueryType(ctx context.Context, queryType string) context.Context
- type DMLStatistics
- type DryRunColumn
- type DryRunResult
- type FileQuerySplitterExtractor
- func (f FileQuerySplitterExtractor) CloneForAsset(ctx context.Context, p *pipeline.Pipeline, t *pipeline.Asset) (QueryExtractor, error)
- func (f FileQuerySplitterExtractor) ExtractQueriesFromString(content string) ([]*Query, error)
- func (f FileQuerySplitterExtractor) ReextractQueriesFromSlice(content []string) ([]string, error)
- type Query
- type QueryDryRunner
- type QueryExecutionSummary
- type QueryExtractor
- type QueryResult
- type Renderer
- type WholeFileExtractor
- func (f *WholeFileExtractor) CloneForAsset(ctx context.Context, p *pipeline.Pipeline, t *pipeline.Asset) (QueryExtractor, error)
- func (f *WholeFileExtractor) ExtractQueriesFromString(content string) ([]*Query, error)
- func (f *WholeFileExtractor) ReextractQueriesFromSlice(content []string) ([]string, error)
Constants ¶
const ( QueryTypeMain = "main" QueryTypeColumn = "column" QueryTypeCustom = "custom" QueryTypeSensor = "sensor" QueryTypeQuery = "query" QueryTypeDiff = "diff" QueryTypeImport = "import" QueryTypePatch = "patch" QueryTypeDryRun = "dryrun" QueryTypePing = "ping" QueryTypeSchema = "schema" QueryTypeEnhance = "enhance" )
Query type labels used by backends (e.g. BigQuery) to tag jobs with a recognizable prefix so users can identify the source of a query in the platform's job/query history. Values are intentionally short and stable — they end up in user-visible identifiers.
Variables ¶
var DefaultJinjaRenderer = jinja.NewRenderer(jinja.Context{ "ds": time.Now().Format("2006-01-02"), "ds_nodash": time.Now().Format("20060102"), "data_interval_start": time.Now().AddDate(0, 0, -1).Format(time.RFC3339), "data_interval_end": time.Now().Format(time.RFC3339), "utils": map[string]interface{}{ "date_add": func(str string, days int) string { return str }, "date_format": func(str, inputFormat, outputFormat string) string { return str }, }, })
Functions ¶
func FirstSQLKeyword ¶ added in v0.11.582
func IsDMLStatement ¶ added in v0.11.582
func IsLikelyResultQuery ¶ added in v0.11.582
func IsNonResultStatement ¶ added in v0.11.582
func IsNonResultStatement(summary *QueryExecutionSummary) bool
func LogOrSinkQueryID ¶ added in v0.11.558
LogOrSinkQueryID either writes the query ID to the sink in the context (if one was set via WithQueryIDSink) or logs it to the console.
func LogQueryID ¶ added in v0.11.558
LogQueryID prints a database query ID to the console writer in the context. It is a no-op if the context has no writer or the queryID is empty.
func QueryTypeFromContext ¶ added in v0.11.587
QueryTypeFromContext returns the query type label set via WithQueryType, or the empty string if none was set.
func SQLStatementType ¶ added in v0.11.582
func StatementTypeFromCommandTag ¶ added in v0.11.582
func StripLeadingSQLComments ¶ added in v0.11.582
func WithQueryIDSink ¶ added in v0.11.558
WithQueryIDSink returns a context that captures query IDs into the given string pointer instead of logging them. This allows callers (e.g. sensors) to control when and whether to log the ID.
func WithQueryType ¶ added in v0.11.587
WithQueryType returns a context labeled with the kind of work driving the query. Backends may read this label to tag their jobs (e.g. BigQuery uses it as a job ID prefix). Empty types are ignored.
Types ¶
type DMLStatistics ¶ added in v0.11.582
type DryRunColumn ¶ added in v0.11.475
DryRunColumn represents a single column in the output schema of a dry-run result.
type DryRunResult ¶ added in v0.11.475
type DryRunResult struct {
// ConnectionType identifies the database backend (e.g., "bigquery", "snowflake", "postgres").
ConnectionType string `json:"connectionType"`
// Valid indicates whether the query passed validation without errors.
Valid bool `json:"valid"`
// BigQuery-specific fields
TotalBytesProcessed int64 `json:"totalBytesProcessed,omitempty"`
EstimatedCostUSD float64 `json:"estimatedCostUSD,omitempty"`
StatementType string `json:"statementType,omitempty"`
ReferencedTables []string `json:"referencedTables,omitempty"`
Schema []DryRunColumn `json:"schema,omitempty"`
// EXPLAIN-based databases populate this with the query plan output.
ExplainRows *QueryResult `json:"explainRows,omitempty"`
}
DryRunResult holds the output of a dry-run operation. Different databases populate different fields depending on their capabilities.
type FileQuerySplitterExtractor ¶
type FileQuerySplitterExtractor struct {
Fs afero.Fs
Renderer jinja.RendererInterface
}
FileQuerySplitterExtractor is a regular file extractor, but it splits the queries in the given file into multiple instances. For usecases that require EXPLAIN statements, such as validating Snowflake queries, it is not possible to use a single query with multiple statements, so we need to split them into multiple queries.
func (FileQuerySplitterExtractor) CloneForAsset ¶ added in v0.11.230
func (f FileQuerySplitterExtractor) CloneForAsset(ctx context.Context, p *pipeline.Pipeline, t *pipeline.Asset) (QueryExtractor, error)
func (FileQuerySplitterExtractor) ExtractQueriesFromString ¶ added in v0.7.1
func (f FileQuerySplitterExtractor) ExtractQueriesFromString(content string) ([]*Query, error)
func (FileQuerySplitterExtractor) ReextractQueriesFromSlice ¶ added in v0.11.230
func (f FileQuerySplitterExtractor) ReextractQueriesFromSlice(content []string) ([]string, error)
type QueryDryRunner ¶ added in v0.11.475
type QueryDryRunner interface {
DryRunQuery(ctx context.Context, q *Query) (*DryRunResult, error)
}
QueryDryRunner is an optional interface that database connections can implement to support dry-run / explain functionality for the "bruin query --dry-run" command.
type QueryExecutionSummary ¶ added in v0.11.582
type QueryExecutionSummary struct {
ConnectionType string `json:"connectionType,omitempty"`
JobID string `json:"jobId,omitempty"`
StatementType string `json:"statementType,omitempty"`
TotalBytesProcessed int64 `json:"totalBytesProcessed,omitempty"`
TotalBytesBilled int64 `json:"totalBytesBilled,omitempty"`
SlotMillis int64 `json:"slotMillis,omitempty"`
DMLAffectedRows *int64 `json:"dmlAffectedRows,omitempty"`
DMLStats *DMLStatistics `json:"dmlStats,omitempty"`
DDLOperationPerformed string `json:"ddlOperationPerformed,omitempty"`
DDLTargetTable string `json:"ddlTargetTable,omitempty"`
DDLTargetRoutine string `json:"ddlTargetRoutine,omitempty"`
}
QueryExecutionSummary holds metadata for a successfully executed statement. Databases populate this when a statement does not return a result set.
func NewExecutionSummaryFromStatement ¶ added in v0.11.582
func NewExecutionSummaryFromStatement(connectionType, statementType string, rowsAffected *int64) *QueryExecutionSummary
type QueryExtractor ¶ added in v0.11.182
type QueryResult ¶ added in v0.11.53
type QueryResult struct {
Columns []string
Rows [][]interface{}
ColumnTypes []string
Execution *QueryExecutionSummary
}
type WholeFileExtractor ¶
type WholeFileExtractor struct {
Fs afero.Fs
Renderer jinja.RendererInterface
}
WholeFileExtractor is a regular file extractor that returns the whole file content as the query string. It is useful for cases where the whole file content can be treated as a single query, such as validating GoogleCloudPlatform queries via dry-run.
func (*WholeFileExtractor) CloneForAsset ¶ added in v0.11.182
func (f *WholeFileExtractor) CloneForAsset(ctx context.Context, p *pipeline.Pipeline, t *pipeline.Asset) (QueryExtractor, error)
func (*WholeFileExtractor) ExtractQueriesFromString ¶ added in v0.7.1
func (f *WholeFileExtractor) ExtractQueriesFromString(content string) ([]*Query, error)
func (*WholeFileExtractor) ReextractQueriesFromSlice ¶ added in v0.11.165
func (f *WholeFileExtractor) ReextractQueriesFromSlice(content []string) ([]string, error)