Пример #1
0
        public override RawRecord Next()
        {
            if (inputOp.State())
            {
                RawRecord r = inputOp.Next();
                if (r == null)
                {
                    Close();
                    return(null);
                }

                FieldObject groupByKey = groupByKeyFieldIndex >= 0
                    ? new StringField(r[groupByKeyFieldIndex].ToValue)
                    : groupByKeyFunction.Evaluate(r);

                GroupState.Accumulate(new Object[] { groupByKey, r });

                if (!inputOp.State())
                {
                    Close();
                }
                return(r);
            }

            return(null);
        }
Пример #2
0
        public override RawRecord Next()
        {
            if (TableInput.State())
            {
                RawRecord rec = TableInput.Next();
                if (rec != null)
                {
                    tableCache.Add(rec);
                    return(rec);
                }
                else
                {
                    TableInput.Close();
                    return(null);
                }
            }

            return(tableCache.Count > 0 ? tableCache[tableCache.Count - 1] : null);
        }
        public override RawRecord Next()
        {
            RawRecord srcRecord = null;

            while (InputOperator.State() && (srcRecord = InputOperator.Next()) != null)
            {
                RawRecord result = DataModify(srcRecord);
                if (result == null)
                {
                    continue;
                }

                RawRecord resultRecord = new RawRecord(srcRecord);
                resultRecord.Append(result);

                return(resultRecord);
            }

            Close();
            return(null);
        }
Пример #4
0
        public override RawRecord Next()
        {
            if (outputBuffer.Count > 0)
            {
                RawRecord r        = new RawRecord(currentRecord);
                RawRecord toAppend = outputBuffer.Dequeue();
                r.Append(toAppend);

                return(r);
            }

            while (inputOperator.State())
            {
                currentRecord = inputOperator.Next();
                if (currentRecord == null)
                {
                    Close();
                    return(null);
                }

                List <RawRecord> results = CrossApply(currentRecord);

                foreach (RawRecord rec in results)
                {
                    outputBuffer.Enqueue(rec);
                }

                if (outputBuffer.Count > 0)
                {
                    RawRecord r        = new RawRecord(currentRecord);
                    RawRecord toAppend = outputBuffer.Dequeue();
                    r.Append(toAppend);

                    return(r);
                }
            }

            Close();
            return(null);
        }
Пример #5
0
        public override RawRecord Next()
        {
            while (this.State())
            {
                if (this.inputBatch.Any())
                {
                    RawRecord subTraversalRecord;
                    while (localTraversal.State() && (subTraversalRecord = localTraversal.Next()) != null)
                    {
                        int       subTraversalRecordIndex = int.Parse(subTraversalRecord[0].ToValue);
                        RawRecord resultRecord            = inputBatch[subTraversalRecordIndex].GetRange(1);
                        resultRecord.Append(subTraversalRecord.GetRange(1));
                        return(resultRecord);
                    }
                }

                this.inputBatch.Clear();
                RawRecord inputRecord;
                while (this.inputBatch.Count < this.batchSize && this.inputOp.State() && (inputRecord = inputOp.Next()) != null)
                {
                    RawRecord batchRawRecord = new RawRecord();
                    batchRawRecord.Append(new StringField(this.inputBatch.Count.ToString(), JsonDataType.Int));
                    batchRawRecord.Append(inputRecord);

                    inputBatch.Add(batchRawRecord);
                }

                if (!inputBatch.Any())
                {
                    this.Close();
                    return(null);
                }

                this.container.ResetTableCache(inputBatch);
                this.localTraversal.ResetState();
            }

            return(null);
        }
