validation

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package validation provides dependency validation for CBT models

Package validation provides dependency validation for CBT models

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotSQLModel is returned when external model is not a SQL model
	ErrNotSQLModel = errors.New("external model is not a SQL model")
	// ErrInvalidUint64 is returned when a value cannot be unmarshaled as uint64
	ErrInvalidUint64 = errors.New("failed to unmarshal value as uint64")
)
View Source
var (
	ErrModelNotFound               = errors.New("model not found")
	ErrDependencyNotFound          = errors.New("dependency model not found")
	ErrRangeNotAvailable           = errors.New("required range not available")
	ErrRangeNotCovered             = errors.New("range not fully covered")
	ErrNotTransformationModel      = errors.New("model is not a transformation")
	ErrInvalidDependencyType       = errors.New("invalid dependency type")
	ErrInvalidModelType            = errors.New("invalid dependency model type")
	ErrFailedModelCast             = errors.New("failed to cast model to transformation")
	ErrInsufficientRange           = errors.New("insufficient dependency range for interval")
	ErrNoORDependencyAvailable     = errors.New("no dependencies in OR group are available")
	ErrUninitializedTransformation = errors.New("transformation dependency has not been initialized")
)

Validation-specific errors

Functions

This section is empty.

Types

type ExternalModelValidator

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

ExternalModelValidator implements the ExternalModelExecutor interface

func NewExternalModelExecutor

func NewExternalModelExecutor(log logrus.FieldLogger, chClient clickhouse.ClientInterface, adminService admin.Service, modelsService models.Service) *ExternalModelValidator

NewExternalModelExecutor creates a new external model executor The cacheManager can be nil if caching is not desired

func (*ExternalModelValidator) GetMinMax

func (e *ExternalModelValidator) GetMinMax(ctx context.Context, model models.External) (minPos, maxPos uint64, err error)

GetMinMax retrieves the min and max position values for an external model

type ExternalValidator added in v0.0.2

type ExternalValidator interface {
	GetMinMax(ctx context.Context, model models.External) (uint64, uint64, error)
}

ExternalValidator defines the interface for external model validation

type FlexUint64 added in v0.0.2

type FlexUint64 uint64

FlexUint64 is a custom type that can unmarshal from both string and number JSON values

func (*FlexUint64) UnmarshalJSON added in v0.0.2

func (f *FlexUint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexUint64

type MockValidator added in v0.0.2

type MockValidator struct {

	// Control behavior
	ValidateDependenciesFunc func(ctx context.Context, modelID string, position, interval uint64) (Result, error)
	GetInitialPositionFunc   func(ctx context.Context, modelID string) (uint64, error)
	GetEarliestPositionFunc  func(ctx context.Context, modelID string) (uint64, error)
	GetValidRangeFunc        func(ctx context.Context, modelID string) (uint64, uint64, error)

	// Track calls for assertions
	ValidateCalls   []ValidateCall
	InitialCalls    []string
	EarliestCalls   []string
	ValidRangeCalls []string
	// contains filtered or unexported fields
}

MockValidator is a mock implementation of Validator for testing

func NewMockValidator added in v0.0.2

func NewMockValidator() *MockValidator

NewMockValidator creates a new mock validator

func (*MockValidator) AssertValidateCalledWith added in v0.0.2

func (m *MockValidator) AssertValidateCalledWith(modelID string, position, interval uint64) bool

AssertValidateCalledWith checks if ValidateDependencies was called with specific args

func (*MockValidator) GetEarliestPosition added in v0.0.2

func (m *MockValidator) GetEarliestPosition(ctx context.Context, modelID string) (uint64, error)

GetEarliestPosition implements Validator

func (*MockValidator) GetInitialPosition added in v0.0.2

func (m *MockValidator) GetInitialPosition(ctx context.Context, modelID string) (uint64, error)

GetInitialPosition implements Validator

func (*MockValidator) GetValidRange added in v0.0.2

func (m *MockValidator) GetValidRange(ctx context.Context, modelID string) (minPos, maxPos uint64, err error)

GetValidRange implements Validator

func (*MockValidator) GetValidateCallCount added in v0.0.2

func (m *MockValidator) GetValidateCallCount() int

GetValidateCallCount returns the number of ValidateDependencies calls

func (*MockValidator) Reset added in v0.0.2

func (m *MockValidator) Reset()

Reset clears all recorded calls

func (*MockValidator) ValidateDependencies added in v0.0.2

func (m *MockValidator) ValidateDependencies(ctx context.Context, modelID string, position, interval uint64) (Result, error)

ValidateDependencies implements Validator

type Result

type Result struct {
	CanProcess bool
	Errors     []error
}

Result contains the result of dependency validation

type ValidateCall added in v0.0.2

type ValidateCall struct {
	ModelID  string
	Position uint64
	Interval uint64
}

ValidateCall records a ValidateDependencies call

type Validator added in v0.0.2

type Validator interface {
	// ValidateDependencies checks if all dependencies are satisfied for a given position
	ValidateDependencies(ctx context.Context, modelID string, position, interval uint64) (Result, error)

	// GetInitialPosition calculates the initial position for a model based on its dependencies
	GetInitialPosition(ctx context.Context, modelID string) (uint64, error)

	// GetEarliestPosition gets the earliest available position for a model
	GetEarliestPosition(ctx context.Context, modelID string) (uint64, error)

	// GetValidRange returns the valid position range [min, max] for a model based on its dependencies
	// min = MAX(MIN(external_mins), MAX(transformation_mins))
	// max = MIN(MAX(external_maxs), MIN(transformation_maxs))
	GetValidRange(ctx context.Context, modelID string) (minPos, maxPos uint64, err error)
}

Validator defines the interface for dependency validation (ethPandaOps pattern)

func NewDependencyValidator

func NewDependencyValidator(
	log logrus.FieldLogger,
	chClient clickhouse.ClientInterface,
	adminService admin.Service,
	modelsService models.Service,
) Validator

NewDependencyValidator creates a new dependency validator

Jump to

Keyboard shortcuts

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