/// <summary>
        /// Executes this operation, sending the input of this operation
        /// to all its child operations
        /// </summary>
        /// <param name="rows">The rows.</param>
        /// <param name="cancellationToken">A CancellationToken to stop execution</param>
        /// <returns></returns>
        public override IAsyncEnumerable <Row> Execute(IAsyncEnumerable <Row> rows, CancellationToken cancellationToken = default)
        {
            return(new AsyncEnumerable <Row>(async yield => {
                var copiedRows = new CachingEnumerable <Row>(rows, cancellationToken);

                foreach (IOperation operation in Operations)
                {
                    var cloned = copiedRows.Select(r => r.Clone());

                    IAsyncEnumerable <Row> enumerable = operation.Execute(cloned, cancellationToken);

                    if (enumerable == null)
                    {
                        continue;
                    }

                    IAsyncEnumerator <Row> enumerator = enumerable.GetAsyncEnumerator(cancellationToken);
#pragma warning disable 642
                    while (await enumerator.MoveNextAsync())
                    {
                        ;
                    }
#pragma warning restore 642
                }
                yield.Break();
            }));
        }
        /// <summary>
        ///     Executes this operation, sending the input of this operation
        ///     to all its child operations
        /// </summary>
        /// <param name="rows">The rows.</param>
        /// <returns></returns>
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            var copiedRows = new CachingEnumerable <Row>(rows);

            foreach (var operation in Operations)
            {
                var cloned = copiedRows.Select(r => r.Clone());

                var enumerable = operation.Execute(cloned);

                if (enumerable == null)
                {
                    continue;
                }

                var enumerator = enumerable.GetEnumerator();
#pragma warning disable 642
                while (enumerator.MoveNext())
                {
                    ;
                }
#pragma warning restore 642
            }
            yield break;
        }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">Rows in pipeline. These are only used if a left part of the join was not specified.</param>
        /// <returns></returns>
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            PrepareForJoin();

            Dictionary <Row, object> matchedRightRows = new Dictionary <Row, object>();
            CachingEnumerable <Row>  rightEnumerable  = new CachingEnumerable <Row>(
                new EventRaisingEnumerator(right, right.Execute(null))
                );
            IEnumerable <Row> execute = left.Execute(leftRegistered ? null : rows);

            foreach (Row leftRow in new EventRaisingEnumerator(left, execute))
            {
                bool leftNeedOuterJoin = true;
                currentLeftRow = leftRow;
                foreach (Row rightRow in rightEnumerable)
                {
                    currentRightRow = rightRow;
                    if (MatchJoinCondition(leftRow, rightRow))
                    {
                        leftNeedOuterJoin          = false;
                        matchedRightRows[rightRow] = null;
                        yield return(MergeRows(leftRow, rightRow));
                    }
                }
                if (leftNeedOuterJoin)
                {
                    Row emptyRow = new Row();
                    emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                    currentRightRow            = emptyRow;
                    if (MatchJoinCondition(leftRow, emptyRow))
                    {
                        yield return(MergeRows(leftRow, emptyRow));
                    }
                    else
                    {
                        LeftOrphanRow(leftRow);
                    }
                }
            }
            foreach (Row rightRow in rightEnumerable)
            {
                if (matchedRightRows.ContainsKey(rightRow))
                {
                    continue;
                }
                currentRightRow = rightRow;
                Row emptyRow = new Row();
                emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                currentLeftRow             = emptyRow;
                if (MatchJoinCondition(emptyRow, rightRow))
                {
                    yield return(MergeRows(emptyRow, rightRow));
                }
                else
                {
                    RightOrphanRow(rightRow);
                }
            }
        }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="ignored">Ignored rows</param>
        /// <returns></returns>
        public override IEnumerable<Row> Execute(IEnumerable<Row> ignored)
        {
            Initialize();

            Guard.Against(left == null, "Left branch of a join cannot be null");
            Guard.Against(right == null, "Right branch of a join cannot be null");

            Dictionary<Row, object> matchedRightRows = new Dictionary<Row, object>();
            CachingEnumerable<Row> rightEnumerable = new CachingEnumerable<Row>(
                new EventRaisingEnumerator(right, right.Execute(null))
                );
            IEnumerable<Row> execute = left.Execute(null);
            foreach (Row leftRow in new EventRaisingEnumerator(left, execute))
            {
                bool leftNeedOuterJoin = true;
                currentLeftRow = leftRow;
                foreach (Row rightRow in rightEnumerable)
                {
                    currentRightRow = rightRow;
                    if (MatchJoinCondition(leftRow, rightRow))
                    {
                        leftNeedOuterJoin = false;
                        matchedRightRows[rightRow] = null;
                        yield return MergeRows(leftRow, rightRow);
                    }
                }
                if (leftNeedOuterJoin)
                {
                    Row emptyRow = new Row();
                    emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                    currentRightRow = emptyRow;
                    if (MatchJoinCondition(leftRow, emptyRow))
                        yield return MergeRows(leftRow, emptyRow);
                    else
                        LeftOrphanRow(leftRow);
                }
            }
            foreach (Row rightRow in rightEnumerable)
            {
                if (matchedRightRows.ContainsKey(rightRow))
                    continue;
                currentRightRow = rightRow;
                Row emptyRow = new Row();
                emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                currentLeftRow = emptyRow;
                if (MatchJoinCondition(emptyRow, rightRow))
                    yield return MergeRows(emptyRow, rightRow);
                else
                    RightOrphanRow(rightRow);
            }
        }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">Rows in pipeline. These are only used if a left part of the join was not specified.</param>
        /// <returns></returns>
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            PrepareForJoin();

            Dictionary<Row, object> matchedRightRows = new Dictionary<Row, object>();
            CachingEnumerable<Row> rightEnumerable = new CachingEnumerable<Row>(
                new EventRaisingEnumerator(right, right.Execute(null))
                );
            IEnumerable<Row> execute = left.Execute(leftRegistered ? null : rows);
            foreach (Row leftRow in new EventRaisingEnumerator(left, execute))
            {
                bool leftNeedOuterJoin = true;
                currentLeftRow = leftRow;
                foreach (Row rightRow in rightEnumerable)
                {
                    currentRightRow = rightRow;
                    if (MatchJoinCondition(leftRow, rightRow))
                    {
                        leftNeedOuterJoin = false;
                        matchedRightRows[rightRow] = null;
                        yield return MergeRows(leftRow, rightRow);
                    }
                }
                if (leftNeedOuterJoin)
                {
                    Row emptyRow = new Row();
                    emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                    currentRightRow = emptyRow;
                    if (MatchJoinCondition(leftRow, emptyRow))
                        yield return MergeRows(leftRow, emptyRow);
                    else
                        LeftOrphanRow(leftRow);
                }
            }
            foreach (Row rightRow in rightEnumerable)
            {
                if (matchedRightRows.ContainsKey(rightRow))
                    continue;
                currentRightRow = rightRow;
                Row emptyRow = new Row();
                emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                currentLeftRow = emptyRow;
                if (MatchJoinCondition(emptyRow, rightRow))
                    yield return MergeRows(emptyRow, rightRow);
                else
                    RightOrphanRow(rightRow);
            }
        }
        private IEnumerable <FdoRow> GetRightEnumerable()
        {
            IEnumerable <FdoRow> rightEnumerable = new CachingEnumerable <FdoRow>(
                new EventRaisingEnumerator(right, right.Execute(null))
                );

            foreach (FdoRow row in rightEnumerable)
            {
                ObjectArrayKeys key = row.CreateKey(rightColumns);
                List <FdoRow>   rowsForKey;
                if (this.rightRowsByJoinKey.TryGetValue(key, out rowsForKey) == false)
                {
                    this.rightRowsByJoinKey[key] = rowsForKey = new List <FdoRow>();
                }
                rowsForKey.Add(row);
            }
            return(rightEnumerable);
        }
        /// <summary>
        ///     Executes this operation, sending the input of this operation
        ///     to all its child operations
        /// </summary>
        /// <param name="rows">The rows.</param>
        /// <returns></returns>
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows) {
            var copiedRows = new CachingEnumerable<Row>(rows);

            foreach (var operation in Operations) {
                var cloned = copiedRows.Select(r => r.Clone());

                var enumerable = operation.Execute(cloned);

                if (enumerable == null)
                    continue;

                var enumerator = enumerable.GetEnumerator();
#pragma warning disable 642
                while (enumerator.MoveNext()) ;
#pragma warning restore 642
            }
            yield break;
        }
