MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / createTaskQuery

Function createTaskQuery

query/query.go:920–985  ·  view source on GitHub ↗

createTaskQuery generates the query buffer.

(ctx context.Context, sg *SubGraph)

Source from the content-addressed store, hash-verified

918
919// createTaskQuery generates the query buffer.
920func createTaskQuery(ctx context.Context, sg *SubGraph) (*pb.Query, error) {
921 namespace, err := x.ExtractNamespace(ctx)
922 if err != nil {
923 return nil, errors.Wrapf(err, "While creating query task")
924 }
925 attr := sg.Attr
926 // Might be safer than just checking first byte due to i18n
927 reverse := strings.HasPrefix(attr, "~")
928 if reverse {
929 attr = strings.TrimPrefix(attr, "~")
930 }
931 var srcFunc *pb.SrcFunction
932 if sg.SrcFunc != nil {
933 srcFunc = &pb.SrcFunction{}
934 srcFunc.Name = sg.SrcFunc.Name
935 srcFunc.IsCount = sg.SrcFunc.IsCount
936 for _, arg := range sg.SrcFunc.Args {
937 srcFunc.Args = append(srcFunc.Args, arg.Value)
938 if arg.IsValueVar {
939 return nil, errors.Errorf("Unsupported use of value var")
940 }
941 }
942 }
943
944 // If the lang is set to *, query all the languages.
945 if len(sg.Params.Langs) == 1 && sg.Params.Langs[0] == "*" {
946 sg.Params.ExpandAll = true
947 }
948
949 // first is to limit how many results we want.
950 first, offset := calculatePaginationParams(sg)
951 ns, err := x.ExtractNamespace(ctx)
952 if err != nil {
953 return nil, errors.Wrapf(err, "While ordering and paginating")
954 }
955 orderParams := sg.createOrderForTask(ns)
956 sortMsg := &pb.SortMessage{
957 Order: orderParams,
958 UidMatrix: sg.uidMatrix,
959 Offset: int32(sg.Params.Offset),
960 Count: int32(sg.Params.Count),
961 ReadTs: sg.ReadTs,
962 }
963
964 out := &pb.Query{
965 ReadTs: sg.ReadTs,
966 Cache: int32(sg.Cache),
967 Attr: x.NamespaceAttr(namespace, attr),
968 Langs: sg.Params.Langs,
969 Reverse: reverse,
970 SrcFunc: srcFunc,
971 AfterUid: sg.Params.AfterUID,
972 DoCount: len(sg.Filters) == 0 && sg.Params.DoCount,
973 FacetParam: sg.Params.Facet,
974 FacetsFilter: sg.facetsFilter,
975 ExpandAll: sg.Params.ExpandAll,
976 First: first,
977 Offset: offset,

Callers 2

ProcessGraphFunction · 0.85
getNodeTypesFunction · 0.85

Calls 5

ExtractNamespaceFunction · 0.92
NamespaceAttrFunction · 0.92
createOrderForTaskMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected