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

Function preprocessFilter

worker/task.go:2424–2497  ·  view source on GitHub ↗
(tree *pb.FilterTree)

Source from the content-addressed store, hash-verified

2422 types.DateTimeID, types.BoolID, types.DefaultID}
2423
2424func preprocessFilter(tree *pb.FilterTree) (*facetsTree, error) {
2425 if tree == nil {
2426 return nil, nil
2427 }
2428 ftree := &facetsTree{}
2429 ftree.op = strings.ToLower(tree.Op)
2430 if tree.Func != nil {
2431 ftree.function = &facetsFunc{}
2432 ftree.function.key = tree.Func.Key
2433 ftree.function.args = tree.Func.Args
2434
2435 fnType, fname := parseFuncTypeHelper(tree.Func.Name)
2436 if len(tree.Func.Args) != 1 {
2437 return nil, errors.Errorf("One argument expected in %s, but got %d.",
2438 fname, len(tree.Func.Args))
2439 }
2440
2441 ftree.function.name = fname
2442 ftree.function.fnType = fnType
2443
2444 switch fnType {
2445 case compareAttrFn:
2446 ftree.function.val = types.Val{Tid: types.StringID, Value: []byte(tree.Func.Args[0])}
2447 ftree.function.typesToVal = make(map[types.TypeID]types.Val, len(commonTypeIDs))
2448 for _, typeID := range commonTypeIDs {
2449 // TODO: if conversion is not possible we are not putting anything to map. In
2450 // applyFacetsTree we check if entry for a type is not present, we try to convert
2451 // it. This double conversion can be avoided.
2452 cv, err := types.Convert(ftree.function.val, typeID)
2453 if err != nil {
2454 continue
2455 }
2456 ftree.function.typesToVal[typeID] = cv
2457 }
2458 case standardFn:
2459 argTokens, aerr := tok.GetTermTokens(tree.Func.Args)
2460 if aerr != nil { // query error ; stop processing.
2461 return nil, aerr
2462 }
2463 sort.Strings(argTokens)
2464 ftree.function.tokens = argTokens
2465 default:
2466 return nil, errors.Errorf("Fn %s not supported in preprocessFilter.", fname)
2467 }
2468 return ftree, nil
2469 }
2470
2471 for _, c := range tree.Children {
2472 ftreec, err := preprocessFilter(c)
2473 if err != nil {
2474 return nil, err
2475 }
2476 ftree.children = append(ftree.children, ftreec)
2477 }
2478
2479 numChild := len(tree.Children)
2480 switch ftree.op {
2481 case "not":

Callers 2

handleValuePostingsMethod · 0.85
handleUidPostingsMethod · 0.85

Calls 4

ConvertFunction · 0.92
GetTermTokensFunction · 0.92
parseFuncTypeHelperFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected