schema

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package schema provides the core data models and types for the tracking system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAllCoreColumnsPresent

func AssertAllCoreColumnsPresent(columns []Column, coreColumns []Interface) error

AssertAllCoreColumnsPresent validates that all core column interfaces have corresponding implementations.

func AssertAllDependenciesFulfilled

func AssertAllDependenciesFulfilled(
	columns []Column,
) error

AssertAllDependenciesFulfilled validates that all column dependencies are satisfied.

func AssertAllDependenciesFulfilledWithCoreColumns

func AssertAllDependenciesFulfilledWithCoreColumns(columns []Column, coreColumns []Interface) error

AssertAllDependenciesFulfilledWithCoreColumns validates that all column dependencies are satisfied and that all core columns are present.

func FromColumns

func FromColumns[T Column](columns []T) *arrow.Schema

FromColumns creates an Arrow schema from a slice of columns.

func SortByOrdering added in v0.10.0

func SortByOrdering[T Column](cols []T, ordering OrderKeeper) []T

SortByOrdering sorts a slice of columns according to their interface order.

func WithExtraFields

func WithExtraFields[T Column](columns []T, extraFields ...arrow.Field) *arrow.Schema

WithExtraFields creates an Arrow schema from columns with additional fields.

Types

type BrokenEventError added in v0.19.0

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

BrokenEventError is an error that occurs when an event doesn't have

all required information in order to be processed.

func NewBrokenEventError added in v0.19.0

func NewBrokenEventError(message string) *BrokenEventError

NewBrokenEventError creates a new BrokenEventError.

func (*BrokenEventError) Error added in v0.19.0

func (e *BrokenEventError) Error() string

func (*BrokenEventError) IsRetryable added in v0.19.0

func (e *BrokenEventError) IsRetryable() bool

type BrokenSessionError added in v0.19.0

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

BrokenSessionError is an error that occurs when a session is invalid.

func NewBrokenSessionError added in v0.19.0

func NewBrokenSessionError(message string) *BrokenSessionError

NewBrokenSessionError creates a new InvalidSessionError.

func (*BrokenSessionError) Error added in v0.19.0

func (e *BrokenSessionError) Error() string

func (*BrokenSessionError) IsRetryable added in v0.19.0

func (e *BrokenSessionError) IsRetryable() bool

type Column

type Column interface {
	Docs() Documentation
	Implements() Interface
	DependsOn() []DependsOnEntry
}

Column represents a column with metadata and dependencies.

func ToGenericColumns

func ToGenericColumns[T Column](columns []T) []Column

ToGenericColumns converts a slice of typed columns to a slice of generic Column interfaces.

type Columns

type Columns struct {
	Session            []SessionColumn
	Event              []EventColumn
	SessionScopedEvent []SessionScopedEventColumn
}

Columns groups the column sources for a table layout

func NewColumns

func NewColumns(session []SessionColumn, event []EventColumn, sessionScoped []SessionScopedEventColumn) Columns

NewColumns creates a new Columns struct with session, event and session-scoped-event columns.

func Sorted added in v0.10.0

func Sorted(columns Columns, ordering OrderKeeper) Columns

Sorted sorts a slice of columns according to their interface order.

func (Columns) Copy added in v0.10.1

func (c Columns) Copy() Columns

Copy returns a copy of the Columns struct.

type ColumnsRegistry

type ColumnsRegistry interface {
	Get(propertyID string) (Columns, error)
}

ColumnsRegistry is a registry of columns for different properties.

func NewColumnsMerger

func NewColumnsMerger(registries []ColumnsRegistry) ColumnsRegistry

NewColumnsMerger creates a new columns merger.

func NewStaticColumnsRegistry

func NewStaticColumnsRegistry(columns map[string]Columns, defaultColumns Columns) ColumnsRegistry

NewStaticColumnsRegistry creates a new static columns registry with the given columns.

type D8AColumnWriteError added in v0.19.0

type D8AColumnWriteError interface {
	Error() string
	IsRetryable() bool
}

type DependencySorter

type DependencySorter struct{}

DependencySorter provides topological sorting functionality for columns with dependencies.

func NewDependencySorter

func NewDependencySorter() *DependencySorter

NewDependencySorter creates a new dependency sorter.

func (*DependencySorter) SortAllColumns

func (s *DependencySorter) SortAllColumns(columns Columns) (Columns, error)

SortAllColumns sorts both session and event columns together, respecting cross-type dependencies.

func (*DependencySorter) SortEventColumns

func (s *DependencySorter) SortEventColumns(columns []EventColumn) ([]EventColumn, error)

SortEventColumns sorts event columns based on their dependencies.

func (*DependencySorter) SortSessionColumns

func (s *DependencySorter) SortSessionColumns(columns []SessionColumn) ([]SessionColumn, error)

SortSessionColumns sorts session columns based on their dependencies.

type DependsOnEntry

type DependsOnEntry struct {
	Interface        InterfaceID
	GreaterOrEqualTo Version
	LessThan         Version
}

DependsOnEntry represents a dependency requirement for a column.

type Documentation added in v0.9.0

type Documentation struct {
	ColumnName  string
	Type        *arrow.Field
	DisplayName string
	InterfaceID string
	Description string
}

