Ejemplo n.º 1
0
        public FieldObject Terminate()
        {
            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)
                    {
                        return(null);
                    }

                    resultCollection[key] = aggregateResult;
                }
            }

            return(new MapField(resultCollection));
        }
Ejemplo n.º 2
0
        public bool MoveNext()
        {
            if (offset + 1 >= tableCache.Count)
            {
                containerOp.Next();
                if (offset + 1 < tableCache.Count)
                {
                    offset++;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            offset++;
            return(true);
        }
Ejemplo n.º 3
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);
        }