querytranslate

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: 18 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 querytranslate compiles OSLC Query 3.0 text and the SysML v2 API Query into document-query plans, so every query surface runs the native semantics of internal/doc/queryexec over one loaded model.

Index

Constants

View Source
const SelectAll = "*"

SelectAll is the wildcard oslc.select spells every property with.

View Source
const SourceParameter = "source"

SourceParameter is the entry query's parameter a frontend binds the elements the query considers to: the model's, or the scope's and everything nested.

Variables

View Source
var DefaultPrefixes = rdf.DefaultPrefixes

DefaultPrefixes are the prefixes available without an oslc.prefix binding: the ones the RDF conversion writes on every graph.

Functions

func DefaultProjection

func DefaultProjection() []string

DefaultProjection is what a query over elements selecting nothing reports: every queryable property but elementId, read from a conversion of the whole model and so reported only when named.

func IgnoredParameterNames

func IgnoredParameterNames() []string

IgnoredParameterNames returns the parameters this implementation accepts without reading, in stable order.

func OutcomeOf

func OutcomeOf(err error) *queryexec.Outcome

OutcomeOf is the QVTS record of a translator refusal that has one: an unknown property is a path error whose frontier lists the properties the query could have named, with the nearest.

func ParameterNames

func ParameterNames() []string

ParameterNames returns the query parameters this implementation reads, in stable order. It is what an unknown-parameter error lists.

func PrefixedPropertyNames

func PrefixedPropertyNames(prefixes map[string]string, table *Table) (names []string, unbound map[string][]string)

PrefixedPropertyNames returns the property names OSLC query text spells under prefixes, in stable order, along with the local names of every namespace those bindings leave unnamed, keyed by namespace. An oslc.prefix binding decides what the parser accepts, so a diagnostic reads the same map.

Types

type Comparison

type Comparison struct {
	Property string
	Operator Operator
	Values   []string
	Inverse  bool
}

Comparison keeps the rows a property of which compares to one of the values.

type Conjunction

type Conjunction struct {
	Terms []Constraint
}

Conjunction keeps the rows satisfying every term.

type Constraint

type Constraint interface {
	// contains filtered or unexported methods
}

Constraint is one node of a query's filter. Its unexported marker method closes the set to the forms this package declares.

type Context

type Context struct {
	Index *symbols.Index
	Model *semantics.Model
	// Table is the property table; built from Index and Model when nil.
	Table *Table
}

Context is what a translation reads of the model: its index and semantics, for the property table and the metaclasses a type test may name.

type Disjunction

type Disjunction struct {
	Terms []Constraint
}

Disjunction keeps the rows satisfying any term.

type Error

type Error struct {
	Kind    ErrorKind
	Message string
	// Property is the unknown property as the query wrote it, for
	// ErrUnknownProperty.
	Property string
	// Candidates are the names the query could have written in place of the
	// unknown one, sorted.
	Candidates []string
}

Error is a typed query refusal. A refusal must not be represented as an empty result, which is indistinguishable from a valid no-match.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind int

ErrorKind identifies a query the translator refuses.

const (
	// ErrUnknownProperty identifies a property the metamodel does not define.
	ErrUnknownProperty ErrorKind = iota + 1
	// ErrMalformed identifies malformed query syntax or structure.
	ErrMalformed
	// ErrUnorderedProperty identifies an ordered comparison on a property whose
	// values are not ordered, or instanceOf on a property other than the type.
	ErrUnorderedProperty
	// ErrUnparsableValue identifies a value an operator cannot compare.
	ErrUnparsableValue
	// ErrUnknownScope identifies a scope absent from the model.
	ErrUnknownScope
	// ErrNoModel identifies a query without a loaded model.
	ErrNoModel
	// ErrUnsupportedDisjunction identifies `or` in OSLC text, which the
	// language does not define.
	ErrUnsupportedDisjunction
	// ErrUnsupportedLiteral identifies an unsupported literal form.
	ErrUnsupportedLiteral
	// ErrUnsupportedInstanceTerm identifies an instance selection written where
	// it cannot be the root of the query: negated, scoped or under a disjunction.
	ErrUnsupportedInstanceTerm
	// ErrUnsupportedWildcard identifies the `*` value on a property other than
	// the multiplicity bounds, whose infinity it is.
	ErrUnsupportedWildcard
)

type Instances

type Instances struct {
	Elements []string
}

Instances selects the objects the session holds whose definition or usage is one of the named elements, by qualified name.

