Beispiel #1
0
        public List <string> Next()
        {
            WSqlScript sqlScript = this.GetEndOp().ToSqlScript();

            SqlScript = sqlScript.ToString();

            GraphViewExecutionOperator op = sqlScript.Batches[0].Compile(null, this.connection);
            List <RawRecord>           rawRecordResults = new List <RawRecord>();
            RawRecord outputRec = null;

            while ((outputRec = op.Next()) != null)
            {
                rawRecordResults.Add(outputRec);
            }

            List <string> results = new List <string>();

            switch (outputFormat)
            {
            case OutputFormat.GraphSON:
                results.Add(GraphSONProjector.ToGraphSON(rawRecordResults, this.connection));
                break;

            default:
                foreach (var record in rawRecordResults)
                {
                    FieldObject field = record[0];
                    results.Add(field.ToString());
                }
                break;
            }

            return(results);
        }
        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);
        }
Beispiel #3
0
            public bool MoveNext()
            {
                if (currentOperator == null)
                {
                    return(false);
                }

                if (outputFormat == OutputFormat.GraphSON)
                {
                    List <RawRecord> rawRecordResults = new List <RawRecord>();

                    RawRecord outputRec  = null;
                    bool      firstEntry = true;
                    while ((outputRec = currentOperator.Next()) != null)
                    {
                        rawRecordResults.Add(outputRec);
                        firstEntry = false;
                    }

                    if (firstEntry && !firstCall)
                    {
                        return(false);
                    }
                    else
                    {
                        firstCall     = false;
                        currentRecord = GraphSONProjector.ToGraphSON(rawRecordResults, this.connection);
                        return(true);
                    }
                }
                else
                {
                    RawRecord outputRec = null;
                    if ((outputRec = currentOperator.Next()) != null)
                    {
                        currentRecord = outputRec[0].ToString();
                        return(currentRecord != null);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
Beispiel #4
0
        public override FieldObject Evaluate(RawRecord record)
        {
            this.container.ResetTableCache(record);
            subqueryOp.ResetState();
            RawRecord firstResult = subqueryOp.Next();

            subqueryOp.Close();

            return(firstResult == null ? null : firstResult.RetriveData(0));
        }
Beispiel #5
0
        public override bool Evaluate(RawRecord r)
        {
            this.container.ResetTableCache(r);
            subqueryOp.ResetState();
            RawRecord firstResult = subqueryOp.Next();

            subqueryOp.Close();

            return(firstResult != null);
        }
        public override bool Evaluate(RawRecord r)
        {
            constantSourceOp.ConstantSource = r;
            subqueryOp.ResetState();
            RawRecord firstResult = subqueryOp.Next();

            subqueryOp.Close();

            return(firstResult != null);
        }
Beispiel #7
0
        public override FieldObject Evaluate(RawRecord record)
        {
            constantSourceOp.ConstantSource = record;
            subqueryOp.ResetState();
            RawRecord firstResult = subqueryOp.Next();

            subqueryOp.Close();

            //return firstResult == null ? null : firstResult.RetriveData(0).ToString();
            return(firstResult == null ? null : firstResult.RetriveData(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));
        }
        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);
        }
        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);
        }
Beispiel #12
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);
        }
Beispiel #13
0
            public bool MoveNext()
            {
                if (currentOperator == null)
                {
                    return(false);
                }

                if (outputFormat == OutputFormat.GraphSON)
                {
                    RawRecord     outputRec       = null;
                    StringBuilder graphsonBuilder = new StringBuilder();
                    graphsonBuilder.Append("[");
                    bool firstEntry = true;
                    while ((outputRec = currentOperator.Next()) != null)
                    {
                        if (firstEntry)
                        {
                            firstEntry = false;
                        }
                        else
                        {
                            graphsonBuilder.Append(", ");
                        }
                        graphsonBuilder.Append(outputRec[0].ToGraphSON());
                    }
                    graphsonBuilder.Append("]");

                    if (firstEntry && !firstCall)     // No results are pulled from the execution operator
                    {
                        return(false);
                    }
                    else
                    {
                        firstCall     = false;
                        currentRecord = graphsonBuilder.ToString();
                        return(true);
                    }
                }
                else
                {
                    RawRecord outputRec = null;
                    if ((outputRec = currentOperator.Next()) != null)
                    {
                        switch (outputFormat)
                        {
                        case OutputFormat.GraphSON:
                            currentRecord = outputRec[0].ToGraphSON();
                            break;

                        default:
                            currentRecord = outputRec[0].ToString();
                            break;
                        }
                        return(currentRecord != null);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
Beispiel #14
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);
        }
Beispiel #15
0
        public override RawRecord Next()
        {
            while (this.State())
            {
                if (this.outputBuffer.Any())
                {
                    // Output in order
                    foreach (Queue <RawRecord> queue in this.outputBuffer.Values)
                    {
                        if (queue.Any())
                        {
                            return(queue.Dequeue());
                        }
                    }

                    // nothing in any queue
                    this.outputBuffer.Clear();
                }

                List <RawRecord> inputBatch = new List <RawRecord>();
                // add to input batch.
                RawRecord inputRecord;

                // Indexes of Racords that will be transfered to next sub-traversal.
                // This set will be updated each time a sub-traversal finish.
                while (inputBatch.Count < this.batchSize && this.inputOp.State() && (inputRecord = inputOp.Next()) != null)
                {
                    RawRecord batchRawRecord = new RawRecord();
                    batchRawRecord.Append(new StringField(inputBatch.Count.ToString(), JsonDataType.Int));
                    batchRawRecord.Append(inputRecord);

                    inputBatch.Add(batchRawRecord);
                }

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

                this.container.ResetTableCache(inputBatch);
                int finishedCount = 0;

                foreach (GraphViewExecutionOperator subTraversal in this.traversalList)
                {
                    subTraversal.ResetState();

                    RawRecord  subTraversalRecord;
                    List <int> deleteIndex = new List <int>();
                    while (subTraversal.State() && (subTraversalRecord = subTraversal.Next()) != null)
                    {
                        int       subTraversalRecordIndex = int.Parse(subTraversalRecord[0].ToValue);
                        RawRecord resultRecord            = this.container[subTraversalRecordIndex].GetRange(1);
                        resultRecord.Append(subTraversalRecord.GetRange(1));

                        if (!this.outputBuffer.ContainsKey(subTraversalRecordIndex))
                        {
                            this.outputBuffer[subTraversalRecordIndex] = new Queue <RawRecord>();
                            deleteIndex.Add(subTraversalRecordIndex);
                            finishedCount++;
                        }
                        this.outputBuffer[subTraversalRecordIndex].Enqueue(resultRecord);
                    }

                    this.container.Delete(deleteIndex);

                    if (finishedCount == this.container.Count)
                    {
                        break;
                    }
                }
            }

            return(null);
        }
        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);
        }