Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
        }