/// <summary> /// Looks at the key and index(aka.left and right) properties of the 2 streams and checks /// for each property if any equivalent index properties exist for other streams. /// Example: s0.p0 = s1.p1 and s1.p1 = s2.p2 ==> therefore s0.p0 = s2.p2 /// ==> look stream s0, property p0; indexed stream s1, property p1 /// Is there any other lookup stream that has stream 1 and property p1 as index property? ==> this is stream s2, p2 /// Add navigation entry between stream s0 and property p0 to stream s2, property p2 /// </summary> private static bool FillEquivalentNav( EventType[] typesPerStream, QueryGraphForge queryGraph, int lookupStream, string keyProp, int indexedStream, string indexProp) { var addedEquivalency = false; for (var otherStream = 0; otherStream < queryGraph.NumStreams; otherStream++) { if (otherStream == lookupStream || otherStream == indexedStream) { continue; } var value = queryGraph.GetGraphValue(otherStream, indexedStream); QueryGraphValuePairHashKeyIndexForge hashKeys = value.HashKeyProps; var otherStrictKeyProps = hashKeys.StrictKeys; var otherIndexProps = hashKeys.Indexed; var otherPropertyNum = -1; if (otherIndexProps == null) { continue; } for (var i = 0; i < otherIndexProps.Length; i++) { if (otherIndexProps[i].Equals(indexProp)) { otherPropertyNum = i; break; } } if (otherPropertyNum != -1) { if (otherStrictKeyProps[otherPropertyNum] != null) { ExprIdentNode identNodeLookup = new ExprIdentNodeImpl( typesPerStream[lookupStream], keyProp, lookupStream); ExprIdentNode identNodeOther = new ExprIdentNodeImpl( typesPerStream[otherStream], otherStrictKeyProps[otherPropertyNum], otherStream); var added = queryGraph.AddStrictEquals( lookupStream, keyProp, identNodeLookup, otherStream, otherStrictKeyProps[otherPropertyNum], identNodeOther); if (added) { addedEquivalency = true; } } } } return addedEquivalency; }
/// <summary> /// Looks at the key and index (aka. left and right) properties of the 2 streams and checks /// for each property if any equivalent index properties exist for other streams. /// </summary> /// <exception cref="IllegalStateException">Unexpected key and index property number mismatch</exception> private static bool FillEquivalentNav( EventType[] typesPerStream, QueryGraphForge queryGraph, int lookupStream, int indexedStream) { var addedEquivalency = false; var value = queryGraph.GetGraphValue(lookupStream, indexedStream); if (value.IsEmptyNotNavigable) { return false; } QueryGraphValuePairHashKeyIndexForge hashKeys = value.HashKeyProps; var strictKeyProps = hashKeys.StrictKeys; var indexProps = hashKeys.Indexed; if (strictKeyProps.Length == 0) { return false; } if (strictKeyProps.Length != indexProps.Length) { throw new IllegalStateException("Unexpected key and index property number mismatch"); } for (var i = 0; i < strictKeyProps.Length; i++) { if (strictKeyProps[i] == null) { continue; // not a strict key } var added = FillEquivalentNav( typesPerStream, queryGraph, lookupStream, strictKeyProps[i], indexedStream, indexProps[i]); if (added) { addedEquivalency = true; } } return addedEquivalency; }