queryplan

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package queryplan compiles native SysML document queries into immutable plans.

Index

Constants

View Source
const (
	RelatedAggregateList  = "list"
	RelatedAggregateCount = "count"
	RelatedAggregateAny   = "any"
)

The aggregates a related column reduces its traversal to.

View Source
const ArgumentTolerateUnevaluable = "tolerateUnevaluable"

ArgumentTolerateUnevaluable is the Project argument naming the properties a translated query did not ask for by name: a feature of that name whose value cannot be evaluated leaves its cell empty.

View Source
const InlineDocument = "<inline query>"

InlineDocument names the document and definition an inline query body is compiled as; no file is called this, so an origin in it is in the inline text.

Variables

This section is empty.

Functions

func IsQueryDefinition

func IsQueryDefinition(index *symbols.Index, model *semantics.Model, sym *symbols.Symbol) bool

IsQueryDefinition reports whether sym specializes DocumentQueries::Query.

func RelatedAggregateSupported

func RelatedAggregateSupported(aggregate string) bool

RelatedAggregateSupported reports whether aggregate names a related-column aggregate.

Types

type Argument

type Argument struct {
	Name  string
	Named bool
	Value Expression
}

Argument is one normalized invocation argument.

func Arg added in v0.13.0

func Arg(name string, value Expression) Argument

Arg names one argument of Operate.

type Definition

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

Definition is one reusable query definition in a compiled program.

func (Definition) Dependencies

func (d Definition) Dependencies() []string

Dependencies returns the invoked query definitions in encounter order.

func (Definition) Expression

func (d Definition) Expression() Expression

Expression returns an independent copy of the compiled result expression.

func (Definition) Name

func (d Definition) Name() string

Name returns the definition's fully qualified name.

func (Definition) Origin

func (d Definition) Origin() symbols.Origin

Origin returns the definition's declaration location.

func (Definition) Parameters

func (d Definition) Parameters() []Parameter

Parameters returns the definition's ordered effective inputs.

func (Definition) Result

func (d Definition) Result() Parameter

Result returns the definition's typed result parameter.

type Error

type Error struct {
	Kind      ErrorKind
	Query     string
	Target    string
	Parameter string
	Path      []string
	Expected  string
	Actual    string
	Origin    symbols.Origin
}

Error is a typed query-planning failure with its source location.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string

ErrorKind classifies a query-planning failure.

const (
	ErrorInvalidContext         ErrorKind = "invalid-context"
	ErrorLibraryUnavailable     ErrorKind = "library-unavailable"
	ErrorNotQueryDefinition     ErrorKind = "not-query-definition"
	ErrorMissingResultParameter ErrorKind = "missing-result-parameter"
	ErrorInvalidParameter       ErrorKind = "invalid-parameter"
	ErrorMissingResult          ErrorKind = "missing-result"
	ErrorConflictingResult      ErrorKind = "conflicting-result"
	ErrorUnsupportedResult      ErrorKind = "unsupported-result"
	ErrorUnknownInvocation      ErrorKind = "unknown-invocation"
	ErrorAmbiguousInvocation    ErrorKind = "ambiguous-invocation"
	ErrorPositionalQueryArgs    ErrorKind = "positional-query-arguments"
	ErrorDuplicateArgument      ErrorKind = "duplicate-argument"
	ErrorUnknownArgument        ErrorKind = "unknown-argument"
	ErrorMissingArgument        ErrorKind = "missing-argument"
	ErrorArgumentCount          ErrorKind = "argument-count"
	ErrorArgumentType           ErrorKind = "argument-type"
	ErrorArgumentMultiplicity   ErrorKind = "argument-multiplicity"
	ErrorCompositionCycle       ErrorKind = "composition-cycle"
	ErrorUnknownParameter       ErrorKind = "unknown-parameter"
	ErrorUnsupportedExpression  ErrorKind = "unsupported-expression"
	ErrorUnsupportedDefault     ErrorKind = "unsupported-default"
	ErrorDefaultType            ErrorKind = "default-type"
	ErrorDefaultMultiplicity    ErrorKind = "default-multiplicity"
	ErrorInvalidColumn          ErrorKind = "invalid-column"
	ErrorColumnSource           ErrorKind = "column-source"
	ErrorColumnName             ErrorKind = "column-name"
	ErrorUnknownColumnProperty  ErrorKind = "unknown-column-property"
	ErrorColumnOperator         ErrorKind = "column-operator"
	ErrorColumnType             ErrorKind = "column-type"
	ErrorDuplicateColumn        ErrorKind = "duplicate-column"
	ErrorEmptyProjection        ErrorKind = "empty-projection"
	ErrorColumnAggregate        ErrorKind = "column-aggregate"
	// ErrorCollectionFunction is a `->` function a cell cannot apply: unknown,
	// or given the wrong arguments.
	ErrorCollectionFunction ErrorKind = "collection-function"
)

