コード例 #1
0
        public virtual IGraphQueryStep Visit(IGraphQueryStep root)
        {
            _token.ThrowIfCancellationRequested();

            switch (root)
            {
            case QueryQueryStep qqs:
                return(VisitQueryQueryStep(qqs));

            case EdgeQueryStep eqs:
                return(VisitEdgeQueryStep(eqs));

            case CollectionDestinationQueryStep cdqs:
                return(VisitCollectionDestinationQueryStep(cdqs));

            case IntersectionQueryStep <Except> iqse:
                return(VisitIntersectionQueryStepExcept(iqse));

            case IntersectionQueryStep <Union> iqsu:
                return(VisitIntersectionQueryStepUnion(iqsu));

            case IntersectionQueryStep <Intersection> iqsi:
                return(VisitIntersectionQueryStepIntersection(iqsi));

            case RecursionQueryStep rqs:
                return(VisitRecursionQueryStep(rqs));

            default:
                throw new NotSupportedException($"Unexpected type {root.GetType().Name} for QueryPlanRewriter.Visit");
            }
        }
コード例 #2
0
 public bool GetNext(out Match match)
 {
     _token.ThrowIfCancellationRequested();
     if (_index >= _results.Count)
     {
         match = default;
         return(false);
     }
     match = _results[_index++];
     return(true);
 }
コード例 #3
0
ファイル: Except.cs プロジェクト: yitaom2/ravendb
 public void Complete(List <Match> output, Dictionary <long, List <Match> > intersection, HashSet <Match> state, OperationCancelToken token)
 {
     foreach (var kvp in intersection)
     {
         foreach (var item in kvp.Value)
         {
             token.ThrowIfCancellationRequested();
             if (state.Contains(item) == false)
             {
                 output.Add(item);
             }
         }
     }
 }
コード例 #4
0
        private void IntersectExpressions()
        {
            _token.ThrowIfCancellationRequested();
            _index = 0;

            if (_returnEmptyIfRightEmpty && _right.IsEmpty())
            {
                return;
            }

            _tempIntersect.Clear();

            var operation = new TOp();

            operation.Set(_left, _right);
            var operationState = new HashSet <Match>();

            if (_intersectedAliases.Count == 0 && !operation.ShouldContinueWhenNoIntersection)
            {
                return; // no matching aliases, so we need to stop when the operation is intersection
            }
            while (_left.GetNext(out var leftMatch))
            {
                _token.ThrowIfCancellationRequested();
                long key = GetMatchHashKey(_intersectedAliases, leftMatch);
                if (_tempIntersect.TryGetValue(key, out var matches) == false)
                {
                    _tempIntersect[key] = matches = new List <Match>(); // TODO: pool these
                }
                matches.Add(leftMatch);
            }


            while (_right.GetNext(out var rightMatch))
            {
                _token.ThrowIfCancellationRequested();
                long key = GetMatchHashKey(_intersectedAliases, rightMatch);

                if (_tempIntersect.TryGetValue(key, out var matchesFromLeft) == false)
                {
                    if (operation.ShouldContinueWhenNoIntersection)
                    {
                        operationState.Add(rightMatch);
                    }
                    continue; // nothing matched, can skip
                }

                for (int i = 0; i < matchesFromLeft.Count; i++)
                {
                    _token.ThrowIfCancellationRequested();
                    var leftMatch             = matchesFromLeft[i];
                    var allIntersectionsMatch = true;
                    for (int j = 0; j < _intersectedAliases.Count; j++)
                    {
                        var intersect = _intersectedAliases[j];
                        if (!leftMatch.TryGetAliasId(intersect, out var x) ||
                            !rightMatch.TryGetAliasId(intersect, out var y) ||
                            x != y)
                        {
                            allIntersectionsMatch = false;
                            break;
                        }
                    }

                    operation.Op(_results, leftMatch, rightMatch, allIntersectionsMatch, operationState);
                }
            }

            operation.Complete(_results, _tempIntersect, operationState, _token);
        }