replaceVarInFunc gets values stored inside UidToVal(coming from a value variable defined in some other query) and adds them as arguments to the SrcFunc in SubGraph. E.g. - func: eq(score, val(myscore)) NOTE - We disallow vars in facets filter so we don't need to worry about that as of now.
()
| 1880 | // E.g. - func: eq(score, val(myscore)) |
| 1881 | // NOTE - We disallow vars in facets filter so we don't need to worry about that as of now. |
| 1882 | func (sg *SubGraph) replaceVarInFunc() error { |
| 1883 | if sg.SrcFunc == nil { |
| 1884 | return nil |
| 1885 | } |
| 1886 | var args []dql.Arg |
| 1887 | // Iterate over the args and replace value args with their values |
| 1888 | for _, arg := range sg.SrcFunc.Args { |
| 1889 | if !arg.IsValueVar { |
| 1890 | args = append(args, arg) |
| 1891 | continue |
| 1892 | } |
| 1893 | if sg.Params.UidToVal.Len() == 0 { |
| 1894 | // This means that the variable didn't have any values and hence there is nothing to add |
| 1895 | // to args. |
| 1896 | break |
| 1897 | } |
| 1898 | // We don't care about uids, just take all the values and put as args. |
| 1899 | // There would be only one value var per subgraph as per current assumptions. |
| 1900 | seenArgs := make(map[string]struct{}) |
| 1901 | err := sg.Params.UidToVal.Iterate(func(uid uint64, v types.Val) error { |
| 1902 | data := types.ValueForType(types.StringID) |
| 1903 | if err := types.Marshal(v, &data); err != nil { |
| 1904 | return err |
| 1905 | } |
| 1906 | val := data.Value.(string) |
| 1907 | if _, ok := seenArgs[val]; ok { |
| 1908 | return nil |
| 1909 | } |
| 1910 | seenArgs[val] = struct{}{} |
| 1911 | args = append(args, dql.Arg{Value: val}) |
| 1912 | return nil |
| 1913 | }) |
| 1914 | if err != nil { |
| 1915 | return err |
| 1916 | } |
| 1917 | } |
| 1918 | sg.SrcFunc.Args = args |
| 1919 | return nil |
| 1920 | } |
| 1921 | |
| 1922 | var ErrStopIteration = errors.New("stop iteration") |
| 1923 |
no test coverage detected