internal void HasId(GremlinVariable lastVariable, Predicate predicate) { WScalarExpression firstExpr = lastVariable.GetVariableProperty(lastVariable.GetPrimaryKey()).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); AddPredicate(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, BooleanComparisonType.Equals)); }
internal void Has(GremlinVariable lastVariable, string propertyKey, Predicate predicate) { WScalarExpression firstExpr = lastVariable.GetVariableProperty(propertyKey).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); AddPredicate(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); foreach (GremlinToSqlContext context in this.CoalesceContextList) { WSelectQueryBlock selectQueryBlock = context.ToSelectQueryBlock(); Dictionary <string, WSelectElement> projectionMap = new Dictionary <string, WSelectElement>(); WSelectElement value = selectQueryBlock.SelectElements[0]; foreach (WSelectElement selectElement in selectQueryBlock.SelectElements) { projectionMap[(selectElement as WSelectScalarExpression).ColumnName] = selectElement; } selectQueryBlock.SelectElements.Clear(); selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr((value as WSelectScalarExpression).SelectExpr, this.DefaultProperty())); foreach (string property in this.ProjectedProperties) { selectQueryBlock.SelectElements.Add( projectionMap.TryGetValue(property, out value) ? value : SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property)); } parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock)); } var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Coalesce, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); if (SourceVariableProperty != null) { parameters.Add(SourceVariableProperty.ToScalarExpression()); } if (SinkVariableProperty != null) { parameters.Add(SinkVariableProperty.ToScalarExpression()); } foreach (var property in ProjectedProperties) { parameters.Add(SqlUtil.GetValueExpr(property)); } WTableReference tableRef = null; if (SourceVariableProperty != null && SinkVariableProperty != null) { //BothV tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.BothV, parameters, GetVariableName()); } else { tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.EtoV, parameters, GetVariableName()); } return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
internal override GremlinToSqlContext GetContext() { GremlinToSqlContext inputContext = GetInputContext(); GremlinFreeVertexVariable newVariable = new GremlinFreeVertexVariable(); if (VertexIdsOrElements.Count > 0) { List <WBooleanExpression> booleanExprList = new List <WBooleanExpression>(); foreach (var id in VertexIdsOrElements) { if (id is int || id is string) { WScalarExpression firstExpr = newVariable.GetVariableProperty(GremlinKeyword.NodeID).ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(id); WBooleanComparisonExpression booleanExpr = SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr); booleanExprList.Add(booleanExpr); } } inputContext.AddPredicate(SqlUtil.ConcatBooleanExprWithOr(booleanExprList)); } inputContext.VariableList.Add(newVariable); inputContext.TableReferences.Add(newVariable); inputContext.SetPivotVariable(newVariable); return(inputContext); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetScalarSubquery(GetSelectQueryBlock(this.FromVertexContext))); parameters.Add(SqlUtil.GetScalarSubquery(GetSelectQueryBlock(this.ToVertexContext))); if (this.ToVertexContext == null && this.FromVertexContext != null) { this.OtherVIndex = 0; } if (this.ToVertexContext != null && this.FromVertexContext == null) { this.OtherVIndex = 1; } if (this.ToVertexContext != null && this.FromVertexContext != null) { this.OtherVIndex = 1; } parameters.Add(SqlUtil.GetValueExpr(this.OtherVIndex)); parameters.Add(SqlUtil.GetValueExpr(this.EdgeLabel)); parameters.AddRange(this.EdgeProperties.Select(property => property.ToPropertyExpr())); var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.AddE, parameters, GetVariableName()); var crossApplyTableRef = SqlUtil.GetCrossApplyTableReference(secondTableRef); crossApplyTableRef.FirstTableRef = this.IsFirstTableReference ? SqlUtil.GetDerivedTable(SqlUtil.GetSimpleSelectQueryBlock("1"), "_") : null; return(SqlUtil.GetCrossApplyTableReference(crossApplyTableRef)); }
internal virtual void Is(GremlinToSqlContext currentContext, Predicate predicate) { WScalarExpression firstExpr = GetDefaultProjection().ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); currentContext.AddPredicate(SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate)); }
public override WTableReference ToTableReference() { WSelectQueryBlock queryBlock = this.SubqueryContext.ToSelectQueryBlock(); queryBlock.SelectElements.Clear(); List <WValueExpression> columnListExpr = new List <WValueExpression>(); columnListExpr.Add(SqlUtil.GetValueExpr(this.SubqueryContext.PivotVariable.DefaultProperty())); columnListExpr.AddRange(this.ProjectedProperties.Select(SqlUtil.GetValueExpr)); List <WScalarExpression> capParameters = new List <WScalarExpression>(); foreach (var sideEffectKey in SideEffectKeys) { capParameters.Add(new WColumnNameList(columnListExpr)); capParameters.Add(SqlUtil.GetValueExpr(sideEffectKey)); } queryBlock.SelectElements.Add( SqlUtil.GetSelectScalarExpr(SqlUtil.GetFunctionCall(GremlinKeyword.func.Cap, capParameters), GremlinKeyword.TableDefaultColumnName)); return(SqlUtil.GetDerivedTable(queryBlock, GetVariableName())); }
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>(); if (ConstantValue is List <object> ) { foreach (var value in ConstantValue as List <object> ) { parameters.Add(SqlUtil.GetValueExpr(value)); } } else if (ConstantValue is List <string> ) { foreach (var value in ConstantValue as List <string> ) { parameters.Add(SqlUtil.GetValueExpr(value)); } } else { parameters.Add(SqlUtil.GetValueExpr(ConstantValue)); } var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Constant, parameters, this, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef)); }
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)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); WTableReference tableReference; if (PredicateContext != null) { parameters.Add(SqlUtil.GetScalarSubquery(PredicateContext.ToSelectQueryBlock())); parameters.Add(SqlUtil.GetScalarSubquery(TrueChoiceContext.ToSelectQueryBlock())); parameters.Add(SqlUtil.GetScalarSubquery(FalseChocieContext.ToSelectQueryBlock())); tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Choose, parameters, GetVariableName()); } else { parameters.Add(SqlUtil.GetScalarSubquery(ChoiceContext.ToSelectQueryBlock())); foreach (var option in Options) { if (option.Key is GremlinKeyword.Pick && (GremlinKeyword.Pick)option.Key == GremlinKeyword.Pick.None) { parameters.Add(SqlUtil.GetValueExpr(null)); } else { parameters.Add(SqlUtil.GetValueExpr(option.Key)); } parameters.Add(SqlUtil.GetScalarSubquery(option.Value.ToSelectQueryBlock())); } tableReference = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.ChooseWithOptions, parameters, GetVariableName()); } return(SqlUtil.GetCrossApplyTableReference(tableReference)); }
internal virtual void Is(GremlinToSqlContext currentContext, object value) { WScalarExpression firstExpr = DefaultVariableProperty().ToScalarExpression(); WScalarExpression secondExpr = SqlUtil.GetValueExpr(value); currentContext.AddPredicate(SqlUtil.GetEqualBooleanComparisonExpr(firstExpr, secondExpr)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); bool isFetchAll = false; if (PropertyKeys.Count == 0) { parameters.Add(InputVariable.DefaultProjection().ToScalarExpression()); isFetchAll = true; } else { foreach (var property in PropertyKeys) { parameters.Add(InputVariable.GetVariableProperty(property).ToScalarExpression()); } } foreach (var projectProperty in ProjectedProperties) { if (projectProperty == GremlinKeyword.TableDefaultColumnName) { continue; } parameters.Add(SqlUtil.GetValueExpr(projectProperty)); } var tableRef = SqlUtil.GetFunctionTableReference(isFetchAll ? GremlinKeyword.func.AllProperties : GremlinKeyword.func.Properties, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
internal void Has(GremlinVariable lastVariable, string propertyKey) { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(lastVariable.DefaultProjection().ToScalarExpression()); parameters.Add(SqlUtil.GetValueExpr(propertyKey)); AddPredicate(SqlUtil.GetFunctionBooleanExpression("hasProperty", parameters)); }
internal virtual void Is(GremlinToSqlContext currentContext, Predicate predicate) { WScalarExpression secondExpr = SqlUtil.GetValueExpr(predicate.Value); var firstExpr = DefaultVariableProperty().ToScalarExpression(); var booleanExpr = SqlUtil.GetBooleanComparisonExpr(firstExpr, secondExpr, predicate); currentContext.AddPredicate(booleanExpr); }
public override WTableReference ToTableReference() { WSelectQueryBlock firstQueryExpr = new WSelectQueryBlock(); foreach (var projectProperty in ProjectedProperties) { if (projectProperty == GremlinKeyword.TableDefaultColumnName) { firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(InputVariable.GetDefaultProjection().ToScalarExpression(), GremlinKeyword.TableDefaultColumnName)); } else if (InputVariable.ProjectedProperties.Contains(projectProperty)) { firstQueryExpr.SelectElements.Add( SqlUtil.GetSelectScalarExpr( InputVariable.GetVariableProperty(projectProperty).ToScalarExpression(), projectProperty)); } else { firstQueryExpr.SelectElements.Add( SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), projectProperty)); } } WSelectQueryBlock secondQueryExpr = OptionalContext.ToSelectQueryBlock(); bool HasAggregateFunctionAsChildren = false; foreach (var variable in OptionalContext.TableReferences) { if (variable is GremlinFoldVariable || variable is GremlinCountVariable || variable is GremlinMinVariable || variable is GremlinMaxVariable || variable is GremlinSumVariable || variable is GremlinMeanVariable || variable is GremlinTreeVariable) { HasAggregateFunctionAsChildren = true; } var group = variable as GremlinGroupVariable; if (group != null && group.SideEffectKey == null) { HasAggregateFunctionAsChildren = true; } } var WBinaryQueryExpression = SqlUtil.GetBinaryQueryExpr(firstQueryExpr, secondQueryExpr); List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetScalarSubquery(WBinaryQueryExpression)); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Optional, parameters, GetVariableName()); ((WOptionalTableReference)tableRef).HasAggregateFunctionAsChildren = HasAggregateFunctionAsChildren; return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
internal WScalarExpression ReplaceContextToScalerExpr(object value) { if (value is GremlinToSqlContext) { GremlinToSqlContext valueContext = value as GremlinToSqlContext; return(SqlUtil.GetScalarSubquery(valueContext.ToSelectQueryBlock())); } return(SqlUtil.GetValueExpr(value)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetValueExpr(this.Probability)); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Coin, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetValueExpr(SideEffectKey)); parameters.Add(PathVariable.GetDefaultProjection().ToScalarExpression()); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Tree, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression()); parameters.Add(SqlUtil.GetValueExpr(Column == GremlinKeyword.Column.Keys ? "Keys" : "Values")); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.SelectColumn, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(this.InputVariable.DefaultProjection().ToScalarExpression()); parameters.Add(SqlUtil.GetValueExpr(this.IsIncludeTokens ? 1: -1)); parameters.AddRange(this.PropertyKeys.Select(SqlUtil.GetValueExpr)); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.ValueMap, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); WSelectQueryBlock selectQueryBlock = ProjectContext.ToSelectQueryBlock(true); parameters.Add(SqlUtil.GetScalarSubquery(selectQueryBlock)); parameters.Add(SqlUtil.GetValueExpr(SideEffectKey)); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Store, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetValueExpr(this.VertexLabel)); parameters.AddRange(this.VertexProperties.Select(property => property.ToPropertyExpr())); var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.AddV, parameters, GetVariableName()); var crossApplyTableRef = SqlUtil.GetCrossApplyTableReference(secondTableRef); crossApplyTableRef.FirstTableRef = this.IsFirstTableReference ? SqlUtil.GetDerivedTable(SqlUtil.GetSimpleSelectQueryBlock("1"), "_") : null; return(crossApplyTableRef); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetValueExpr(SideEffectKey)); parameters.Add(SqlUtil.GetScalarSubquery(GroupByContext.ToSelectQueryBlock())); parameters.Add(SqlUtil.GetScalarSubquery(ProjectByContext.ToSelectQueryBlock())); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Group, parameters, GetVariableName()); ((WGroupTableReference)tableRef).IsProjectingACollection = IsProjectingACollection; return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); List <WSelectQueryBlock> queryBlocks = new List <WSelectQueryBlock>(); //Must toSelectQueryBlock before toCompose1 of variableList in order to populate needed columns foreach (var byContext in ByContexts) { queryBlocks.Add(byContext.ToSelectQueryBlock(true)); } parameters.Add(InputVariable.GetDefaultProjection().ToScalarExpression()); parameters.Add(PathVariable.GetDefaultProjection().ToScalarExpression()); switch (Pop) { case GremlinKeyword.Pop.All: parameters.Add(SqlUtil.GetValueExpr("All")); break; case GremlinKeyword.Pop.First: parameters.Add(SqlUtil.GetValueExpr("First")); break; case GremlinKeyword.Pop.Last: parameters.Add(SqlUtil.GetValueExpr("Last")); break; } foreach (var selectKey in SelectKeys) { parameters.Add(SqlUtil.GetValueExpr(selectKey)); } foreach (var block in queryBlocks) { parameters.Add(SqlUtil.GetScalarSubquery(block)); } if (SelectKeys.Count == 1) { foreach (var projectProperty in ProjectedProperties) { parameters.Add(SqlUtil.GetValueExpr(projectProperty)); } } var tableRef = SqlUtil.GetFunctionTableReference( SelectKeys.Count == 1 ? GremlinKeyword.func.SelectOne: GremlinKeyword.func.Select, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(InputVaribale.DefaultProjection().ToScalarExpression()); parameters.Add(SqlUtil.GetValueExpr(Low)); parameters.Add(SqlUtil.GetValueExpr(High)); parameters.Add(IsLocal ? SqlUtil.GetValueExpr(1) : SqlUtil.GetValueExpr(-1)); parameters.Add(IsReverse ? SqlUtil.GetValueExpr(1): SqlUtil.GetValueExpr(-1)); var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Range, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); for (var i = 0; i < ProjectKeys.Count; i++) { parameters.Add(SqlUtil.GetScalarSubquery(ProjectContextList[i % ProjectContextList.Count].ToSelectQueryBlock())); parameters.Add(SqlUtil.GetValueExpr(ProjectKeys[i])); } var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Project, parameters, this, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(SqlUtil.GetColumnReferenceExpr(GremlinKeyword.Compose1TableDefaultName, GremlinKeyword.TableDefaultColumnName)); foreach (var projectProperty in ProjectedProperties) { parameters.Add(SqlUtil.GetValueExpr(projectProperty)); } var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Decompose1, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }
public override WTableReference ToTableReference() { List <WScalarExpression> parameters = new List <WScalarExpression>(); parameters.Add(InputVariable.DefaultProjection().ToScalarExpression()); foreach (var propertyKey in PropertyKeys) { parameters.Add(SqlUtil.GetValueExpr(propertyKey)); } var tableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.PropertyMap, parameters, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(tableRef)); }