func ElementInstances

func ElementInstances(values []string) (Instances, bool, error)

ElementInstances reads a list of @type values as element IRIs of the RDF conversion (<urn:sysmlv2:element:id> or elmt:id), the objects of which an instance term selects; it reports false when no value is one, and an error when only some are.

type Operator

type Operator string

Operator is a comparison operator as a query writes it.

const (
	Equal        Operator = "="
	NotEqual     Operator = "!="
	Less         Operator = "<"
	Greater      Operator = ">"
	LessEqual    Operator = "<="
	GreaterEqual Operator = ">="
	In           Operator = "in"
	InstanceOf   Operator = "instanceOf"
)

type OrderTerm

type OrderTerm struct {
	Property string
	Desc     bool
}

OrderTerm is one sort key. Desc is true for a '-' prefix.

type Plan

type Plan struct {
	Program *queryplan.Program
	// Columns are the properties projected as written, a wildcard among them
	// as `*`; the result's columns name what it expanded to.
	Columns []string
	// Objects reports a query over the session's held objects, whose root is
	// Objects rather than the bound source.
	Objects bool
}

Plan is a translated query: the program to execute, bound at SourceParameter, and the columns its rows report, in order.

func Translate

func Translate(q Query, ctx Context, name string) (*Plan, error)

Translate compiles a query to a plan named name, refusing before any element is read what no model could evaluate: an unknown property, an operator its values cannot take, a value it cannot compare.

type Query

type Query struct {
	// Scope names the elements considered, with everything nested inside them;
	// empty considers the whole model.
	Scope       []string
	Select      []Selection
	Where       Constraint
	OrderBy     []OrderTerm
	SearchTerms []string
	// Spelling names, per reported column, the name the request asked for it by,
	// where that differs from the column name.
	Spelling map[string]string
	// Features are the properties the request named as features of the model
	// itself (OSLC's sysx: namespace), which the evaluator judges on its rows.
	Features map[string]bool
}

Query is the common representation OSLC text and the API Query parse into.

func ParseOSLC

func ParseOSLC(text string, table *Table) (Query, error)

ParseOSLC parses a where expression against the model's property table. It also accepts a query-parameter string, allowing callers to pass an HTTP-style OSLC query directly.

func ParseParameters

func ParseParameters(text string, table *Table) (Query, error)

ParseParameters parses oslc.where, oslc.select, oslc.orderBy, oslc.searchTerms and oslc.prefix parameters. Parameter text follows URL query decoding rules.

func (Query) Columns

func (q Query) Columns() []string

Columns are the names the query's selected properties are reported under: a property, or a dotted path for a nested selection.

func (Query) SpellingOf

func (q Query) SpellingOf(column string) string

SpellingOf returns the name the request asked for column by, so a frontend reports a result in terms its caller can ask the next query in.

type Scoped

type Scoped struct {
	Property string
	Inner    Constraint
}

Scoped keeps the rows one of whose Property values satisfies Inner.

type Selection

type Selection struct {
	Property string
	Nested   []Selection
}

Selection is one property to report, with the properties of the elements it holds when nested.

type Table

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

Table is the reflective property table of a loaded model: every feature the metamodel library declares on a metaclass, and the evaluator's own properties.

func NewTable

func NewTable(index *symbols.Index, model *semantics.Model) *Table

NewTable reads the metaclass declarations of the model's library. A model loaded without the library knows the evaluator's queryable properties alone.

func (*Table) Derived

func (t *Table) Derived(name string) bool

Derived reports whether name is a property of the evaluator's own.

func (*Table) DerivedNames

func (t *Table) DerivedNames() []string

DerivedNames lists the evaluator's own properties, sorted.

func (*Table) Known

func (t *Table) Known(name string) bool

Known reports whether name is a property the evaluator can read: of the metamodel, of the evaluator, or a dotted path whose every segment is one.

func (*Table) Metamodel

func (t *Table) Metamodel(name string) bool

Metamodel reports whether the metamodel declares a property so named.

func (*Table) MetamodelNames

func (t *Table) MetamodelNames() []string

MetamodelNames lists the metamodel's properties, sorted.

func (*Table) Names

func (t *Table) Names() []string

Names lists every property the table knows, sorted.

type TypeTest

type TypeTest struct {
	Types   []string
	Exact   bool
	Inverse bool
}

TypeTest keeps the rows of the named metaclasses: their own metaclass when Exact, else any conforming one.

Jump to

Keyboard shortcuts

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