MCPcopy
hub / github.com/dgraph-io/dgraph / parseSrcFn

Function parseSrcFn

worker/task.go:1922–2209  ·  view source on GitHub ↗
(ctx context.Context, q *pb.Query)

Source from the content-addressed store, hash-verified

1920}
1921
1922func parseSrcFn(ctx context.Context, q *pb.Query) (*functionContext, error) {
1923 fnType, f := parseFuncType(q.SrcFunc)
1924 attr := q.Attr
1925 fc := &functionContext{fnType: fnType, fname: f}
1926 isIndexedAttr := schema.State().IsIndexed(ctx, attr)
1927 var err error
1928
1929 t, err := schema.State().TypeOf(attr)
1930 if err == nil && fnType != notAFunction && t.Name() == types.StringID.Name() {
1931 fc.isStringFn = true
1932 }
1933
1934 switch fnType {
1935 case notAFunction:
1936 fc.n = len(q.UidList.Uids)
1937 case aggregatorFn:
1938 // confirm aggregator could apply on the attributes
1939 typ, err := schema.State().TypeOf(attr)
1940 if err != nil {
1941 return nil, errors.Errorf("Attribute %q is not scalar-type", x.ParseAttr(attr))
1942 }
1943 if !couldApplyAggregatorOn(f, typ) {
1944 return nil, errors.Errorf("Aggregator %q could not apply on %v",
1945 f, x.ParseAttr(attr))
1946 }
1947 fc.n = len(q.UidList.Uids)
1948 case compareAttrFn:
1949 args := q.SrcFunc.Args
1950 if fc.fname == eq { // Only eq can have multiple args. It should have atleast one.
1951 if len(args) < 1 {
1952 return nil, errors.Errorf("eq expects atleast 1 argument.")
1953 }
1954 } else if fc.fname == between { // between should have exactly 2 arguments.
1955 if len(args) != 2 {
1956 return nil, errors.Errorf("between expects exactly 2 argument.")
1957 }
1958 } else { // Others can have only 1 arg.
1959 if len(args) != 1 {
1960 return nil, errors.Errorf("%+v expects only 1 argument. Got: %+v",
1961 fc.fname, args)
1962 }
1963 }
1964
1965 generateIneqTokens := true
1966 if fc.fname != eq && q.UidList != nil && uint64(len(q.UidList.Uids)) < Config.TypeFilterUidLimit {
1967 if !checkUidZero(q.UidList.Uids) {
1968 fc.n = len(q.UidList.Uids)
1969 generateIneqTokens = false
1970 }
1971 }
1972
1973 var tokens []string
1974 var ineqValues []types.Val
1975 // eq can have multiple args.
1976 for idx := 0; idx < len(args); idx++ {
1977 arg := args[idx]
1978 ineqValues = ineqValues[:0]
1979 ineqValue1, err := convertValue(attr, arg)

Callers 1

helpProcessTaskMethod · 0.85

Calls 15

StateFunction · 0.92
ParseAttrFunction · 0.92
GetGeoTokensFunction · 0.92
EncodeGeoTokensFunction · 0.92
GetTokenizerFunction · 0.92
BuildTokensFunction · 0.92
GetTokenizerForLangFunction · 0.92
parseFuncTypeFunction · 0.85
couldApplyAggregatorOnFunction · 0.85
checkUidZeroFunction · 0.85
convertValueFunction · 0.85
getInequalityTokensFunction · 0.85

Tested by

no test coverage detected