internal static void GetPathStepListAndByFuncList( QueryCompilationContext context, GraphViewCommand command, IList <WScalarExpression> parameters, out List <Tuple <ScalarFunction, bool, HashSet <string> > > pathStepList, out List <ScalarFunction> byFuncList) { // // If the boolean value is true, then it's a subPath to be unfolded // pathStepList = new List <Tuple <ScalarFunction, bool, HashSet <string> > >(); byFuncList = new List <ScalarFunction>(); QueryCompilationContext byInitContext = new QueryCompilationContext(context); byInitContext.ClearField(); byInitContext.AddField(GremlinKeyword.Compose1TableDefaultName, GremlinKeyword.TableDefaultColumnName, ColumnGraphType.Value); foreach (WScalarExpression expression in parameters) { WFunctionCall basicStep = expression as WFunctionCall; WValueExpression stepLabel = expression as WValueExpression; WColumnReferenceExpression subPath = expression as WColumnReferenceExpression; WScalarSubquery byFunc = expression as WScalarSubquery; if (basicStep != null) { pathStepList.Add( new Tuple <ScalarFunction, bool, HashSet <string> >( basicStep.CompileToFunction(context, command), false, new HashSet <string>())); } else if (stepLabel != null) { if (!pathStepList.Any()) { pathStepList.Add(new Tuple <ScalarFunction, bool, HashSet <string> >(null, false, new HashSet <string>())); } pathStepList.Last().Item3.Add(stepLabel.Value); } else if (subPath != null) { pathStepList.Add( new Tuple <ScalarFunction, bool, HashSet <string> >( subPath.CompileToFunction(context, command), true, new HashSet <string>())); } else if (byFunc != null) { byFuncList.Add(byFunc.CompileToFunction(byInitContext, command)); } else { throw new QueryCompilationException( "The parameter of WPathTableReference can only be a WFunctionCall/WValueExpression/WColumnReferenceExpression/WScalarSubquery."); } } }
public override void Visit(WFunctionCall fcall) { switch (fcall.FunctionName.Value.ToLowerInvariant()) { case "withinarray": case "withoutarray": case "hasproperty": runtimeFunctionCount++; break; } }
private static WBooleanExpression ConstructDownSizeJoinCondition(string affectedTableAlias) { // Add disjunctive DownSize predicates into the current join condition var downSizeFunctionCall = new WFunctionCall { CallTarget = new WMultiPartIdentifierCallTarget { Identifiers = new WMultiPartIdentifier(new Identifier { Value = "dbo" }) }, FunctionName = new Identifier { Value = "DownSizeFunction" }, Parameters = new List <WScalarExpression> { new WColumnReferenceExpression { MultiPartIdentifier = new WMultiPartIdentifier { Identifiers = new List <Identifier> { new Identifier { Value = affectedTableAlias }, new Identifier { Value = "LocalNodeid" } } } } } }; return(new WBooleanParenthesisExpression { Expression = new WBooleanBinaryExpression { BooleanExpressionType = BooleanBinaryExpressionType.Or, FirstExpr = new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpr = downSizeFunctionCall, SecondExpr = new WValueExpression("1", false) }, SecondExpr = new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpr = downSizeFunctionCall, SecondExpr = new WValueExpression("2", false) } } }); }
public override void Visit(WFunctionCall fcall) { switch (fcall.FunctionName.Value.ToUpper()) { case "COUNT": case "FOLD": case "TREE": case "CAP": case "SUM": case "MAX": case "MIN": case "MEAN": aggregateFunctionCount++; break; } }
public override void Visit(WFunctionCall node) { }
public override void Visit(WFunctionCall node) { _referencedByNodeAndEdge = false; }
private WScalarExpression ParseScalarExpression(ScalarExpression scalarExpr) { if (scalarExpr == null) { return null; } switch (scalarExpr.GetType().Name) { case "BinaryExpression": { var bexpr = scalarExpr as BinaryExpression; var wexpr = new WBinaryExpression { ExpressionType = bexpr.BinaryExpressionType, FirstExpr = ParseScalarExpression(bexpr.FirstExpression), SecondExpr = ParseScalarExpression(bexpr.SecondExpression), FirstTokenIndex = bexpr.FirstTokenIndex, LastTokenIndex = bexpr.LastTokenIndex, }; return wexpr; } case "UnaryExpression": { var uexpr = scalarExpr as UnaryExpression; var wuexpr = new WUnaryExpression { Expression = ParseScalarExpression(uexpr.Expression), ExpressionType = uexpr.UnaryExpressionType, FirstTokenIndex = uexpr.FirstTokenIndex, LastTokenIndex = uexpr.LastTokenIndex }; return wuexpr; } case "ColumnReferenceExpression": { var cre = scalarExpr as ColumnReferenceExpression; var wexpr = new WColumnReferenceExpression { MultiPartIdentifier = ParseMultiPartIdentifier(cre.MultiPartIdentifier), ColumnType = cre.ColumnType, FirstTokenIndex = cre.FirstTokenIndex, LastTokenIndex = cre.LastTokenIndex }; return wexpr; } case "ScalarSubquery": { var oquery = scalarExpr as ScalarSubquery; var wexpr = new WScalarSubquery { SubQueryExpr = ParseSelectQueryStatement(oquery.QueryExpression), FirstTokenIndex = oquery.FirstTokenIndex, LastTokenIndex = oquery.LastTokenIndex }; return wexpr; } case "ParenthesisExpression": { var parenExpr = scalarExpr as ParenthesisExpression; var wexpr = new WParenthesisExpression { Expression = ParseScalarExpression(parenExpr.Expression), FirstTokenIndex = parenExpr.FirstTokenIndex, LastTokenIndex = parenExpr.LastTokenIndex, }; return wexpr; } case "FunctionCall": { var fc = scalarExpr as FunctionCall; var wexpr = new WFunctionCall { CallTarget = ParseCallTarget(fc.CallTarget), FunctionName = fc.FunctionName, UniqueRowFilter = fc.UniqueRowFilter, FirstTokenIndex = fc.FirstTokenIndex, LastTokenIndex = fc.LastTokenIndex, }; if (fc.Parameters == null) return wexpr; wexpr.Parameters = new List<WScalarExpression>(fc.Parameters.Count); foreach (var pe in fc.Parameters.Select(ParseScalarExpression).Where(pe => pe != null)) { wexpr.Parameters.Add(pe); } return wexpr; } case "SearchedCaseExpression": { var caseExpr = scalarExpr as SearchedCaseExpression; var wexpr = new WSearchedCaseExpression { FirstTokenIndex = caseExpr.FirstTokenIndex, LastTokenIndex = caseExpr.LastTokenIndex, WhenClauses = new List<WSearchedWhenClause>(caseExpr.WhenClauses.Count) }; foreach (var pwhen in caseExpr.WhenClauses.Select(swhen => new WSearchedWhenClause { WhenExpression = ParseBooleanExpression(swhen.WhenExpression), ThenExpression = ParseScalarExpression(swhen.ThenExpression), FirstTokenIndex = swhen.FirstTokenIndex, LastTokenIndex = swhen.LastTokenIndex, })) { wexpr.WhenClauses.Add(pwhen); } wexpr.ElseExpr = ParseScalarExpression(caseExpr.ElseExpression); return wexpr; } case "CastCall": { var castExpr = scalarExpr as CastCall; var wexpr = new WCastCall { DataType = ParseDataType(castExpr.DataType), Parameter = ParseScalarExpression(castExpr.Parameter), FirstTokenIndex = castExpr.FirstTokenIndex, LastTokenIndex = castExpr.LastTokenIndex, }; return wexpr; } default: { if (!(scalarExpr is ValueExpression)) return null; var wexpr = new WValueExpression { FirstTokenIndex = scalarExpr.FirstTokenIndex, LastTokenIndex = scalarExpr.LastTokenIndex, }; var expr = scalarExpr as Literal; if (expr != null) { wexpr.Value = expr.Value; if (expr.LiteralType == LiteralType.String) { wexpr.SingleQuoted = true; } } else { var reference = scalarExpr as VariableReference; wexpr.Value = reference != null ? reference.Name : ((GlobalVariableExpression)scalarExpr).Name; } return wexpr; } } }
public virtual void Visit(WFunctionCall node) { node.AcceptChildren(this); }
public override void Visit(WFunctionCall node) { throw new NotImplementedException(); }
public virtual void Visit(WFunctionCall node) { node.AcceptChildren(this); }
public override void Visit(WFunctionCall node) { }
public override WTableReference ToTableReference() { Dictionary <GremlinVariableProperty, string> map = new Dictionary <GremlinVariableProperty, string>(); Dictionary <GremlinVariableProperty, string> map2 = new Dictionary <GremlinVariableProperty, string>(); Dictionary <GremlinVariableProperty, string> map3 = new Dictionary <GremlinVariableProperty, string>(); Dictionary <GremlinVariableProperty, string> map4 = new Dictionary <GremlinVariableProperty, string>(); WRepeatConditionExpression conditionExpr = GetRepeatConditionExpression(); List <WSelectScalarExpression> inputSelectList = GetInputSelectList(ref map); List <WSelectScalarExpression> outerSelectList = GetOuterSelectList(ref map); List <WSelectScalarExpression> terminateSelectList = GetConditionSelectList(ref map2); List <WSelectScalarExpression> repeatPathOuterList = GetRepeatPathOuterVariableList(ref map3); List <WSelectScalarExpression> conditionPathOuterList = GetConditionPathOuterVariableList(ref map4); WSelectQueryBlock selectQueryBlock = RepeatContext.ToSelectQueryBlock(); selectQueryBlock.SelectElements.Clear(); foreach (var selectElement in inputSelectList) { selectQueryBlock.SelectElements.Add(selectElement); } foreach (var selectElement in outerSelectList) { selectQueryBlock.SelectElements.Add(selectElement); } foreach (var selectElement in terminateSelectList) { selectQueryBlock.SelectElements.Add(selectElement); } foreach (var selectElement in repeatPathOuterList) { selectQueryBlock.SelectElements.Add(selectElement); } foreach (var selectElement in conditionPathOuterList) { selectQueryBlock.SelectElements.Add(selectElement); } WSelectQueryBlock firstQueryExpr = new WSelectQueryBlock(); foreach (var item in map) { firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(item.Key.ToScalarExpression(), item.Value)); } foreach (var item in map2) { firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), item.Value)); } foreach (var item in map3) { firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(item.Key.ToScalarExpression(), item.Value)); } foreach (var item in map4) { firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(item.Key.ToScalarExpression(), item.Value)); } //firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(FirstVariable.DefaultProjection().ToScalarExpression(), GremlinKeyword.TableDefaultColumnName)); //selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr(RepeatContext.PivotVariable.DefaultProjection().ToScalarExpression(), GremlinKeyword.TableDefaultColumnName)); foreach (var property in ProjectedProperties) { if (InputVariable.ProjectedProperties.Contains(property)) { firstQueryExpr.SelectElements.Add( SqlUtil.GetSelectScalarExpr( InputVariable.GetVariableProperty(property).ToScalarExpression(), property)); } else { firstQueryExpr.SelectElements.Add( SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property)); } if (RepeatContext.PivotVariable.ProjectedProperties.Contains(property)) { selectQueryBlock.SelectElements.Add( SqlUtil.GetSelectScalarExpr( RepeatContext.PivotVariable.GetVariableProperty(property).ToScalarExpression(), property)); } else { selectQueryBlock.SelectElements.Add( SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), property)); } } if (SelectedVariableList.Count != 0) { foreach (var selectedVariableTuple in SelectedVariableList) { var columnName = selectedVariableTuple.Item1; var selectedVariable = selectedVariableTuple.Item2; firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), columnName)); List <WScalarExpression> compose2Paramters = new List <WScalarExpression>(); compose2Paramters.Add(selectedVariable.RealVariable.ToCompose1()); compose2Paramters.Add(SqlUtil.GetColumnReferenceExpr("R", columnName)); WFunctionCall compose2 = SqlUtil.GetFunctionCall(GremlinKeyword.func.Compose2, compose2Paramters); selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr(compose2, columnName)); } } if (RepeatContext.IsPopulateGremlinPath) { var columnName = GremlinKeyword.Path; var pathVariable = RepeatContext.CurrentContextPath; firstQueryExpr.SelectElements.Add(SqlUtil.GetSelectScalarExpr(SqlUtil.GetValueExpr(null), columnName)); selectQueryBlock.SelectElements.Add(SqlUtil.GetSelectScalarExpr(pathVariable.DefaultProjection().ToScalarExpression(), columnName)); } var WBinaryQueryExpression = SqlUtil.GetBinaryQueryExpr(firstQueryExpr, selectQueryBlock); ModifyColumnNameVisitor newVisitor = new ModifyColumnNameVisitor(); newVisitor.Invoke(selectQueryBlock, map); newVisitor.Invoke(conditionExpr, map2); newVisitor.Invoke(selectQueryBlock, map3); newVisitor.Invoke(conditionExpr, map4); List <WScalarExpression> repeatParameters = new List <WScalarExpression>(); repeatParameters.Add(SqlUtil.GetScalarSubquery(WBinaryQueryExpression)); repeatParameters.Add(conditionExpr); var secondTableRef = SqlUtil.GetFunctionTableReference(GremlinKeyword.func.Repeat, repeatParameters, this, GetVariableName()); return(SqlUtil.GetCrossApplyTableReference(null, secondTableRef)); }
public override void Visit(WFunctionCall node) { _referencedByNodeAndEdge = false; }
//public MatchComponent(MatchNode node, List<MatchEdge> populatedEdges,GraphMetaData metaData) : this(node) //{ // foreach (var edge in populatedEdges) // { // TableRef = SpanTableRef(TableRef, edge, node.RefAlias, metaData); // EdgeMaterilizedDict[edge] = true; // SinkNodeStatisticsDict[edge.SinkNode] = edge.Statistics; // var edgeList = UnmaterializedNodeMapping.GetOrCreate(edge.SinkNode); // edgeList.Add(edge); // if (!Nodes.Contains(edge.SinkNode)) // Nodes.Add(edge.SinkNode); // Cardinality *= edge.AverageDegree; // SqlEstimatedSize *= 1000; // } //} private static WBooleanExpression ConstructDownSizeJoinCondition(string affectedTableAlias) { // Add disjunctive DownSize predicates into the current join condition var downSizeFunctionCall = new WFunctionCall { CallTarget = new WMultiPartIdentifierCallTarget { Identifiers = new WMultiPartIdentifier(new Identifier { Value = "dbo" }) }, FunctionName = new Identifier { Value = "DownSizeFunction" }, Parameters = new List<WScalarExpression> { new WColumnReferenceExpression { MultiPartIdentifier = new WMultiPartIdentifier { Identifiers = new List<Identifier> { new Identifier {Value = affectedTableAlias}, new Identifier {Value = "LocalNodeid"} } } } } }; return new WBooleanParenthesisExpression { Expression = new WBooleanBinaryExpression { BooleanExpressionType = BooleanBinaryExpressionType.Or, FirstExpr = new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpr = downSizeFunctionCall, SecondExpr = new WValueExpression("1", false) }, SecondExpr = new WBooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpr = downSizeFunctionCall, SecondExpr = new WValueExpression("2", false) } } }; }