public GremlinBoundEdgeTableVariable(GremlinVariableProperty sourceVertexVariableProperty, GremlinVariableProperty adjEdgeVariableProperty, WEdgeType edgeType) { this.sourceVertexVariableProperty = sourceVertexVariableProperty; this.adjEdgeVariableProperty = adjEdgeVariableProperty; EdgeType = edgeType; }
internal virtual void InV(GremlinToSqlContext currentContext) { GremlinVariableProperty sinkProperty = GetVariableProperty(GremlinKeyword.EdgeSinkV); GremlinTableVariable inVertex = new GremlinBoundVertexVariable(sinkProperty); currentContext.VariableList.Add(inVertex); currentContext.TableReferences.Add(inVertex); currentContext.SetPivotVariable(inVertex); }
internal virtual void OtherV(GremlinToSqlContext currentContext) { GremlinVariableProperty otherProperty = GetVariableProperty(GremlinKeyword.EdgeOtherV); GremlinBoundVertexVariable otherVertex = new GremlinBoundVertexVariable(otherProperty); currentContext.VariableList.Add(otherVertex); currentContext.TableReferences.Add(otherVertex); currentContext.SetPivotVariable(otherVertex); }
internal void DropVertex(GremlinVariable dropVertexVariable) { GremlinVariableProperty variableProperty = dropVertexVariable.GetVariableProperty(GremlinKeyword.NodeID); GremlinDropVariable dropVariable = new GremlinDropVertexVariable(variableProperty); VariableList.Add(dropVariable); TableReferences.Add(dropVariable); SetPivotVariable(dropVariable); }
internal void PopulateColumn(GremlinVariableProperty variableProperty, string alias) { if (ProjectedProperties.Contains(alias)) { return; } ProjectedProperties.Add(alias); ProjectVariablePropertiesList.Add(new Tuple <GremlinVariableProperty, string>(variableProperty, alias)); }
internal virtual void OutV(GremlinToSqlContext currentContext) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinTableVariable outVertex = new GremlinBoundVertexVariable(sourceProperty); currentContext.VariableList.Add(outVertex); currentContext.TableReferences.Add(outVertex); currentContext.SetPivotVariable(outVertex); }
public GremlinBoundEdgeTableVariable(GremlinVariableProperty sourceVertexVariableProperty, GremlinVariableProperty adjEdgeVariableProperty, GremlinVariableProperty labelVariableProperty, WEdgeType edgeType) { SourceVertexVariableProperty = sourceVertexVariableProperty; AdjEdgeVariableProperty = adjEdgeVariableProperty; LabelVariableProperty = labelVariableProperty; EdgeType = edgeType; }
internal void BothV(GremlinVariable lastVariable) { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinVariableProperty sinkProperty = lastVariable.GetVariableProperty(GremlinKeyword.EdgeSinkV); GremlinBoundVertexVariable bothVertex = new GremlinBoundVertexVariable(lastVariable.GetEdgeType(), sourceProperty, sinkProperty); VariableList.Add(bothVertex); TableReferences.Add(bothVertex); SetPivotVariable(bothVertex); }
internal virtual void OutE(GremlinToSqlContext currentContext, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjEdge = GetVariableProperty(GremlinKeyword.EdgeAdj); GremlinBoundEdgeTableVariable outEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjEdge, WEdgeType.OutEdge); currentContext.VariableList.Add(outEdgeTable); currentContext.TableReferences.Add(outEdgeTable); currentContext.AddLabelPredicateForEdge(outEdgeTable, edgeLabels); currentContext.SetPivotVariable(outEdgeTable); }
internal virtual void HasIdOrLabel(GremlinToSqlContext currentContext, GremlinHasType hasType, List <object> valuesOrPredicates) { GremlinVariableProperty variableProperty = hasType == GremlinHasType.HasId ? DefaultVariableProperty() : GetVariableProperty(GremlinKeyword.Label); List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var valuesOrPredicate in valuesOrPredicates) { booleanExprList.Add(CreateBooleanExpression(variableProperty, valuesOrPredicate)); } currentContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); }
internal virtual void InE(GremlinToSqlContext currentContext, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjReverseEdge = GetVariableProperty(GremlinKeyword.ReverseEdgeAdj); GremlinVariableProperty labelProperty = GetVariableProperty(GremlinKeyword.Label); GremlinBoundEdgeTableVariable inEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjReverseEdge, labelProperty, WEdgeType.InEdge); currentContext.VariableList.Add(inEdgeTable); currentContext.TableReferences.Add(inEdgeTable); currentContext.AddLabelPredicateForEdge(inEdgeTable, edgeLabels); //currentContext.PathList.Add(new GremlinMatchPath(null, inEdgeTable, this)); currentContext.SetPivotVariable(inEdgeTable); }
internal void OutE(GremlinVariable lastVariable, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjEdge = lastVariable.GetVariableProperty(GremlinKeyword.EdgeAdj); GremlinVariableProperty labelProperty = lastVariable.GetVariableProperty(GremlinKeyword.Label); GremlinBoundEdgeTableVariable outEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjEdge, labelProperty, WEdgeType.OutEdge); VariableList.Add(outEdgeTable); TableReferences.Add(outEdgeTable); AddLabelPredicateForEdge(outEdgeTable, edgeLabels); AddPath(new GremlinMatchPath(lastVariable, outEdgeTable, null)); SetPivotVariable(outEdgeTable); }
internal void BothE(GremlinVariable lastVariable, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjReverseEdge = lastVariable.GetVariableProperty(GremlinKeyword.ReverseEdgeAdj); GremlinVariableProperty adjEdge = lastVariable.GetVariableProperty(GremlinKeyword.EdgeAdj); GremlinVariableProperty labelProperty = lastVariable.GetVariableProperty(GremlinKeyword.Label); GremlinBoundEdgeTableVariable bothEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjEdge, adjReverseEdge, labelProperty, WEdgeType.BothEdge); VariableList.Add(bothEdgeTable); TableReferences.Add(bothEdgeTable); AddLabelPredicateForEdge(bothEdgeTable, edgeLabels); SetPivotVariable(bothEdgeTable); }
internal List <WSelectElement> GetSelectElement(bool isToCompose1) { var selectElements = new List <WSelectElement>(); if (PivotVariable.GetVariableType() == GremlinVariableType.Null) { selectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetStarColumnReferenceExpr(), GremlinKeyword.TableDefaultColumnName)); return(selectElements); } if (isToCompose1) { selectElements.Add(SqlUtil.GetSelectScalarExpr(PivotVariable.ToCompose1(), GremlinKeyword.TableDefaultColumnName)); return(selectElements); } foreach (var projectProperty in ProjectedProperties) { WSelectScalarExpression selectScalarExpr; if (projectProperty == GremlinKeyword.Path) { selectScalarExpr = SqlUtil.GetSelectScalarExpr(ContextLocalPath.GetDefaultProjection().ToScalarExpression(), GremlinKeyword.Path); } else if (projectProperty == GremlinKeyword.TableDefaultColumnName) { GremlinVariableProperty defaultProjection = PivotVariable.GetDefaultProjection(); selectScalarExpr = SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), GremlinKeyword.TableDefaultColumnName); } else if (PivotVariable.ProjectedProperties.Contains(projectProperty)) { WScalarExpression columnExpr = PivotVariable.GetVariableProperty(projectProperty).ToScalarExpression(); selectScalarExpr = SqlUtil.GetSelectScalarExpr(columnExpr, projectProperty); } else { selectScalarExpr = SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), projectProperty); } selectElements.Add(selectScalarExpr); } if (selectElements.Count == 0) { GremlinVariableProperty defaultProjection = PivotVariable.GetDefaultProjection(); selectElements.Add(SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), GremlinKeyword.TableDefaultColumnName)); } return(selectElements); }
private WBooleanExpression CreateBooleanExpression(GremlinVariableProperty variableProperty, object valuesOrPredicate) { if (valuesOrPredicate is string || valuesOrPredicate is int || valuesOrPredicate is bool) { WScalarExpression firstExpr = variableProperty.ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(valuesOrPredicate); return(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); } if (valuesOrPredicate is Predicate) { WScalarExpression firstExpr = variableProperty.ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr((valuesOrPredicate as Predicate).Value); return(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, valuesOrPredicate as Predicate)); } throw new ArgumentException(); }
/// <summary> /// Only valid for VertexProperty /// </summary> internal virtual void HasKeyOrValue(GremlinToSqlContext currentContext, GremlinHasType hasType, List <object> valuesOrPredicates) { GraphTraversal2 traversal2 = hasType == GremlinHasType.HasKey ? GraphTraversal2.__().Key() : GraphTraversal2.__().Value(); traversal2.GetStartOp().InheritedVariableFromParent(currentContext); GremlinToSqlContext existContext = traversal2.GetEndOp().GetContext(); List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); GremlinVariableProperty defaultVariableProperty = existContext.PivotVariable.DefaultProjection(); foreach (var valuesOrPredicate in valuesOrPredicates) { booleanExprList.Add(CreateBooleanExpression(defaultVariableProperty, valuesOrPredicate)); } existContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); currentContext.AddPredicate(SqlUtil.GetExistPredicate(existContext.ToSelectQueryBlock())); }
internal virtual void In(GremlinToSqlContext currentContext, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjReverseEdge = GetVariableProperty(GremlinKeyword.ReverseEdgeAdj); GremlinBoundEdgeTableVariable inEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjReverseEdge, WEdgeType.InEdge); currentContext.VariableList.Add(inEdgeTable); currentContext.TableReferences.Add(inEdgeTable); currentContext.AddLabelPredicateForEdge(inEdgeTable, edgeLabels); GremlinVariableProperty edgeProperty = inEdgeTable.GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinBoundVertexVariable outVertex = new GremlinBoundVertexVariable(edgeProperty); currentContext.VariableList.Add(outVertex); currentContext.TableReferences.Add(outVertex); currentContext.SetPivotVariable(outVertex); }
internal void OutV(GremlinVariable lastVariable) { if (lastVariable is GremlinFreeEdgeTableVariable) { var path = GetPathFromPathList(lastVariable); if (path != null && path.SourceVariable != null) { if (IsVariableInCurrentContext(path.SourceVariable)) { SetPivotVariable(path.SourceVariable); } else { GremlinContextVariable newContextVariable = GremlinContextVariable.Create(path.SourceVariable); VariableList.Add(newContextVariable); SetPivotVariable(newContextVariable); } } else { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinTableVariable outVertex = lastVariable.CreateAdjVertex(sourceProperty); if (path != null) { path.SetSourceVariable(outVertex); } VariableList.Add(outVertex); TableReferences.Add(outVertex); SetPivotVariable(outVertex); } } else { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinTableVariable outVertex = new GremlinBoundVertexVariable(lastVariable.GetEdgeType(), sourceProperty); VariableList.Add(outVertex); TableReferences.Add(outVertex); SetPivotVariable(outVertex); } }
internal List <WSelectElement> GetSelectElement(bool isToCompose1) { var selectElements = new List <WSelectElement>(); if (this.PivotVariable.GetVariableType() == GremlinVariableType.NULL) { selectElements.Add( SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), GremlinKeyword.TableDefaultColumnName)); return(selectElements); } if (isToCompose1) { selectElements.Add( SqlUtil.GetSelectScalarExpr(this.PivotVariable.ToCompose1(), GremlinKeyword.TableDefaultColumnName)); return(selectElements); } GremlinVariableProperty defaultProjection = this.PivotVariable.DefaultProjection(); selectElements.Add( SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), this.PivotVariable.DefaultProperty())); foreach (var property in this.ProjectedProperties) { WScalarExpression selectScalarExpr; if (property == GremlinKeyword.Path) { selectScalarExpr = ContextLocalPath.DefaultProjection().ToScalarExpression(); } else { selectScalarExpr = this.PivotVariable.ProjectedProperties.Contains(property) ? this.PivotVariable.GetVariableProperty(property).ToScalarExpression() : SqlUtil.GetValueExpr(null); } selectElements.Add(SqlUtil.GetSelectScalarExpr(selectScalarExpr, property)); } return(selectElements); }
internal virtual void Out(GremlinToSqlContext currentContext, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjEdge = GetVariableProperty(GremlinKeyword.EdgeAdj); GremlinVariableProperty labelProperty = GetVariableProperty(GremlinKeyword.Label); GremlinBoundEdgeTableVariable outEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjEdge, labelProperty, WEdgeType.OutEdge); currentContext.VariableList.Add(outEdgeTable); currentContext.TableReferences.Add(outEdgeTable); currentContext.AddLabelPredicateForEdge(outEdgeTable, edgeLabels); GremlinVariableProperty sinkProperty = outEdgeTable.GetVariableProperty(GremlinKeyword.EdgeSinkV); GremlinBoundVertexVariable inVertex = new GremlinBoundVertexVariable(sinkProperty); currentContext.VariableList.Add(inVertex); currentContext.TableReferences.Add(inVertex); //currentContext.PathList.Add(new GremlinMatchPath(this, outEdgeTable, inVertex)); currentContext.SetPivotVariable(inVertex); }
internal void In(GremlinVariable lastVariable, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = lastVariable.GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjReverseEdge = lastVariable.GetVariableProperty(GremlinKeyword.ReverseEdgeAdj); GremlinVariableProperty labelProperty = lastVariable.GetVariableProperty(GremlinKeyword.Label); GremlinBoundEdgeTableVariable inEdgeTable = new GremlinBoundEdgeTableVariable(sourceProperty, adjReverseEdge, labelProperty, WEdgeType.InEdge); VariableList.Add(inEdgeTable); TableReferences.Add(inEdgeTable); AddLabelPredicateForEdge(inEdgeTable, edgeLabels); GremlinVariableProperty edgeProperty = inEdgeTable.GetVariableProperty(GremlinKeyword.EdgeSourceV); GremlinBoundVertexVariable outVertex = new GremlinBoundVertexVariable(inEdgeTable.GetEdgeType(), edgeProperty); VariableList.Add(outVertex); TableReferences.Add(outVertex); AddPath(new GremlinMatchPath(outVertex, inEdgeTable, lastVariable)); SetPivotVariable(outVertex); }
internal void OtherV(GremlinVariable lastVariable) { switch (lastVariable.GetEdgeType()) { case WEdgeType.Undefined: case WEdgeType.BothEdge: GremlinVariableProperty otherProperty = lastVariable.GetVariableProperty(GremlinKeyword.EdgeOtherV); GremlinBoundVertexVariable otherVertex = new GremlinBoundVertexVariable(lastVariable.GetEdgeType(), otherProperty); VariableList.Add(otherVertex); TableReferences.Add(otherVertex); SetPivotVariable(otherVertex); break; case WEdgeType.InEdge: OutV(lastVariable); break; case WEdgeType.OutEdge: InV(lastVariable); break; } }
internal virtual void Both(GremlinToSqlContext currentContext, List <string> edgeLabels) { GremlinVariableProperty sourceProperty = GetVariableProperty(GremlinKeyword.NodeID); GremlinVariableProperty adjEdge = GetVariableProperty(GremlinKeyword.EdgeAdj); GremlinVariableProperty adjReverseEdge = GetVariableProperty(GremlinKeyword.ReverseEdgeAdj); GremlinBoundEdgeTableVariable bothEdgeTable = new GremlinBoundEdgeTableVariable( sourceProperty, adjEdge, adjReverseEdge, WEdgeType.BothEdge); currentContext.VariableList.Add(bothEdgeTable); currentContext.TableReferences.Add(bothEdgeTable); currentContext.AddLabelPredicateForEdge(bothEdgeTable, edgeLabels); GremlinVariableProperty otherProperty = bothEdgeTable.GetVariableProperty(GremlinKeyword.EdgeOtherV); GremlinBoundVertexVariable otherVertex = new GremlinBoundVertexVariable(otherProperty); currentContext.VariableList.Add(otherVertex); currentContext.TableReferences.Add(otherVertex); currentContext.SetPivotVariable(otherVertex); }
public GremlinValueVariable(GremlinVariableProperty projectVariable) { ProjectVariable = projectVariable; }
public GremlinDropEdgeVariable(GremlinVariableProperty sourceVariable, GremlinVariableProperty edgeVariable) { SourceVariable = sourceVariable; EdgeVariable = edgeVariable; }
public GremlinDropVertexVariable(GremlinVariableProperty dropVetexVariable) { DropVetexVariable = dropVetexVariable; }
public GremlinBoundVertexVariable(GremlinVariableProperty sourceVariableProperty, GremlinVariableProperty sinkVariableProperty) { SourceVariableProperty = sourceVariableProperty; SinkVariableProperty = sinkVariableProperty; }
internal virtual GremlinTableVariable CreateAdjVertex(GremlinVariableProperty propertyVariable) { return(new GremlinBoundVertexVariable(GetEdgeType(), propertyVariable)); }
internal List <WSelectElement> GetSelectElement(List <string> ProjectedProperties) { var selectElements = new List <WSelectElement>(); if ((PivotVariable is GremlinUnionVariable && HomeVariable is GremlinSideEffectVariable) || PivotVariable.GetVariableType() == GremlinVariableType.NULL) { selectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetStarColumnReferenceExpr())); return(selectElements); } if (ProjectedProperties != null && ProjectedProperties.Count != 0) { foreach (var projectProperty in ProjectedProperties) { WSelectScalarExpression selectScalarExpr; if (projectProperty == GremlinKeyword.TableDefaultColumnName) { GremlinVariableProperty defaultProjection = PivotVariable.DefaultProjection(); selectScalarExpr = SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression(), GremlinKeyword.TableDefaultColumnName); selectElements.Add(selectScalarExpr); } else if (ProjectVariablePropertiesList.All(p => p.Item2 != projectProperty)) { if (PivotVariable.ProjectedProperties.Contains(projectProperty)) { WScalarExpression columnExpr = PivotVariable.GetVariableProperty(projectProperty).ToScalarExpression(); selectScalarExpr = SqlUtil.GetSelectScalarExpr(columnExpr, projectProperty); selectElements.Add(selectScalarExpr); } else { selectScalarExpr = SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), projectProperty); selectElements.Add(selectScalarExpr); } } } } else { selectElements.Add(SqlUtil.GetSelectScalarExpr(PivotVariable.DefaultProjection().ToScalarExpression(), GremlinKeyword.TableDefaultColumnName)); } if (IsPopulateGremlinPath) { selectElements.Add(SqlUtil.GetSelectScalarExpr(CurrentContextPath.DefaultProjection().ToScalarExpression(), GremlinKeyword.Path)); } foreach (var item in ProjectVariablePropertiesList) { selectElements.Add(SqlUtil.GetSelectScalarExpr(item.Item1.ToScalarExpression(), item.Item2)); } if (selectElements.Count == 0) { if (PivotVariable is GremlinTableVariable || (PivotVariable is GremlinUnionVariable && HomeVariable is GremlinSideEffectVariable)) { selectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetStarColumnReferenceExpr())); } else if (PivotVariable.GetVariableType() == GremlinVariableType.Table) { throw new Exception("Can't process table type"); } else { GremlinVariableProperty defaultProjection = PivotVariable.DefaultProjection(); selectElements.Add(SqlUtil.GetSelectScalarExpr(defaultProjection.ToScalarExpression())); } } return(selectElements); }
public GremlinBoundVertexVariable(WEdgeType inputEdgeType, GremlinVariableProperty sourceVariableProperty, GremlinVariableProperty sinkVariableProperty) { InputEdgeType = inputEdgeType; SourceVariableProperty = sourceVariableProperty; SinkVariableProperty = sinkVariableProperty; }