Documentation represents the documentation for a column.

type Event

type Event struct {
	BoundHit *hits.Hit
	Metadata map[string]any
	Values   map[string]any

	IsBroken     bool
	BrokenReason string
}

Event represents a test event with bound hit and all hits.

func NewEvent added in v0.10.0

func NewEvent(boundHit *hits.Hit) *Event

NewEvent creates a new event with a bound hit and empty metadata and values.

func (*Event) WithValueKey added in v0.10.0

func (e *Event) WithValueKey(key string, value any) *Event

WithValueKey sets a value for a key in the event values.

type EventColumn

type EventColumn interface {
	Column
	Write(event *Event) D8AColumnWriteError
}

EventColumn represents a column that can be written to during event processing.

type Guard

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

Guard ensures that warehouse tables have the correct schema and columns.

func NewGuard

func NewGuard(
	warehouseRegistry warehouse.Registry,
	columnsColumns ColumnsRegistry,
	layout LayoutRegistry,
	ordering OrderKeeper,
) *Guard

NewGuard creates a new Guard

func (*Guard) EnsureTables

func (m *Guard) EnsureTables(
	propertyID string,
) error

EnsureTables creates tables and adds missing columns for the specified property.

type Interface

type Interface struct {
	ID      InterfaceID
	Version Version
	Field   *arrow.Field
}

Interface represents a virtual column, with given name, version and a field (including column name and type) Various parts of the system may then provide implementations of this interface. As example you can use something like "event_type". You may centrally define an abstract column interface, and then provide implementations in the protocols, which may have different understanding of what really means "event_type".

type InterfaceID

type InterfaceID string

InterfaceID represents a unique identifier for a column.

type InterfaceOrdering added in v0.10.0

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

InterfaceOrdering maintains the order of column interfaces based on their definition position in structs.

func NewInterfaceDefinitionOrderKeeper added in v0.10.1

func NewInterfaceDefinitionOrderKeeper(structs ...any) *InterfaceOrdering

NewInterfaceDefinitionOrderKeeper creates a new OrderKeeper instance, that tracks the order of columns using the definition position in structs.

func (*InterfaceOrdering) GetOrder added in v0.10.0

func (o *InterfaceOrdering) GetOrder(id InterfaceID) int

GetOrder returns the order index for a given interface ID. Returns math.MaxInt for unknown interfaces (they sort last).

type Layout

type Layout interface {
	Tables(columns Columns) []WithName
	ToRows(columns Columns, sessions ...*Session) ([]TableRows, error)
}

Layout is the interface for a table layout, implementations take control over the final schema and dictate the format of writing the session data to the table.

func NewEmbeddedSessionColumnsLayout

func NewEmbeddedSessionColumnsLayout(
	eventsTableName string,
	sessionColumnsPrefix string,
) Layout

NewEmbeddedSessionColumnsLayout creates a single table, with all the session columns embedded in the event table, with given prefix.

type LayoutRegistry

type LayoutRegistry interface {
	Get(propertyID string) (Layout, error)
}

LayoutRegistry is a registry of layouts for different properties.

func NewStaticLayoutRegistry

func NewStaticLayoutRegistry(layouts map[string]Layout, defaultLayout Layout) LayoutRegistry

NewStaticLayoutRegistry creates a new static layout registry with the given layouts.

type OrderKeeper added in v0.10.1

type OrderKeeper interface {
	GetOrder(id InterfaceID) int
}

OrderKeeper is a interface that can be used to get the order of a given interface ID.

func NewNoParticicularOrderKeeper added in v0.10.1

func NewNoParticicularOrderKeeper() OrderKeeper

NewNoParticicularOrderKeeper creates a new OrderKeeper that assigns an order to each interface ID in the order they are encountered, useful for testing or quick prototyping.

type RetryableError added in v0.19.0

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

func NewRetryableError added in v0.19.0

func NewRetryableError(message string) *RetryableError

func (*RetryableError) Error added in v0.19.0

func (e *RetryableError) Error() string

func (*RetryableError) IsRetryable added in v0.19.0

func (e *RetryableError) IsRetryable() bool

type Session

type Session struct {
	PropertyID string
	Metadata   map[string]any

	Events []*Event
	Values map[string]any

	IsBroken     bool
	BrokenReason string
}

Session represents a session with events and values.

func NewSession added in v0.10.0

func NewSession(events []*Event) *Session

NewSession creates a new session from a slice of events.

type SessionColumn

type SessionColumn interface {
	Column
	Write(session *Session) D8AColumnWriteError
}

SessionColumn represents a column that can be written to during session processing.

type SessionScopedEventColumn added in v0.2.0

type SessionScopedEventColumn interface {
	Column
	Write(session *Session, i int) D8AColumnWriteError
}

SessionScopedEventColumn represents a column computed with session scope that writes per-event values while having access to the whole session. It complements EventColumn and SessionColumn without changing their semantics.

type TableRows

type TableRows struct {
	Table string
	Rows  []map[string]any
}

TableRows are a collection of rows with a table to write them to

type Version

type Version string // semver

Version represents a semantic version string for a column.

type WithName

type WithName struct {
	Schema *arrow.Schema
	Table  string
}

WithName adds a table name to the schema

Jump to

Keyboard shortcuts

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