(ctx context.Context, sg *SubGraph)
| 2036 | } |
| 2037 | |
| 2038 | func expandSubgraph(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) { |
| 2039 | span := trace.SpanFromContext(ctx) |
| 2040 | stop := x.SpanTimer(span, "expandSubgraph: "+sg.Attr) |
| 2041 | defer stop() |
| 2042 | |
| 2043 | namespace, err := x.ExtractNamespace(ctx) |
| 2044 | if err != nil { |
| 2045 | return nil, errors.Wrapf(err, "While expanding subgraph") |
| 2046 | } |
| 2047 | out := make([]*SubGraph, 0, len(sg.Children)) |
| 2048 | for i := range sg.Children { |
| 2049 | child := sg.Children[i] |
| 2050 | |
| 2051 | if child.Params.Expand == "" { |
| 2052 | out = append(out, child) |
| 2053 | continue |
| 2054 | } |
| 2055 | |
| 2056 | var preds []string |
| 2057 | typeNames, err := getNodeTypes(ctx, sg) |
| 2058 | if err != nil { |
| 2059 | return out, err |
| 2060 | } |
| 2061 | |
| 2062 | switch child.Params.Expand { |
| 2063 | // It could be expand(_all_) or expand(val(x)). |
| 2064 | case "_all_": |
| 2065 | span.AddEvent("expand(_all_)") |
| 2066 | if len(typeNames) == 0 { |
| 2067 | break |
| 2068 | } |
| 2069 | |
| 2070 | preds = getPredicatesFromTypes(namespace, typeNames) |
| 2071 | // restrict preds to allowed preds if ACL is turned on. |
| 2072 | if sg.Params.AllowedPreds != nil { |
| 2073 | // Take intersection of both the predicate lists |
| 2074 | intersectPreds := make([]string, 0) |
| 2075 | hashMap := make(map[string]bool) |
| 2076 | for _, allowedPred := range sg.Params.AllowedPreds { |
| 2077 | hashMap[allowedPred] = true |
| 2078 | } |
| 2079 | for _, pred := range preds { |
| 2080 | if _, found := hashMap[pred]; found { |
| 2081 | intersectPreds = append(intersectPreds, pred) |
| 2082 | } |
| 2083 | } |
| 2084 | preds = intersectPreds |
| 2085 | } |
| 2086 | |
| 2087 | default: |
| 2088 | if len(child.ExpandPreds) > 0 { |
| 2089 | span.AddEvent("expand default") |
| 2090 | // We already have the predicates populated from the var. |
| 2091 | temp := getPredsFromVals(child.ExpandPreds) |
| 2092 | for _, pred := range temp { |
| 2093 | preds = append(preds, x.NamespaceAttr(namespace, pred)) |
| 2094 | } |
| 2095 | } else { |
no test coverage detected