sql

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequired          = xerror.TransformSQLRequired()
	ErrNotSelect         = xerror.TransformSQLNotSelect()
	ErrMultiStatement    = xerror.TransformSQLMultiStatement()
	ErrFeatureNotAllowed = xerror.TransformSQLFeatureNotAllowed()
	ErrContractInvalid   = xerror.TransformContractInvalid()
	ErrContractType      = xerror.TransformContractTypeMismatch()
	ErrContractMissing   = xerror.TransformContractMissingField()
	ErrTypeInput         = xerror.TransformTypeValidationInput()

	ErrRuntimeProjectionExpressionUnsupported   = xerror.TransformRuntimeProjectionExpressionUnsupported()
	ErrRuntimeProjectionFieldNotFound           = xerror.TransformRuntimeProjectionFieldNotFound()
	ErrRuntimeAggregateExpressionUnsupported    = xerror.TransformRuntimeAggregateExpressionUnsupported()
	ErrRuntimeAggregateColumnReference          = xerror.InvalidTransformRuntimeAggregateColumnReferenceRequired()
	ErrRuntimeWhereExpressionUnsupported        = xerror.TransformRuntimeWhereExpressionUnsupported()
	ErrRuntimeOutputKindUnsupported             = xerror.TransformRuntimeOutputKindUnsupported()
	ErrRuntimeHeadlessCSVNamedAccessUnsupported = xerror.TransformRuntimeHeadlessCSVNamedAccessUnsupported()
	ErrOutputContractViolation                  = xerror.TransformOutputContractViolation()

	ErrInvalidRuntimeLimits       = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_LIMITS_INVALID", "transform runtime limits are invalid")
	ErrWorkBudgetExceeded         = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_WORK_BUDGET_EXCEEDED", "transform work budget exceeded")
	ErrIntermediateRowsExceeded   = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_INTERMEDIATE_ROWS_BUDGET_EXCEEDED", "transform intermediate row budget exceeded")
	ErrIntermediateBytesExceeded  = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_INTERMEDIATE_BYTES_BUDGET_EXCEEDED", "transform intermediate byte budget exceeded")
	ErrOutputRowsExceeded         = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_OUTPUT_ROWS_BUDGET_EXCEEDED", "transform output row budget exceeded")
	ErrOutputBytesExceeded        = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_OUTPUT_BYTES_BUDGET_EXCEEDED", "transform output byte budget exceeded")
	ErrDepthBudgetExceeded        = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_DEPTH_BUDGET_EXCEEDED", "transform depth budget exceeded")
	ErrExecutionBudgetInterrupted = xerror.New(xerror.KindTimeout, "PIPELINE_TRANSFORM_EXECUTION_INTERRUPTED", "transform timeout or cancellation budget exceeded")
)
View Source
var ErrNumericConversion = xerror.New(xerror.KindInvalidInput, "PIPELINE_TRANSFORM_NUMERIC_CONVERSION", "unsupported transform numeric conversion")

ErrNumericConversion rejects unsupported ranges and lossy integer conversions.

Functions

func BuildTransformInputFieldTypes

func BuildTransformInputFieldTypes(
	dataSourceType model.DataSourceType,
	nativeFieldTypes map[string]string,
) map[string]model.ContractFieldType

BuildTransformInputFieldTypes normalizes introspected field types for input.

func ContractFieldFromNative

func ContractFieldFromNative(dataSourceType model.DataSourceType, name, nativeType string) pipepayload.ContractField

ContractFieldFromNative retains bounded precision/scale when the provider declares it. Unqualified native types keep their existing compatibility mapping.

func ContractFieldTypeFromNative

func ContractFieldTypeFromNative(
	dataSourceType model.DataSourceType,
	nativeType string,
) model.ContractFieldType

ContractFieldTypeFromNative maps datasource-native field type strings from schema introspection into the unified contract field type.

func InferOutputContractWithInputSchema

func InferOutputContractWithInputSchema(
	sql string,
	outputKind model.TransformOutputKind,
	dataSourceType model.DataSourceType,
	inputFieldTypes map[string]model.ContractFieldType,
) (*pipepayload.Contract, error)