Пример #6
0
        public override RawRecord Next()
        {
            if (this.needInitialize)
            {
                List <RawRecord> inputs = new List <RawRecord>();
                RawRecord        inputRecord;
                while (this.inputOp.State() && (inputRecord = this.inputOp.Next()) != null)
                {
                    RawRecord batchRawRecord = new RawRecord();
                    batchRawRecord.Append(new StringField(inputs.Count.ToString(), JsonDataType.Int));
                    batchRawRecord.Append(inputRecord);
                    inputs.Add(batchRawRecord);
                }

                if (!inputs.Any())
                {
                    this.Close();
                    return(null);
                }

                this.container.ResetTableCache(inputs);
                this.targetSubOp.ResetState();

                this.selectOption = Enumerable.Repeat(-1, this.container.Count).ToList();
                int       index = 0;
                RawRecord targetRecord;
                while (this.targetSubOp.State() && (targetRecord = this.targetSubOp.Next()) != null)
                {
                    // one input, one output. must one to one
                    Debug.Assert(this.container[index][0].ToValue == targetRecord[0].ToValue,
                                 "The provided traversal of choose() does not map to a value.");

                    FieldObject value = targetRecord[1];
                    RawRecord   input = this.container[index].GetRange(1);
                    for (int i = 0; i < this.traversalList.Count; i++)
                    {
                        if (this.traversalList[i].Item1.Equals(value))
                        {
                            this.traversalList[i].Item2.Add(input);
                            this.selectOption[index] = i;
                            break;
                        }

                        if (i == this.traversalList.Count - 1 && this.optionNoneTraversalOp != null)
                        {
                            this.optionNoneContainer.Add(input);
                        }
                    }

                    index++;
                }

                this.needInitialize = false;
            }

            if (this.State())
            {
                if (this.outputBuffer.Any())
                {
                    return(this.outputBuffer.Dequeue());
                }

                while (this.currentIndex < this.container.Count)
                {
                    int select = this.selectOption[this.currentIndex];
                    if (select != -1)
                    {
                        GraphViewExecutionOperator op = this.traversalList[select].Item3;
                        RawRecord record;
                        while (op.State() && (record = op.Next()) != null)
                        {
                            this.outputBuffer.Enqueue(record);
                        }
                    }
                    else if (this.optionNoneTraversalOp != null)
                    {
                        RawRecord record;
                        while (this.optionNoneTraversalOp.State() && (record = this.optionNoneTraversalOp.Next()) != null)
                        {
                            this.outputBuffer.Enqueue(record);
                        }
                    }

                    this.currentIndex++;

                    if (this.outputBuffer.Any())
                    {
                        return(this.outputBuffer.Dequeue());
                    }
                }

                if (!this.outputBuffer.Any())
                {
                    this.Close();
                    return(null);
                }
            }
            return(null);
        }
Пример #7
0
        public override RawRecord Next()
        {
            if (!State())
            {
                return(null);
            }

            RawRecord r = null;

            while (inputOp.State() && (r = inputOp.Next()) != null)
            {
                FieldObject groupByKey = groupByKeyFieldIndex >= 0
                    ? new StringField(r[groupByKeyFieldIndex].ToValue)
                    : groupByKeyFunction.Evaluate(r);

                if (!groupedStates.ContainsKey(groupByKey))
                {
                    groupedStates.Add(groupByKey, new List <RawRecord>());
                }
                groupedStates[groupByKey].Add(r);
            }

            Dictionary <FieldObject, FieldObject> resultCollection = new Dictionary <FieldObject, FieldObject>(groupedStates.Count);

            if (elementPropertyProjectionIndex >= 0)
            {
                foreach (FieldObject key in groupedStates.Keys)
                {
                    List <FieldObject> projectFields = new List <FieldObject>();
                    foreach (var rawRecord in groupedStates[key])
                    {
                        FieldObject fo = rawRecord[elementPropertyProjectionIndex];
                        if (fo is PropertyField)
                        {
                            PropertyField pf = fo as PropertyField;
                            projectFields.Add(new StringField(pf.PropertyValue, pf.JsonDataType));
                        }
                        else
                        {
                            projectFields.Add(fo);
                        }
                    }
                    resultCollection[key] = new CollectionField(projectFields);
                }
            }
            else
            {
                foreach (KeyValuePair <FieldObject, List <RawRecord> > pair in groupedStates)
                {
                    FieldObject      key = pair.Key;
                    List <RawRecord> aggregatedRecords = pair.Value;
                    groupedSourceOp.ResetState();
                    aggregateOp.ResetState();

                    foreach (RawRecord record in aggregatedRecords)
                    {
                        tempSourceOp.ConstantSource = record;
                        groupedSourceOp.Next();
                    }

                    RawRecord aggregateTraversalRecord = aggregateOp.Next();

                    FieldObject aggregateResult = aggregateTraversalRecord?.RetriveData(0);
                    if (aggregateResult == null)
                    {
                        Close();
                        return(null);
                    }

                    resultCollection[key] = aggregateResult;
                }
            }

            RawRecord resultRecord = new RawRecord();

            for (int i = 0; i < carryOnCount; i++)
            {
                resultRecord.Append((FieldObject)null);
            }

            resultRecord.Append(new MapField(resultCollection));

            Close();
            return(resultRecord);
        }