public static GremlinUnionVariable Create(List <GremlinToSqlContext> unionContextList) { if (unionContextList.Count == 0) { return(new GremlinUnionNullVariable(unionContextList)); } if (GremlinUtil.IsTheSameOutputType(unionContextList)) { switch (unionContextList.First().PivotVariable.GetVariableType()) { case GremlinVariableType.Vertex: return(new GremlinUnionVertexVariable(unionContextList)); case GremlinVariableType.Edge: return(new GremlinUnionEdgeVariable(unionContextList)); case GremlinVariableType.Scalar: return(new GremlinUnionScalarVariable(unionContextList)); case GremlinVariableType.NULL: return(new GremlinUnionNullVariable(unionContextList)); case GremlinVariableType.Property: return(new GremlinUnionPropertyVariable(unionContextList)); } } return(new GremlinUnionTableVariable(unionContextList)); }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); if (inputContext.PivotVariable != null) { throw new QueryCompilationException("This step only can be a start step."); } GremlinFreeVertexVariable newVariable = new GremlinFreeVertexVariable(); inputContext.VariableList.Add(newVariable); inputContext.TableReferences.Add(newVariable); inputContext.SetPivotVariable(newVariable); inputContext.PivotVariable.OutE(inputContext, new List <string>()); if (EdgeIdsOrElements.Count > 0) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var id in EdgeIdsOrElements) { if (GremlinUtil.IsNumber(id) || id is string) { WScalarExpression firstExpr = inputContext.PivotVariable.GetVariableProperty(GremlinKeyword.EdgeID).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(id); WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr); booleanExprList.Add(booleanExpr); } } inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); } return(inputContext); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); bool isList = false; if (GremlinUtil.IsList(ConstantValue) || GremlinUtil.IsArray(ConstantValue)) { isList = true; //1 It's a list foreach (var value in (IEnumerable)ConstantValue) { parameters.Add(SqlUtil.GetValueExpr(value)); } } else if (GremlinUtil.IsNumber(ConstantValue) || ConstantValue is string || ConstantValue is bool) { parameters.Add(SqlUtil.GetValueExpr(ConstantValue)); } else { throw new ArgumentException(); } var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Constant, parameters, GetVariableName()); ((WConstantReference)tableRef).IsList = isList; return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
internal override GremlinVariableType GetVariableType() { if (GremlinUtil.IsTheSameType(GremlinVariableList)) { return(GremlinVariableList.First().GetVariableType()); } return(GremlinVariableType.Table); }
public static bool CheckIsTheSameType(List <List <GremlinVariable> > brachVariableList) { List <GremlinVariable> checkList = new List <GremlinVariable>(); foreach (var branchVariable in brachVariableList) { checkList.Add(branchVariable.First()); } return(GremlinUtil.IsTheSameType(checkList)); }
public GraphTraversal2 Inject(params object[] injections) { foreach (var injection in injections) { if (GremlinUtil.IsInjectable(injection)) { this.AddOperator(new GremlinInjectOp(injection)); } } return(this); }
internal static bool IsInjectable(object injection) { if (GremlinUtil.IsList(injection) || GremlinUtil.IsArray(injection) || GremlinUtil.IsNumber(injection) || injection is string || injection is bool) { return(true); } else { throw new ArgumentException(); } }
public GraphTraversal2 Constant(object value) { if (GremlinUtil.IsList(value) || GremlinUtil.IsArray(value) || GremlinUtil.IsNumber(value) || value is string || value is bool) { this.AddOperator(new GremlinConstantOp(value)); } else { throw new ArgumentException(); } return(this); }
internal override void Populate(string property) { RealVariable.Populate(property); if (ProjectedProperties.Contains(property)) { return; } switch (GetVariableType()) { case GremlinVariableType.Vertex: if (GremlinUtil.IsEdgeProperty(property)) { return; } break; case GremlinVariableType.Edge: if (GremlinUtil.IsVertexProperty(property)) { return; } break; case GremlinVariableType.Scalar: if (property != GremlinKeyword.ScalarValue) { return; } break; case GremlinVariableType.Property: if (property != GremlinKeyword.PropertyValue) { return; } break; } base.Populate(property); if (!PropertiesMap.ContainsKey(property)) { string columnName = SelectKey + "_" + property; RealVariable.BottomUpPopulate(AttachedVariable, property, columnName); PropertiesMap[property] = columnName; } }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); GremlinTableVariable newVariable; if (inputContext.PivotVariable == null || inputContext.PivotVariable is GremlinFreeVertexVariable || inputContext.PivotVariable is GremlinContextVariable) { newVariable = new GremlinFreeVertexVariable(); } else { newVariable = new GremlinBoundVertexVariable(); } if (VertexIdsOrElements.Count > 0) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var id in VertexIdsOrElements) { if (GremlinUtil.IsNumber(id) || id is string) { WScalarExpression firstExpr = newVariable.GetVariableProperty(GremlinKeyword.NodeID).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(id); WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr); booleanExprList.Add(booleanExpr); } else { throw new ArgumentException(); } } inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); } inputContext.VariableList.Add(newVariable); inputContext.TableReferencesInFromClause.Add(newVariable); inputContext.SetPivotVariable(newVariable); return(inputContext); }
private WBooleanExpression CreateBooleanExpression(GremlinVariableProperty variableProperty, object valuesOrPredicate) { if (valuesOrPredicate is string || GremlinUtil.IsNumber(valuesOrPredicate) || valuesOrPredicate is bool) { WScalarExpression firstExpr = variableProperty.ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(valuesOrPredicate); return(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); } var predicate = valuesOrPredicate as Predicate; if (predicate != null) { WScalarExpression firstExpr = variableProperty.ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); return(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate)); } throw new ArgumentException(); }
public static GremlinCoalesceVariable Create(List <GremlinToSqlContext> coalesceContextList) { if (GremlinUtil.IsTheSameOutputType(coalesceContextList)) { switch (coalesceContextList.First().PivotVariable.GetVariableType()) { case GremlinVariableType.Vertex: return(new GremlinCoalesceVertexVariable(coalesceContextList)); case GremlinVariableType.Edge: return(new GremlinCoalesceEdgeVariable(coalesceContextList)); case GremlinVariableType.Scalar: return(new GremlinCoalesceScalarVariable(coalesceContextList)); case GremlinVariableType.Property: return(new GremlinCoalescePropertyVariable(coalesceContextList)); } } return(new GremlinCoalesceTableVariable(coalesceContextList)); }
internal override bool Populate(string property, string label = null) { if (property == null && label == null) { return(true); } switch (this.GetVariableType()) { case GremlinVariableType.Vertex: if (GremlinUtil.IsEdgeProperty(property)) { return(false); } break; case GremlinVariableType.Edge: if (GremlinUtil.IsVertexProperty(property)) { return(false); } break; case GremlinVariableType.VertexProperty: if (GremlinUtil.IsVertexProperty(property) || GremlinUtil.IsEdgeProperty(property)) { return(false); } break; case GremlinVariableType.VertexAndEdge: case GremlinVariableType.Mixed: case GremlinVariableType.Unknown: case GremlinVariableType.NULL: break; default: return(false); } return(base.Populate(property, label)); }
internal override void Populate(string property) { if (ProjectedProperties.Contains(property)) { return; } switch (GetVariableType()) { case GremlinVariableType.Vertex: if (GremlinUtil.IsEdgeProperty(property)) { return; } break; case GremlinVariableType.Edge: if (GremlinUtil.IsVertexProperty(property)) { return; } break; case GremlinVariableType.VertexProperty: if (GremlinUtil.IsVertexProperty(property) || GremlinUtil.IsEdgeProperty(property)) { return; } break; case GremlinVariableType.Scalar: case GremlinVariableType.Property: if (property != GremlinKeyword.TableDefaultColumnName) { return; } break; } base.Populate(property); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); if (InputVariable == null) { //g.Inject() parameters.Add(SqlUtil.GetValueExpr(null)); } else { parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression()); } bool isList = false; if (GremlinUtil.IsList(Injection) || GremlinUtil.IsArray(Injection)) { isList = true; //1 It's a list foreach (var value in (IEnumerable)Injection) { parameters.Add(SqlUtil.GetValueExpr(value)); } } else if (GremlinUtil.IsNumber(Injection) || Injection is string || Injection is bool) { parameters.Add(SqlUtil.GetValueExpr(Injection)); } else { throw new ArgumentException(); } var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Inject, parameters, GetVariableName()); ((WInjectTableReference)tableRef).IsList = isList; return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public GraphTraversal2 Option(object pickToken, GraphTraversal2 traversalOption) { if (!(GremlinUtil.IsNumber(pickToken) || pickToken is string || pickToken is GremlinKeyword.Pick || pickToken is bool)) { throw new ArgumentException(); } var op = GetEndOp() as GremlinChooseOp; if (op != null) { if (op.Options.ContainsKey(pickToken)) { throw new SyntaxErrorException( $"Choose step can only have one traversal per pick token: {pickToken}"); } op.Options[pickToken] = traversalOption; return(this); } else { throw new Exception("Option step only can follow by choose step."); } }
public GraphTraversal2 HasValue(params object[] valuesOrPredicates) { GremlinUtil.CheckIsValueOrPredicate(valuesOrPredicates); this.AddOperator(new GremlinHasOp(GremlinHasType.HasValue, valuesOrPredicates)); return(this); }
protected GremlinTableVariable(GremlinVariableType variableType) { VariableType = variableType; VariableName = GremlinUtil.GenerateTableAlias(VariableType); }
protected GremlinTableVariable(GremlinVariableType variableType) : base(variableType) { this.VariableName = GremlinUtil.GenerateTableAlias(this.VariableType); }
public void SetVariableTypeAndGenerateName(GremlinVariableType variableType) { VariableType = variableType; _variableName = GremlinUtil.GenerateTableAlias(VariableType); }
internal virtual void Coalesce(GremlinToSqlContext currentContext, List <GremlinToSqlContext> coalesceContextList) { GremlinCoalesceVariable newVariable = new GremlinCoalesceVariable(coalesceContextList, GremlinUtil.GetContextListType(coalesceContextList)); currentContext.VariableList.Add(newVariable); currentContext.TableReferences.Add(newVariable); currentContext.SetPivotVariable(newVariable); }
internal virtual void Union(ref GremlinToSqlContext currentContext, List <GremlinToSqlContext> unionContexts) { GremlinUnionVariable newVariable = new GremlinUnionVariable(unionContexts, GremlinUtil.GetContextListType(unionContexts)); foreach (var unionContext in unionContexts) { unionContext.HomeVariable = newVariable; } currentContext.VariableList.Add(newVariable); currentContext.TableReferences.Add(newVariable); currentContext.SetPivotVariable(newVariable); }
public GremlinTableVariable(GremlinVariableType variableType) { VariableType = variableType; variableName = GremlinUtil.GenerateTableAlias(VariableType); }
public GraphTraversal2 Has(string label, string propertyKey, object predicateOrValue) { GremlinUtil.CheckIsValueOrPredicate(predicateOrValue); this.AddOperator(new GremlinHasOp(label, propertyKey, predicateOrValue)); return(this); }