func ErrorKinds added in v0.11.0

func ErrorKinds() []ErrorKind

ErrorKinds lists every error kind, in declaration order.

type Expression

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

Expression is one immutable node of a compiled query plan.

func BooleanLiteral added in v0.13.0

func BooleanLiteral(value bool, origin symbols.Origin) Expression

BooleanLiteral is a boolean literal.

func Literal added in v0.13.0

func Literal(kind LiteralKind, value string, origin symbols.Origin) Expression

Literal is a plan literal of the given kind.

func Operate added in v0.13.0

func Operate(operation Operation, origin symbols.Origin, arguments ...Argument) Expression

Operate is an operation applied to named arguments, each one of the library's parameters for it; an omitted defaulted parameter takes its default.

func ParameterRef added in v0.13.0

func ParameterRef(name string, origin symbols.Origin) Expression

ParameterRef reads the entry definition's parameter so named.

func Sequence added in v0.13.0

func Sequence(origin symbols.Origin, items ...Expression) Expression

Sequence concatenates the values of its operands, in order.

func StringLiteral added in v0.13.0

func StringLiteral(value string, origin symbols.Origin) Expression

StringLiteral is a string literal.

func (Expression) Arguments

func (e Expression) Arguments() []Argument

Arguments returns an independent copy of the expression's arguments.

func (Expression) Element

func (e Expression) Element() (*symbols.Symbol, bool)

Element returns the model element an element expression binds.

func (Expression) Literal

func (e Expression) Literal() (LiteralKind, string)

Literal returns the kind and source value of a literal expression.

func (Expression) Multiplicity added in v0.9.2

func (e Expression) Multiplicity() Multiplicity

Multiplicity returns the declared multiplicity of the feature or parameter a column expression reads, which bounds how many values a cell may hold.

func (Expression) Operation

func (e Expression) Operation() Operation

Operation returns the operation this expression performs.

func (Expression) Origin

func (e Expression) Origin() symbols.Origin

Origin returns the source expression that produced this plan node.

func (Expression) Quantity

func (e Expression) Quantity() (semantics.Quantity, bool)

Quantity returns an independent copy of a quantity literal's folded value and whether the expression is one.

func (Expression) Target

func (e Expression) Target() string

Target returns the parameter or query definition named by the expression.

type Inline added in v0.13.0

type Inline struct {
	// Index holds the model's documents (the same symbols) and the inline
	// definition; the model's own index is untouched.
	Index *symbols.Index
	// Entry is the inline definition, what Compile takes as its entry.
	Entry *symbols.Symbol
	// contains filtered or unexported fields
}

Inline is an inline query body, indexed as a query definition of its own beside the model's documents, so Compile plans it as one the model declares.

func ParseInline added in v0.13.0

func ParseInline(index *symbols.Index, text string) (*Inline, error)

ParseInline parses text as the result expression of a query definition and indexes it beside the model's documents, leaving index as it is.

func (*Inline) Locate added in v0.13.0

func (q *Inline) Locate(err error, origin symbols.Origin) error

Locate wraps err, reported at origin, as an InlineError when the origin is in the inline text; any other error is returned as it is.

func (*Inline) Position added in v0.13.0

func (q *Inline) Position(origin symbols.Origin) (source.Pos, bool)

Position locates an origin within the inline text, false for an origin elsewhere.

func (*Inline) Text added in v0.13.0

func (q *Inline) Text() string

Text is the inline text as written.

type InlineError added in v0.13.0

type InlineError struct {
	Message string
	// Pos is the 1-based line and column within the inline text.
	Pos source.Pos
	// Span is the faulty text's span, offsets within the inline text.
	Span source.Span
	// Text is the inline text, so a report can show the line under the fault.
	Text string
	// Err is the planning or execution error located, nil for a parse error.
	Err error
}

InlineError is a fault located within an inline query's text: a parse error, or a planning or execution error (Err) whose origin is in the text.

func (*InlineError) Error added in v0.13.0

func (e *InlineError) Error() string

func (*InlineError) Line added in v0.13.0

func (e *InlineError) Line() (string, int)

Line is the line of the inline text the fault is on and the byte offset of the fault within it.

func (*InlineError) Unwrap added in v0.13.0

func (e *InlineError) Unwrap() error

Unwrap exposes the located error, so its kind still decides how it is reported.

type LiteralKind

type LiteralKind string

LiteralKind classifies a literal retained in a query plan.

