public List <string> Next() { var sqlScript = LastGremlinTranslationOp.ToSqlScript(); SqlScript = sqlScript.ToString(); //Console.WriteLine(str); // Added temporarily for debugging purpose. //Console.WriteLine(); var op = sqlScript.Batches[0].Compile(null, Connection); var 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: string result = "["; bool firstEntry = true; foreach (var record in rawRecordResults) { if (firstEntry) { firstEntry = false; } else { result += ", "; } FieldObject field = record[0]; result += field.ToGraphSON(); } result += "]"; results.Add(result); break; default: foreach (var record in rawRecordResults) { FieldObject field = record[0]; results.Add(field.ToString()); } break; } return(results); }
internal static string ToGraphSON(List <RawRecord> results, GraphViewConnection connection) { StringBuilder finalGraphSonResult = new StringBuilder("["); HashSet <string> batchIdSet = new HashSet <string>(); Dictionary <int, VertexField> batchGraphSonDict = new Dictionary <int, VertexField>(); StringBuilder notBatchedGraphSonResult = new StringBuilder(); bool firstEntry = true; foreach (RawRecord record in results) { if (firstEntry) { firstEntry = false; } else { notBatchedGraphSonResult.Append(", "); } FieldObject field = record[0]; VertexField vertexField = field as VertexField; if (vertexField != null && (!vertexField.AdjacencyList.HasBeenFetched || !vertexField.RevAdjacencyList.HasBeenFetched)) { string vertexId = vertexField[GraphViewKeywords.KW_DOC_ID].ToValue; batchIdSet.Add(vertexId); batchGraphSonDict.Add(notBatchedGraphSonResult.Length, vertexField); continue; } notBatchedGraphSonResult.Append(field.ToGraphSON()); } if (batchIdSet.Any()) { EdgeDocumentHelper.ConstructSpilledAdjListsOrVirtualRevAdjListsOfVertices(connection, batchIdSet); int startIndex = 0; foreach (KeyValuePair <int, VertexField> kvp in batchGraphSonDict) { int insertedPosition = kvp.Key; int length = insertedPosition - startIndex; VertexField vertexField = kvp.Value; finalGraphSonResult.Append(notBatchedGraphSonResult.ToString(startIndex, length)); finalGraphSonResult.Append(vertexField.ToGraphSON()); startIndex = insertedPosition; } finalGraphSonResult.Append(notBatchedGraphSonResult.ToString(startIndex, notBatchedGraphSonResult.Length - startIndex)); } else { finalGraphSonResult.Append(notBatchedGraphSonResult.ToString()); } finalGraphSonResult.Append("]"); return(finalGraphSonResult.ToString()); }