transformTo transforms fromNode to toNode level using the path between them and the corresponding uidMatrices.
(toPath []*SubGraph)
| 1141 | // transformTo transforms fromNode to toNode level using the path between them and the |
| 1142 | // corresponding uidMatrices. |
| 1143 | func (fromNode *varValue) transformTo(toPath []*SubGraph) (*types.ShardedMap, error) { |
| 1144 | if len(toPath) < len(fromNode.path) { |
| 1145 | return fromNode.Vals, nil |
| 1146 | } |
| 1147 | |
| 1148 | idx := 0 |
| 1149 | for ; idx < len(fromNode.path); idx++ { |
| 1150 | if fromNode.path[idx] != toPath[idx] { |
| 1151 | return fromNode.Vals, nil |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if fromNode.Vals.Len() == 0 { |
| 1156 | return fromNode.Vals, nil |
| 1157 | } |
| 1158 | |
| 1159 | newMap := fromNode.Vals |
| 1160 | for ; idx < len(toPath); idx++ { |
| 1161 | curNode := toPath[idx] |
| 1162 | if idx == 0 { |
| 1163 | continue |
| 1164 | } |
| 1165 | |
| 1166 | var mutex sync.Mutex |
| 1167 | var resultMap *types.ShardedMap |
| 1168 | |
| 1169 | calculate := func(start, end int) { |
| 1170 | tempMap := types.NewShardedMap() |
| 1171 | |
| 1172 | for i := start; i < end; i++ { |
| 1173 | ul := curNode.uidMatrix[i] |
| 1174 | srcUid := curNode.SrcUIDs.Uids[i] |
| 1175 | curVal, ok := newMap.Get(srcUid) |
| 1176 | if !ok || curVal.Value == nil { |
| 1177 | continue |
| 1178 | } |
| 1179 | if curVal.Tid != types.IntID && curVal.Tid != types.FloatID { |
| 1180 | return |
| 1181 | } |
| 1182 | ag := aggregator{name: "sum"} |
| 1183 | for j := range ul.Uids { |
| 1184 | ag.result = types.Val{} |
| 1185 | dstUid := ul.Uids[j] |
| 1186 | if err := ag.Apply(curVal); err != nil { |
| 1187 | return |
| 1188 | } |
| 1189 | if tempVal, ok := tempMap.Get(dstUid); ok { |
| 1190 | if err := ag.Apply(tempVal); err != nil { |
| 1191 | return |
| 1192 | } |
| 1193 | } |
| 1194 | val, err := ag.Value() |
| 1195 | if err != nil { |
| 1196 | continue |
| 1197 | } |
| 1198 | tempMap.Set(dstUid, val) |
| 1199 | } |
| 1200 | } |