Documentation
      ¶
    
    
  
    
  
    Overview ¶
Copyright 2016 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
 - Variables
 - func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, error)
 - func AssignUids(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error)
 - func ExpandEdges(ctx context.Context, m *pb.Mutations) ([]*pb.DirectedEdge, error)
 - func ExtractBlankUIDs(ctx context.Context, gmuList []*dql.Mutation) (map[string]uint64, error)
 - func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error)
 - func StripBlankNode(mp map[string]uint64) map[string]uint64
 - func ToDirectedEdges(gmuList []*dql.Mutation, newUids map[string]uint64) (edges []*pb.DirectedEdge, err error)
 - func ToJson(ctx context.Context, l *Latency, sgl []*SubGraph, field gqlSchema.Field) ([]byte, error)
 - func ToRDF(l *Latency, sgl []*SubGraph) ([]byte, error)
 - func UidToHex(uid uint64) string
 - func UidsToHex(m map[string]uint64) map[string]string
 - type CascadeArgs
 - type ContextKey
 - type ExecutionResult
 - type Extensions
 - type Function
 - type Latency
 - type Request
 - type SubGraph
 
Constants ¶
const ( INT valType = iota FLOAT VFLOAT DEFAULT BIGFLOAT )
Variables ¶
var ( ErrorIntOverflow = errors.New("Integer overflow") ErrorFloat32Overflow = errors.New("Float32 overflow") ErrorDivisionByZero = errors.New("Division by zero") ErrorFractionalPower = errors.New("Fractional power of negative number") ErrorNegativeLog = errors.New("Log of negative number") ErrorNegativeRoot = errors.New("Root of negative number") ErrorVectorsNotMatch = errors.New("The length of vectors must match") ErrorArgsDisagree = errors.New("Left and right arguments must match") ErrorShouldBeVector = errors.New("Type should be []float, but is not. Cannot determine type.") ErrorBadVectorMult = errors.New("Cannot multiply vector by vector") )
var ( // ErrEmptyVal is returned when a value is empty. ErrEmptyVal = errors.New("Query: harmless error, e.g. task.Val is nil") // ErrWrongAgg is returned when value aggregation is attempted in the root level of a query. ErrWrongAgg = errors.New("Wrong level for var aggregation") )
var ErrStopIteration = errors.New("stop iteration")
    Functions ¶
func ApplyMutations ¶
ApplyMutations performs the required edge expansions and forwards the results to the worker to perform the mutations.
func AssignUids ¶
AssignUids tries to assign unique ids to each identity in the subjects and objects in the format of _:xxx. An identity, e.g. _:a, will only be assigned one uid regardless how many times it shows up in the subjects or objects
func ExpandEdges ¶
func ExtractBlankUIDs ¶
func ProcessGraph ¶
ProcessGraph processes the SubGraph instance accumulating result for the query from different instances. Note: taskQuery is nil for root node.
func StripBlankNode ¶
StripBlankNode returns a copy of the map where all the keys have the blank node prefix removed.
func ToDirectedEdges ¶
func ToDirectedEdges(gmuList []*dql.Mutation, newUids map[string]uint64) ( edges []*pb.DirectedEdge, err error)
ToDirectedEdges converts the dql.Mutation input into a set of directed edges.
func ToJson ¶
func ToJson(ctx context.Context, l *Latency, sgl []*SubGraph, field gqlSchema.Field) ([]byte, error)
ToJson converts the list of subgraph into a JSON response by calling toFastJSON.
Types ¶
type CascadeArgs ¶
CascadeArgs stores the arguments needed to process @cascade directive. It is introduced to ensure correct behaviour for cascade with pagination.
type ContextKey ¶
type ContextKey int
ContextKey is used to set options in the context object.
const ( // DebugKey is the key used to toggle debug mode. DebugKey ContextKey = iota )
type ExecutionResult ¶
type ExecutionResult struct {
	Subgraphs  []*SubGraph
	SchemaNode []*pb.SchemaNode
	Types      []*pb.TypeUpdate
	Metrics    map[string]uint64
}
    ExecutionResult holds the result of running a query.
type Extensions ¶
type Extensions struct {
	Latency *api.Latency    `json:"server_latency,omitempty"`
	Txn     *api.TxnContext `json:"txn,omitempty"`
	Metrics *api.Metrics    `json:"metrics,omitempty"`
}
    Extensions represents the extra information appended to query results.
type Function ¶
type Function struct {
	Name       string    // Specifies the name of the function.
	Args       []dql.Arg // Contains the arguments of the function.
	IsCount    bool      // gt(count(friends),0)
	IsValueVar bool      // eq(val(s), 10)
	IsLenVar   bool      // eq(len(s), 10)
}
    Function holds the information about dql functions.
type Latency ¶
type Latency struct {
	Start           time.Time     `json:"-"`
	Parsing         time.Duration `json:"query_parsing"`
	AssignTimestamp time.Duration `json:"assign_timestamp"`
	Processing      time.Duration `json:"processing"`
	Json            time.Duration `json:"json_conversion"`
}
    Latency is used to keep track of the latency involved in parsing and processing the query. It also contains information about the time it took to convert the result into a format(JSON/Protocol Buffer) that the client expects.
type Request ¶
type Request struct {
	ReadTs   uint64 // ReadTs for the transaction.
	Cache    int    // 0 represents use txn cache, 1 represents not to use cache.
	Latency  *Latency
	DqlQuery *dql.Result
	Subgraphs []*SubGraph
	Vars map[string]varValue
}
    Request wraps the state that is used when executing query. Initially ReadTs, Cache and DQLQuery are set. Subgraphs, Vars and Latency are filled when processing query.
type SubGraph ¶
type SubGraph struct {
	ReadTs      uint64
	Cache       int
	Attr        string
	UnknownAttr bool
	// read only parameters which are populated before the execution of the query and are used to
	// execute this query.
	Params params
	ExpandPreds []*pb.ValueList
	GroupbyRes  []*groupResults // one result for each uid list.
	LangTags    []*pb.LangList
	// SrcUIDs is a list of unique source UIDs. They are always copies of destUIDs
	// of parent nodes in GraphQL structure.
	SrcUIDs *pb.List
	// SrcFunc specified using func. Should only be non-nil at root. At other levels,
	// filters are used.
	SrcFunc *Function
	FilterOp string
	Filters  []*SubGraph // List of filters specified at the current node.
	MathExp  *mathTree
	Children []*SubGraph // children of the current node, should be empty for leaf nodes.
	// destUIDs is a list of destination UIDs, after applying filters, pagination.
	DestUIDs *pb.List
	List     bool // whether predicate is of list type
	// contains filtered or unexported fields
}
    SubGraph is the way to represent data. It contains both the request parameters and the response. Once generated, this can then be encoded to other client convenient formats, like GraphQL / JSON. SubGraphs are recursively nested. Each SubGraph contain the following:
- SrcUIDS: A list of UIDs that were sent to this query. If this subgraph is a child graph, then the DestUIDs of the parent must match the SrcUIDs of the children.
 - DestUIDs: A list of UIDs for which there can be output found in the Children field
 - Children: A list of child results for this query
 - valueMatrix: A list of values, against a single attribute, such as name (for a scalar subgraph). This must be the same length as the SrcUIDs
 - uidMatrix: A list of outgoing edges. This must be same length as the SrcUIDs list.
 
Example, say we are creating a SubGraph for a query "users", which returns one user with name 'Foo', you may get SubGraph
Params: { Alias: "users" }
SrcUIDs: [1]
DestUIDs: [1]
uidMatrix: [[1]]
Children:
  SubGraph:
    Attr: "name"
    SrcUIDs: [1]
    uidMatrix: [[]]
    valueMatrix: [["Foo"]]
func ToSubGraph ¶
ToSubGraph converts the GraphQuery into the pb.SubGraph instance type.
func (*SubGraph) DebugPrint ¶
DebugPrint prints out the SubGraph tree in a nice format for debugging purposes.
func (*SubGraph) IsInternal ¶
IsInternal returns whether this subgraph is marked as internal.