InferOutputContractWithInputSchema derives a transform output contract from the SELECT projection using the same schema-aware inference as validation.

func ValidateOutputContract

func ValidateOutputContract(
	output *pipepayload.Output,
	contract *pipepayload.Contract,
) error

ValidateOutputContract checks runtime transform output against the declared contract. It dispatches by output kind so each representation can enforce shape rules consistently, and fails closed on unknown kinds to prevent silent validation gaps. Returns ErrOutputContractViolation (wrapped) on the first detected violation.

func ValidateOutputContractStructure

func ValidateOutputContractStructure(sql string, contract *pipepayload.Contract) error

ValidateOutputContractStructure validates only projection/contract structure. It is intended for load-time checks where datasource schema context is unavailable.

func ValidateOutputContractTypesWithInputSchema

func ValidateOutputContractTypesWithInputSchema(
	sql string,
	contract *pipepayload.Contract,
	dataSourceType model.DataSourceType,
	inputFieldTypes map[string]model.ContractFieldType,
) error

ValidateOutputContractTypesWithInputSchema validates output contract types using datasource context plus inferred input field types from schema introspection.

inputFieldTypes is a map of source field name -> contract field type for input columns/fields.

func ValidateOutputContractTypesWithInputSchemaForOutputKind

func ValidateOutputContractTypesWithInputSchemaForOutputKind(
	sql string,
	outputKind model.TransformOutputKind,
	contract *pipepayload.Contract,
	dataSourceType model.DataSourceType,
	inputFieldTypes map[string]model.ContractFieldType,
) error

ValidateOutputContractTypesWithInputSchemaForOutputKind validates output contract types after applying output_kind-specific serialization semantics.

func ValidateTransformInputRelationName

func ValidateTransformInputRelationName(name string) error

func ValidateTransformSQL

func ValidateTransformSQL(sql string) ([]string, error)

ValidateTransformSQL enforces the sql_v1 MVP contract for transform DSL. Returns (warnings, error): warnings are informational hints to surface to the user; they do not block the statement from being accepted.

Validation checks the supported SQL syntax and structure but does not infer or validate field types. Type enforcement is handled separately in ValidateOutputContractTypes once datasource context is available.

Types

type Limits

type Limits struct {
	MaxWork              int64
	MaxIntermediateRows  int
	MaxIntermediateBytes int64
	MaxOutputRows        int
	MaxOutputBytes       int64
	MaxDepth             int
	Timeout              time.Duration
}

Limits bounds one transform execution. Zero values leave the corresponding core limit disabled so callers can preserve the legacy runtime while deployment configuration supplies positive deny-by-default limits.

type Observer

type Observer func(Usage, error)

Observer receives aggregate usage and the final error without payload data.

type Runtime

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

func NewRuntime

func NewRuntime(configured ...Limits) Runtime

NewRuntime creates a transform runtime. The variadic parameter preserves source compatibility with the original no-argument constructor.

func (Runtime) Execute

func (r Runtime) Execute(
	transform Transform,
	upstreamPayloads map[string]*pipepayload.Payload,
) (*pipepayload.Output, error)

func (Runtime) ExecuteContext

func (r Runtime) ExecuteContext(
	ctx context.Context,
	transform Transform,
	upstreamPayloads map[string]*pipepayload.Payload,
) (output *pipepayload.Output, err error)

ExecuteContext executes a transform with cumulative per-execution budgets.

func (Runtime) WithObserver

func (r Runtime) WithObserver(observer Observer) Runtime

WithObserver returns a runtime that reports aggregate usage after execution.

type Transform

type Transform struct {
	SQL            string
	OutputKind     model.TransformOutputKind
	InputContract  *pipepayload.Contract
	InputContracts map[string]*pipepayload.Contract
	OutputContract *pipepayload.Contract
}

type Usage

type Usage struct {
	Work                 int64
	IntermediateRows     int64
	IntermediateBytes    int64
	OutputRows           int
	OutputBytes          int64
	MaxDepth             int
	Duration             time.Duration
	RoundedDecimalValues int64
	InexactDecimalValues int64
}

Usage contains only aggregate execution measurements safe for metrics.

Jump to

Keyboard shortcuts

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