v0.0.0-...-6719cd2 Latest Latest

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 22 Imported by: 0



Package exec is used to execute a KG query that was built by the query planner. The Execute method takes a plan and executes it, generating a stream of ResultChunks containing the results.

Each FactSet represents a single valid set of facts that match the query, in addition to the facts the ResultChunk also contains a tabular set of values related to variables.

Each node in the plan is converted into a queryOperator instance, creating a parallel tree of queryOperators. Executing the query is then a matter of executing the root node in the tree. Each queryOperator publishes a results stream on a caller supplied channel, slow consumption of the channel will apply back pressure down the tree, possibly all the way to the underling RPC calls to the Views.



This section is empty.


This section is empty.


func Execute

func Execute(ctx context.Context, events Events, index uint64, cache cache.FactCache, views lookups.All, query *plandef.Plan, resCh chan<- ResultChunk) error

Execute takes a query as described by the output of the query planner and executes it. Results are returned as 1..N ResultChunk's on the provided results channel. If the query generates no result rows, a single ResultChunk is generated that contains the column info, but no rows.

This function blocks until all results are generated on the results channel or there was an error. The results channel is closed when this function returns regardless of outcomes. 'events' will receive callbacks during query execution, you can pass nil if you don't need them.


type Columns

type Columns []*plandef.Variable

Columns describes the ordered list of columns that is generated by an operator.

func (Columns) IndexOf

func (c Columns) IndexOf(v *plandef.Variable) (int, bool)

IndexOf returns the index into Columns that the variable 'v' appears and the value true, or (0,false) if its not in the columns.

func (Columns) IndexesOf

func (c Columns) IndexesOf(vars []*plandef.Variable) ([]int, error)

IndexesOf returns the indexes that the variables 'vars' appear at in Columns. Returns (nil, error) if any of the variables is not found in Columns.

func (Columns) MustIndexOf

func (c Columns) MustIndexOf(v *plandef.Variable) int

MustIndexOf returns the index into Columns that the variable 'v' appears. It panics if it can't find v. This should only be used when it's a programmer error for v to not be in the columns.

func (Columns) MustIndexesOf

func (c Columns) MustIndexesOf(vars []*plandef.Variable) []int

MustIndexesOf returns the indexes that the variables 'vars' appears at in Columns. It panics if it can't find any of the variable in Columns.

func (Columns) String

func (c Columns) String() string

type Events

type Events interface {
	// OpCompleted is called when an Operator has finished execution (even in
	// error cases). The event parameter contains a summary of information about
	// the execution.
	OpCompleted(event OpCompletedEvent)
	// Clocks will be called to obtain a time source that can be used for timing
	// the execution.
	Clock() clocks.Source

Events receives callbacks about the progress of the query execution. Methods in the interface can be called concurrently by the execution engine, implementations of this interface must be concurrent safe.

type FactSet

type FactSet struct {
	Facts []rpc.Fact

FactSet represents the facts that make up a result row from an operator. It consists of 0 or more facts that are true.

func (FactSet) String

func (fs FactSet) String() string

type FinalStatistics

type FinalStatistics struct {
	// For queries that specify a LIMIT or OFFSET clause, this field is
	// populated with the overall resultset size that would have been returned
	// without the clause.
	TotalResultSize uint64

FinalStatistics contains statistics that a QueryOperator can output.

type OpCompletedEvent

type OpCompletedEvent struct {
	// The definition of the Operator that was executed. A single query execution
	// may generate multiple OpCompleted events for the same Operator. For
	// example because it's the right side input to a loop join.
	Operator plandef.Operator
	// The number of bulk input rows that were executed.
	InputBulkCount uint32
	// When the operator started execution.
	StartedAt time.Time
	// When the operator completed execution.
	EndedAt time.Time
	// resulting output Chunk/Row counts.
	Output StreamStats
	// if set, the execution failed with an error.
	Err error

OpCompletedEvent contains the collected data about a single execution of an operator. All these fields are populated by exec before it calls the OpCompleted method.

type ResultChunk

type ResultChunk struct {
	// The columns that this result chunk contains.
	Columns Columns
	// Values contains the values for the rows, these are in the order described
	// by columns. This contains len(columns) values for each row, repeated for
	// each row. For example if there are 4 columns and 5 rows, this will
	// contain 20 values. Although the external API is columnar oriented, while
	// executing the query everything needs row oriented values.
	Values []Value

	// Although the FactSets are in a slice the order is not relevant.
	Facts []FactSet
	// The last chunk may contain the final statistics value. However, if it's
	// found in any arbitrary chunk, then all of the subsequent chunks received
	// from a channel will contain the same final statistics value.
	FinalStatistics FinalStatistics
	// contains filtered or unexported fields

ResultChunk contains a slice of rows from a table of a single QueryOperator's output. The overall results for a QueryOperator consists of 0..N of these. The final execution tree is rooted by emptyResultOp which generates a ResultChunk with 0 rows in the event the query doesn't generate any results. This is required to be able to pass the column info to the API which it needs to meet its semantics.

func (*ResultChunk) NumRows

func (r *ResultChunk) NumRows() int

NumRows returns the number of rows in this chunk.

func (*ResultChunk) Row

func (r *ResultChunk) Row(row int) []Value

Row returns the values for the indicated row number. The values are in the order indicated in ResultChunk.Columns

func (*ResultChunk) ToTable

func (r *ResultChunk) ToTable(w io.Writer)

ToTable writes a human readable version of the chunk results as a table to the supplied Writer.

type StreamStats

type StreamStats struct {
	NumChunks       int
	NumFactSets     int
	FinalStatistics FinalStatistics

StreamStats contains basic stats about a particular operator output stream

type Value

type Value struct {
	KGObject  rpc.KGObject
	ExtID     string
	LangExtID string
	UnitExtID string

Value stores the current value of a single item. Typically these are the value for a Variable.

func (*Value) SetExtID

func (v *Value) SetExtID(s string)

SetExtID stores the supplied ExternalID in the Value, formatting it as necessary. It doesn't stores the supplied ExternalID if it's empty. This along with SetLangExtID and SetUnitExtID are used by the externalIds query op to update values with the fetched externalID.

func (*Value) SetLangExtID

func (v *Value) SetLangExtID(s string)

SetLangExtID stores the supplied LangExtID in the Value.

func (*Value) SetUnitExtID

func (v *Value) SetUnitExtID(s string)

SetUnitExtID stores the supplied UnitExtID in the Value, formatting it as necessary. It doesn't stores the supplied UnitExtID if it's empty.

func (Value) String

func (v Value) String() string

Jump to

Keyboard shortcuts

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