Documentation ¶
Overview ¶
Package parser implements a parser combinator for the akutan query language. After parsing a query string into a query object, it is passed to the planner for a cost based evaluation of possible execution paths and finally the executor where the retrieval and join operations on the best plan are performed.
For documentation on the query language specifics; see the root README.md.
Index ¶
- Constants
- Variables
- func MustRewrite(ctx context.Context, lookup lookups.PO, idx uint64, in *Query)
- func Rewrite(ctx context.Context, lookup lookups.PO, idx uint64, in *Query) error
- type AggregateExpr
- type AggregateFunction
- type BoundExpression
- type Distinct
- type Entity
- type Expression
- type Insert
- type Language
- type LimitOffset
- type Literal
- type LiteralBool
- type LiteralFloat
- type LiteralID
- type LiteralInt
- type LiteralSet
- type LiteralString
- type LiteralTime
- type MatchSpecificity
- type Nil
- type Operator
- type OrderCondition
- type ParseError
- type QName
- type Quad
- type Query
- type QueryType
- type Reduced
- type SelectClause
- type SolutionModifier
- type SortDirection
- type Term
- type Unit
- type Variable
- type WhereClause
- type Wildcard
Constants ¶
const ( // QuerySparql indicates that the query is in the sparql(ish) subset format. QuerySparql = "sparql" // QueryFactPattern indicates that the query is a bare set of fact patterns to match. QueryFactPattern = "facts" )
const ( // InsertFormatTSV takes one fact per line, consisting of three or four // whitespace-separated columns. It's far more forgiving about whitespace // than normal tab-separated values files. Blank lines and lines consisting // of # comments are allowed. // // <dont_care> may be used as a dummy fact ID. // // Variables like ?var capture a fact ID and must be used as subject or // object in a subsequent fact. InsertFormatTSV = "tsv" )
These are possible values for ParseInsert formats.
Variables ¶
var ( // NoUnit indicates no units were specified for the literal. NoUnit = Unit{} // NoLanguage indicates no language was specified for the string. NoLanguage = Language{} )
Functions ¶
func MustRewrite ¶
MustRewrite uses a set of rewrite rules in order to rewrite the query definition and panics if an error occurs. It simplifies variable initialization.
Types ¶
type AggregateExpr ¶
type AggregateExpr struct { Function AggregateFunction // Of is the target to be aggregated. Of aggregateTarget // *Variable, Wildcard [Later Expression] }
AggregateExpr describes a single aggregate expression.
func (*AggregateExpr) String ¶
func (a *AggregateExpr) String() string
type AggregateFunction ¶
type AggregateFunction int
AggregateFunction describes the different types of aggregate functions. Only COUNT is currently supported.
const ( // AggCount counts rows (or solutions in SPARQL terms) AggCount AggregateFunction = iota + 1 )
func (AggregateFunction) String ¶
func (f AggregateFunction) String() string
type BoundExpression ¶
type BoundExpression struct { Expr Expression As *Variable }
BoundExpression represents an expression whose result is bound to a variable. e.g (COUNT(?v) AS ?c) is a BoundExpression, COUNT(?v) is the expression and its bound to the ?c Variable.
func (*BoundExpression) String ¶
func (b *BoundExpression) String() string
type Expression ¶
type Expression interface { String() string // contains filtered or unexported methods }
Expression is a marker interface for types that are expressions. For example COUNT(?v) is an expression. (AggregateExpr is our only Expression type)
type Insert ¶
type Insert struct { // The possible types for each Quad are restricted significantly. // // Each ID is either Nil or Variable. // // Each Subject is either LiteralID, QName, Entity, or Variable. // // Each Predicate is either LiteralID, QName, or Entity. // // Each Object is either LiteralID, QName, Entity, Variable, or a primitive // literal type (LiteralBool, LiteralInt, LiteralFloat, LiteralString, // LiteralTime). // // For QName, Entity, unit, or language values, only the string form is // given. // // All returned Quads will have a MatchSpecificity of MatchRequired. Facts []*Quad }
Insert is the result of ParseInsert.
func ParseInsert ¶
ParseInsert parses 'input' for inserting facts into the graph. The given format identifies the syntax of the input; the possible values are defined as InsertFormat* constants.
type LimitOffset ¶
type LimitOffset struct { // Limit and Offset are nil if not explicitly specified in the query. Limit *uint64 Offset *uint64 }
LimitOffset contains paging related values
func (*LimitOffset) String ¶
func (o *LimitOffset) String() string
type Literal ¶
type Literal interface { Term // Literal returns the api.KGObject representation of a parsed literal value. Literal() *api.KGObject }
Literal represents comparable object values.
func ParseLiteral ¶
ParseLiteral parses an object literal value.
type LiteralBool ¶
LiteralBool type.
func (*LiteralBool) Literal ¶
func (l *LiteralBool) Literal() *api.KGObject
Literal returns a boolean api object.
func (*LiteralBool) String ¶
func (l *LiteralBool) String() string
type LiteralFloat ¶
LiteralFloat type.
func (*LiteralFloat) Literal ¶
func (l *LiteralFloat) Literal() *api.KGObject
Literal returns a floating point api object.
func (*LiteralFloat) String ¶
func (l *LiteralFloat) String() string
type LiteralID ¶
type LiteralID struct { Value uint64 // A human-readable string that might be more evocative than the opaque // Value. This string includes angle brackets (like "<foo>") when rewritten // from an Entity. Hint string }
LiteralID type.
type LiteralInt ¶
LiteralInt type.
func (*LiteralInt) Literal ¶
func (l *LiteralInt) Literal() *api.KGObject
Literal returns an integer api object.
func (*LiteralInt) String ¶
func (l *LiteralInt) String() string
type LiteralSet ¶
type LiteralSet struct {
Values []Term
}
LiteralSet represents a set of literal values.
func (*LiteralSet) String ¶
func (l *LiteralSet) String() string
type LiteralString ¶
LiteralString object value type.
func (*LiteralString) Literal ¶
func (l *LiteralString) Literal() *api.KGObject
Literal returns a string api object.
func (*LiteralString) String ¶
func (l *LiteralString) String() string
type LiteralTime ¶
LiteralTime type.
func (*LiteralTime) Literal ¶
func (l *LiteralTime) Literal() *api.KGObject
Literal returns a time api object.
func (*LiteralTime) String ¶
func (l *LiteralTime) String() string
type MatchSpecificity ¶
type MatchSpecificity int
MatchSpecificity describes requirements for how a query line fits with the overall query
const ( // MatchRequired indicates that the queryline is required to have a matching // fact for there to be a result MatchRequired MatchSpecificity = 0 // MatchOptional indicates that the queryline is optional, if it exists it's // returned, if it doesn't it does not prevent an otherwise complete result // being generated. MatchOptional MatchSpecificity = 1 )
func (MatchSpecificity) String ¶
func (m MatchSpecificity) String() string
type OrderCondition ¶
type OrderCondition struct { Direction SortDirection On *Variable }
OrderCondition describes a single expression in the order by clause. SPARQL supports ordering by expressions, however we only support ordering by variables.
func (*OrderCondition) String ¶
func (o *OrderCondition) String() string
type ParseError ¶
type ParseError struct { // query, literal, etc. ParseType string // The input string to the parser which resulted in this error. Input string // Offset is the byte offset into 'Input' at which the error ocurred. Offset int // Line is the line number in 'Input' at which the error ocurred. Line int // Column is the column (in runes) into the indicated Line that the error // ocurred. Line & Column represent the same point in 'Input' as 'Offset'. Column int // The specific parser error that ocurred. Details string }
ParseError captures more detailed information about a parsing error, and where it occurred.
func (*ParseError) Error ¶
func (p *ParseError) Error() string
type Quad ¶
type Quad struct { // ID is set to &Nil{} when not present. // TODO: should it be nil instead? ID Term Subject Term Predicate Term Object Term Specificity MatchSpecificity }
Quad query statement.
type Query ¶
type Query struct { Type QueryType Select SelectClause // DatasetClause not supported Where WhereClause Modifiers SolutionModifier }
Query contains the definition of a single query.
func MustParse ¶
MustParse parses the akutan query language and panics if an error occurs. It simplifies variable initialization. This is primarily meant for writing unit tests.
type QueryType ¶
type QueryType int
QueryType defines the different type of queries. See https://www.w3.org/TR/sparql11-query/#QueryForms
const ( // LegacyPatternQuery indicates the query should use the legacy akutan query // where a fact pattern is specified, and sets of facts matching the pattern // are returned. This is what is now in the Where clause of a Select query. LegacyPatternQuery QueryType = iota + 1 // SelectQuery indicates the query should match patterns from the where // clause and return results as a tabular set of values. The result values // are either based on variables from the where clause, or on an aggregate // function. SelectQuery // AskQuery indicates the query should check if there exists at least one // set of facts that match the WHERE clause. If so it returns true, false // otherwise AskQuery )
type SelectClause ¶
type SelectClause struct { Keyword selectClauseKeyword // Distinct / Reduced Items []selectClauseItem // *Variable, *BoundExpression, Wildcard }
SelectClause details the requested results projection for the query. A Select * query would result in a single Wildcard instance in the Items slice.
func (SelectClause) String ¶
func (s SelectClause) String() string
type SolutionModifier ¶
type SolutionModifier struct { // GroupClause not supported // HavingClause not supported OrderBy []OrderCondition Paging LimitOffset }
SolutionModifier describes the different ways in which the solutions (aka rows) produced by the where clause can be manipulated, such as sorting.
func (*SolutionModifier) String ¶
func (s *SolutionModifier) String() string
type SortDirection ¶
type SortDirection int
SortDirection is the direction that a sort should be in.
const ( // SortAsc indicate an ascending sort, i.e. smaller values appear before // larger values. SortAsc SortDirection = 1 // SortDesc indicate a descending sort, i.e. larger values appear // before smaller values. SortDesc SortDirection = 2 )
func (SortDirection) String ¶
func (d SortDirection) String() string
type Term ¶
type Term interface { // Return a parseable string representation of the Term. It is used for // debugging to build a parseable string of the query. It is also used to // distinguish Terms when building the literal set. String() string // contains filtered or unexported methods }
A Term is a reference to an entity, an operator, a variable, Nil, a primitive literal, or a set of these. Sets of sets are not allowed. Each field in a Quad is a Term.
type WhereClause ¶
type WhereClause []*Quad
WhereClause type.
func (WhereClause) String ¶
func (q WhereClause) String() string