const (
	LiteralString   LiteralKind = "string"
	LiteralInteger  LiteralKind = "integer"
	LiteralReal     LiteralKind = "real"
	LiteralBoolean  LiteralKind = "boolean"
	LiteralInfinity LiteralKind = "infinity"
	LiteralNull     LiteralKind = "null"
	// LiteralQuantity is a magnitude in a unit, `2.5 [s]`, folded at planning.
	LiteralQuantity LiteralKind = "quantity"
)

type Multiplicity

type Multiplicity struct {
	Lower         int64
	Upper         int64
	UpperInfinite bool
	Known         bool
}

Multiplicity is the effective cardinality of a query parameter or of the feature a column reads.

func (Multiplicity) Admits added in v0.9.2

func (m Multiplicity) Admits(count int) bool

Admits reports whether a value count lies within a known multiplicity; an unknown multiplicity admits every count.

func (Multiplicity) String added in v0.9.2

func (m Multiplicity) String() string

String writes the multiplicity in notation form, `[lower..upper]`.

type Operation

type Operation string

Operation is one closed document-query planning operation.

const (
	OperationParameter     Operation = "parameter"
	OperationElement       Operation = "element"
	OperationLiteral       Operation = "literal"
	OperationSequence      Operation = "sequence"
	OperationInvoke        Operation = "invoke"
	OperationOwnedElements Operation = "owned-elements"
	OperationDescendants   Operation = "descendants"
	OperationAncestors     Operation = "ancestors"
	// OperationNamed resolves qualified names to the model elements they denote.
	OperationNamed Operation = "named"
	// OperationObjects enumerates the objects a session holds, by type.
	OperationObjects Operation = "objects"
	// OperationVerdicts checks the assertions about each source row's object.
	OperationVerdicts Operation = "verdicts"
	// OperationStates lists the active states of each source row's object.
	OperationStates Operation = "states"
	// OperationInState lists the session's objects whose machine is in a state.
	OperationInState Operation = "in-state"
	// OperationEvents reads the session's trace as time-ordered rows.
	OperationEvents          Operation = "events"
	OperationRelatedElements Operation = "related-elements"
	OperationWhereType       Operation = "where-type"
	OperationWhereMetadata   Operation = "where-metadata"
	OperationWhereName       Operation = "where-name"
	OperationWhereText       Operation = "where-text"
	OperationWhereFeature    Operation = "where-feature"
	OperationOrderBy         Operation = "order-by"
	OperationProject         Operation = "project"
	OperationColumn          Operation = "column"
	OperationRowProperty     Operation = "row-property"
	// OperationRowMember reads a feature reached through a member path nested
	// in the row element — a feature chain like `stat.runs`.
	OperationRowMember      Operation = "row-member"
	OperationColumnOperator Operation = "column-operator"
	// OperationRelatedColumn projects the elements a relationship reaches from each row.
	OperationRelatedColumn Operation = "related-column"
	// OperationWhereRelated keeps the source rows by whether a related element exists.
	OperationWhereRelated Operation = "where-related"
	// OperationExcept and OperationUnion are the ordered set operations over rows.
	OperationExcept Operation = "except"
	OperationUnion  Operation = "union"
	// OperationDiffer is the keyed value comparison of two projected row sets.
	OperationDiffer Operation = "differ"
	// OperationTree arranges rows as a containment tree, each with its depth.
	OperationTree Operation = "tree"
	// OperationVariable reads a cell's row parameter or the element a
	// collection body is bound to.
	OperationVariable Operation = "variable"
	// OperationNavigate reads one feature of each element its source yields.
	OperationNavigate Operation = "navigate"
	// OperationCollection applies a sequence function — `->size()`,
	// `->select {in e; …}` — to its source.
	OperationCollection Operation = "collection"
	// OperationLambda is the body a collection function evaluates once per
	// element, bound to the variable it names.
	OperationLambda Operation = "lambda"
)

type Parameter

type Parameter struct {
	Name         string
	Type         string
	Multiplicity Multiplicity
	HasDefault   bool
	Default      Expression
	DefaultQuery string
	Origin       symbols.Origin
}

Parameter is one typed query input or result. A defaulted input carries its compiled default and the query whose declaration supplied it.

type Program

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

Program is an immutable dependency-ordered query plan.

func Compile

func Compile(index *symbols.Index, model *semantics.Model, resolver *resolve.Resolver, entry *symbols.Symbol) (*Program, error)

Compile compiles entry and every query it invokes into dependency order.

func NewProgram added in v0.13.0

func NewProgram(name string, parameters []Parameter, result Parameter, expression Expression, origin symbols.Origin) *Program

NewProgram is a program of one entry definition over the given parameters, whose result is the expression.

func (*Program) Definitions

func (p *Program) Definitions() []Definition

Definitions returns dependencies before their consumers, each exactly once.

func (*Program) Entry

func (p *Program) Entry() string

Entry returns the fully qualified entry query name.

Jump to

Keyboard shortcuts

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