Ejemplo n.º 1
0
        internal override GremlinToSqlContext GetContext()
        {
            GremlinToSqlContext inputContext = GetInputContext();

            if (inputContext.PivotVariable == null)
            {
                throw new QueryCompilationException("The PivotVariable can't be null.");
            }

            switch (Type)
            {
            //has(key)
            case GremlinHasType.HasProperty:
                inputContext.PivotVariable.Has(inputContext, PropertyKey);
                break;

            //hasNot(key)
            case GremlinHasType.HasNotProperty:
                inputContext.PivotVariable.HasNot(inputContext, PropertyKey);
                break;

            //has(key, value) | has(key, predicate)
            case GremlinHasType.HasPropertyValueOrPredicate:
                inputContext.PivotVariable.Has(inputContext, PropertyKey, ValueOrPredicate);
                break;

            //has(key, traversal)
            case GremlinHasType.HasPropertyTraversal:
                Traversal.GetStartOp().InheritedVariableFromParent(inputContext);
                if (Traversal.GetStartOp() is GremlinParentContextOp)
                {
                    if (Traversal.TranslationOpList.Count > 1)
                    {
                        Traversal.InsertOperator(1, new GremlinValuesOp(PropertyKey));
                    }
                    else
                    {
                        Traversal.AddOperator(new GremlinValuesOp(PropertyKey));
                    }
                }
                GremlinToSqlContext hasContext = Traversal.GetEndOp().GetContext();
                inputContext.AddPredicate(hasContext.ToSqlBoolean());
                break;

            //has(label, key, value) | has(label, key, predicate)
            case GremlinHasType.HasLabelPropertyValue:
                inputContext.PivotVariable.Has(inputContext, GremlinKeyword.Label, Label);
                inputContext.PivotVariable.Has(inputContext, PropertyKey, ValueOrPredicate);
                break;

            //hasId(values)
            case GremlinHasType.HasId:
            case GremlinHasType.HasLabel:
                inputContext.PivotVariable.HasIdOrLabel(inputContext, Type, ValuesOrPredicates);
                break;

            //===================================================================
            //hasKey(values) || hasValue(values)
            case GremlinHasType.HasKey:
            case GremlinHasType.HasValue:
                inputContext.PivotVariable.HasKeyOrValue(inputContext, Type, ValuesOrPredicates);
                break;
            }
            return(inputContext);
        }