private static void ConstructTree(TreeField root, int index, PathField pathField) { if (index >= pathField.Path.Count) { return; } PathStepField pathStepField = pathField.Path[index++] as PathStepField; Debug.Assert(pathStepField != null, "pathStepField != null"); CompositeField compose1PathStep = pathStepField.StepFieldObject as CompositeField; Debug.Assert(compose1PathStep != null, "compose1PathStep != null"); FieldObject nodeObject = compose1PathStep[compose1PathStep.DefaultProjectionKey]; TreeField child; if (!root.Children.TryGetValue(nodeObject, out child)) { child = new TreeField(nodeObject); root.Children[nodeObject] = child; } ConstructTree(child, index, pathField); }
public override FieldObject Evaluate(RawRecord record) { List <FieldObject> path = new List <FieldObject>(); foreach (Tuple <ScalarFunction, bool, HashSet <string> > tuple in pathStepList) { ScalarFunction accessPathStepFunc = tuple.Item1; bool needsUnfold = tuple.Item2; HashSet <string> stepLabels = tuple.Item3; if (accessPathStepFunc == null) { PathStepField pathStepField = new PathStepField(null); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); continue; } FieldObject step = accessPathStepFunc.Evaluate(record); if (step == null) { PathStepField lastPathStep; if (path.Any()) { lastPathStep = (PathStepField)path[path.Count - 1]; } else { lastPathStep = new PathStepField(null); path.Add(lastPathStep); } foreach (string label in stepLabels) { lastPathStep.AddLabel(label); } continue; } if (needsUnfold) { PathField subPath = step as PathField; Debug.Assert(subPath != null, "(subPath as PathField) != null"); foreach (PathStepField subPathStep in subPath.Path.Cast <PathStepField>()) { if (subPathStep.StepFieldObject == null) { if (path.Any()) { PathStepField lastPathStep = (PathStepField)path[path.Count - 1]; foreach (string label in subPathStep.Labels) { lastPathStep.AddLabel(label); } } else { path.Add(subPathStep); } continue; } PathStepField pathStepField = new PathStepField(subPathStep.StepFieldObject); foreach (string label in subPathStep.Labels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } PathStepField lastSubPathStep = (PathStepField)path.Last(); foreach (string label in stepLabels) { lastSubPathStep.AddLabel(label); } } else { PathStepField pathStepField = new PathStepField(step); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } } return(new PathField(path)); }
public override RawRecord Next() { RawRecord inputRec; while (this.inputOp.State() && (inputRec = this.inputOp.Next()) != null) { List <FieldObject> path = new List <FieldObject>(); int activeByFuncIndex = 0; foreach (Tuple <ScalarFunction, bool, HashSet <string> > tuple in pathStepList) { ScalarFunction accessPathStepFunc = tuple.Item1; bool needsUnfold = tuple.Item2; HashSet <string> stepLabels = tuple.Item3; if (accessPathStepFunc == null) { PathStepField pathStepField = new PathStepField(null); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); continue; } FieldObject step = accessPathStepFunc.Evaluate(inputRec); if (step == null) { PathStepField lastPathStep; if (path.Any()) { lastPathStep = (PathStepField)path[path.Count - 1]; } else { lastPathStep = new PathStepField(null); path.Add(lastPathStep); } foreach (string label in stepLabels) { lastPathStep.AddLabel(label); } continue; } if (needsUnfold) { PathField subPath = step as PathField; Debug.Assert(subPath != null, "(subPath as PathField) != null"); foreach (PathStepField subPathStep in subPath.Path.Cast <PathStepField>()) { if (subPathStep.StepFieldObject == null) { if (path.Any()) { PathStepField lastPathStep = (PathStepField)path[path.Count - 1]; foreach (string label in subPathStep.Labels) { lastPathStep.AddLabel(label); } } else { path.Add(subPathStep); } continue; } FieldObject pathStep = GetStepProjectionResult(subPathStep.StepFieldObject, ref activeByFuncIndex); PathStepField pathStepField = new PathStepField(pathStep); foreach (string label in subPathStep.Labels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } PathStepField lastSubPathStep = (PathStepField)path.Last(); foreach (string label in stepLabels) { lastSubPathStep.AddLabel(label); } } else { FieldObject pathStep = GetStepProjectionResult(step, ref activeByFuncIndex); Compose1Field compose1PathStep = pathStep as Compose1Field; Debug.Assert(compose1PathStep != null, "compose1PathStep != null"); // // g.V().optional(__.count().V()).path() // if (compose1PathStep[compose1PathStep.DefaultProjectionKey] == null) { continue; } PathStepField pathStepField = new PathStepField(pathStep); foreach (string label in stepLabels) { pathStepField.AddLabel(label); } path.Add(pathStepField); } } RawRecord r = new RawRecord(inputRec); r.Append(new PathField(path)); return(r); } this.Close(); return(null); }