Beispiel #8
0
        private async Task <IAsyncEnumerable <Row> > GetRightEnumerable(CancellationToken cancellationToken = default)
        {
            IAsyncEnumerable <Row> rightEnumerable = new CachingEnumerable <Row>(new EventRaisingEnumerator(right, right.Execute(null, cancellationToken)),
                                                                                 cancellationToken);
            await rightEnumerable.ForEachAsync(row =>
            {
                ObjectArrayKeys key = row.CreateKey(rightColumns);
                List <Row> rowsForKey;
                if (this.rightRowsByJoinKey.TryGetValue(key, out rowsForKey) == false)
                {
                    this.rightRowsByJoinKey[key] = rowsForKey = new List <Row>();
                }

                rowsForKey.Add(row);
            }, cancellationToken);

            return(rightEnumerable);
        }
 private IEnumerable<Row> GetRightEnumerable() {
     IEnumerable<Row> rightEnumerable = new CachingEnumerable<Row>(
         new EventRaisingEnumerator(right, right.Execute(null))
         );
     foreach (var row in rightEnumerable) {
         var key = row.CreateKey(rightColumns);
         List<Row> rowsForKey;
         if (rightRowsByJoinKey.TryGetValue(key, out rowsForKey) == false) {
             rightRowsByJoinKey[key] = rowsForKey = new List<Row>();
         }
         rowsForKey.Add(row);
     }
     return rightEnumerable;
 }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="ignored">Ignored rows</param>
        /// <returns></returns>
        public override IEnumerable <Row> Execute(IEnumerable <Row> ignored)
        {
            Initialize();

            Guard.Against(left == null, "Left branch of a join cannot be null");
            Guard.Against(right == null, "Right branch of a join cannot be null");

            Dictionary <Row, object> matchedRightRows = new Dictionary <Row, object>();
            CachingEnumerable <Row>  rightEnumerable  = new CachingEnumerable <Row>(
                new EventRaisingEnumerator(right, right.Execute(null))
                );
            IEnumerable <Row> execute = left.Execute(null);

            foreach (Row leftRow in new EventRaisingEnumerator(left, execute))
            {
                bool leftNeedOuterJoin = true;
                currentLeftRow = leftRow;
                foreach (Row rightRow in rightEnumerable)
                {
                    currentRightRow = rightRow;
                    if (MatchJoinCondition(leftRow, rightRow))
                    {
                        leftNeedOuterJoin          = false;
                        matchedRightRows[rightRow] = null;
                        yield return(MergeRows(leftRow, rightRow));
                    }
                }
                if (leftNeedOuterJoin)
                {
                    Row emptyRow = new Row();
                    emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                    currentRightRow            = emptyRow;
                    if (MatchJoinCondition(leftRow, emptyRow))
                    {
                        yield return(MergeRows(leftRow, emptyRow));
                    }
                    else
                    {
                        LeftOrphanRow(leftRow);
                    }
                }
            }
            foreach (Row rightRow in rightEnumerable)
            {
                if (matchedRightRows.ContainsKey(rightRow))
                {
                    continue;
                }
                currentRightRow = rightRow;
                Row emptyRow = new Row();
                emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                currentLeftRow             = emptyRow;
                if (MatchJoinCondition(emptyRow, rightRow))
                {
                    yield return(MergeRows(emptyRow, rightRow));
                }
                else
                {
                    RightOrphanRow(rightRow);
                }
            }
        }
        /// <summary>
        /// Executes this operation
        /// </summary>
        /// <param name="rows">Rows in pipeline. These are only used if a left part of the join was not specified.</param>
        /// <param name="cancellationToken">A CancellationToken to stop execution</param>
        /// <returns></returns>
        public override IAsyncEnumerable <Row> Execute(IAsyncEnumerable <Row> rows, CancellationToken cancellationToken = default)
        {
            return(new AsyncEnumerable <Row>(async yield => {
                PrepareForJoin();

                Dictionary <Row, object> matchedRightRows = new Dictionary <Row, object>();
                CachingEnumerable <Row> rightEnumerable = new CachingEnumerable <Row>(
                    new EventRaisingEnumerator(right, right.Execute(null, cancellationToken)), cancellationToken);
                IAsyncEnumerable <Row> execute = left.Execute(leftRegistered ? null : rows, cancellationToken);
                await new EventRaisingEnumerator(left, execute)
                .ForEachAsync(async leftRow =>
                {
                    bool leftNeedOuterJoin = true;
                    currentLeftRow = leftRow;
                    await rightEnumerable.ForEachAsync(async rightRow =>
                    {
                        currentRightRow = rightRow;
                        if (MatchJoinCondition(leftRow, rightRow))
                        {
                            leftNeedOuterJoin = false;
                            matchedRightRows[rightRow] = null;
                            await yield
                            .ReturnAsync(MergeRows(leftRow,
                                                   rightRow));
                        }
                    }, cancellationToken);

                    if (leftNeedOuterJoin)
                    {
                        Row emptyRow = new Row();
                        emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                        currentRightRow = emptyRow;
                        if (MatchJoinCondition(leftRow, emptyRow))
                        {
                            await yield.ReturnAsync(MergeRows(leftRow, emptyRow));
                        }
                        else
                        {
                            LeftOrphanRow(leftRow);
                        }
                    }
                }, cancellationToken);
                await rightEnumerable.ForEachAsync(async rightRow =>
                {
                    if (matchedRightRows.ContainsKey(rightRow))
                    {
                        return;
                    }
                    currentRightRow = rightRow;
                    Row emptyRow = new Row();
                    emptyRow[IsEmptyRowMarker] = IsEmptyRowMarker;
                    currentLeftRow = emptyRow;
                    if (MatchJoinCondition(emptyRow, rightRow))
                    {
                        await yield.ReturnAsync(MergeRows(emptyRow, rightRow));
                    }
                    else
                    {
                        RightOrphanRow(rightRow);
                    }
                }, cancellationToken);
            }));
        }