diff --git a/src/Kusto.Language/Binder/Binder_ContextBuilder.cs b/src/Kusto.Language/Binder/Binder_ContextBuilder.cs index a343bb26..ff8fb745 100644 --- a/src/Kusto.Language/Binder/Binder_ContextBuilder.cs +++ b/src/Kusto.Language/Binder/Binder_ContextBuilder.cs @@ -501,7 +501,19 @@ public override void VisitGraphMatchOperator(GraphMatchOperator node) || (node.ProjectClause != null && _position >= node.ProjectClause.TextStart)) { _binder._localScope = new LocalScope(_binder._localScope); - _binder.AddGraphMatchPatternDeclarationsToLocalScope(node); + _binder.AddGraphMatchPatternDeclarationsToLocalScope(node.Patterns); + } + } + + public override void VisitGraphShortestPathsOperator(GraphShortestPathsOperator node) + { + base.VisitGraphShortestPathsOperator(node); + + if ((node.WhereClause != null && _position >= node.WhereClause.TextStart) + || (node.ProjectClause != null && _position >= node.ProjectClause.TextStart)) + { + _binder._localScope = new LocalScope(_binder._localScope); + _binder.AddGraphMatchPatternDeclarationsToLocalScope(node.Patterns); } } diff --git a/src/Kusto.Language/Binder/Binder_Misc.cs b/src/Kusto.Language/Binder/Binder_Misc.cs index 5085e5e9..3b0e22dd 100644 --- a/src/Kusto.Language/Binder/Binder_Misc.cs +++ b/src/Kusto.Language/Binder/Binder_Misc.cs @@ -574,13 +574,13 @@ private void AddStepDeclarationsToLocalScope(ScanOperator node) } } - private void BindGraphMatchPatternDeclarations(GraphMatchOperator graphMatch) + private void BindGraphMatchPatternDeclarations(SyntaxNode operatorNode, SyntaxList> patterns) { - var graphScope = GetGraphSymbol(graphMatch); + var graphScope = GetGraphSymbol(operatorNode); var edgeTuple = graphScope != null ? new TupleSymbol(graphScope.EdgeShape.Columns, graphScope.EdgeShape) : TupleSymbol.Empty; var nodeTuple = graphScope?.NodeShape != null ? new TupleSymbol(graphScope.NodeShape.Columns, graphScope.NodeShape) : TupleSymbol.Empty; - foreach (var pattern in graphMatch.Patterns) + foreach (var pattern in patterns) { foreach (var notation in pattern.Element.PatternElements) { @@ -615,9 +615,9 @@ private VariableSymbol CreateGraphMatchEdgeVariableSymbol(GraphMatchPatternEdge return new VariableSymbol(edge.Name.SimpleName, new TupleSymbol(newColumns)); } - private void AddGraphMatchPatternDeclarationsToLocalScope(GraphMatchOperator graphMatch) + private void AddGraphMatchPatternDeclarationsToLocalScope(SyntaxList> patterns) { - foreach (var pattern in graphMatch.Patterns) + foreach (var pattern in patterns) { foreach (var notation in pattern.Element.PatternElements) { diff --git a/src/Kusto.Language/Binder/Binder_NodeBinder.cs b/src/Kusto.Language/Binder/Binder_NodeBinder.cs index f7179bf1..4cda91c5 100644 --- a/src/Kusto.Language/Binder/Binder_NodeBinder.cs +++ b/src/Kusto.Language/Binder/Binder_NodeBinder.cs @@ -3911,8 +3911,20 @@ public override SemanticInfo VisitGraphMarkComponentsOperator(GraphMarkComponent _binder.CheckQueryOperatorParameters(node.Parameters, QueryOperatorParameters.GraphMarkComponentsParameters, diagnostics); } - var symbol = new GraphSymbol(this.RowScopeOrEmpty); - return new SemanticInfo(symbol, diagnostics); + // get existing graph symbol from left-side of parent pipe operator + var graphSymbol = (node.Parent as PipeExpression)?.Expression?.ResultType is GraphSymbol g + ? new GraphSymbol(g.EdgeShape, g.NodeShape) + : new GraphSymbol(this.RowScopeOrEmpty); + + // add component-id column to node shape + var componentIdName = node.Parameters.GetParameterNameValue(QueryOperatorParameters.WithComponentId) as string ?? "ComponentId"; + var componentIdColumn = new ColumnSymbol(componentIdName, ScalarTypes.Long); + var newNodeShape = graphSymbol.NodeShape != null + ? graphSymbol.NodeShape.AddColumns(componentIdColumn) + : new TableSymbol(new[] { componentIdColumn }); + graphSymbol = graphSymbol.WithNodeShape(newNodeShape); + + return new SemanticInfo(graphSymbol, diagnostics); } finally { diff --git a/src/Kusto.Language/Binder/Binder_TreeBinder.cs b/src/Kusto.Language/Binder/Binder_TreeBinder.cs index ecd640d3..a8ffea13 100644 --- a/src/Kusto.Language/Binder/Binder_TreeBinder.cs +++ b/src/Kusto.Language/Binder/Binder_TreeBinder.cs @@ -1118,8 +1118,35 @@ public override void VisitGraphMatchOperator(GraphMatchOperator node) _binder._localScope = new LocalScope(oldLocalScope); try { - _binder.BindGraphMatchPatternDeclarations(node); - _binder.AddGraphMatchPatternDeclarationsToLocalScope(node); + node.Parameters.Accept(this); + + _binder.BindGraphMatchPatternDeclarations(node, node.Patterns); + _binder.AddGraphMatchPatternDeclarationsToLocalScope(node.Patterns); + + node.WhereClause?.Accept(this); + node.ProjectClause?.Accept(this); + } + finally + { + _binder._rowScope = oldScope; + _binder._localScope = oldLocalScope; + } + + BindNode(node); + } + + public override void VisitGraphShortestPathsOperator(GraphShortestPathsOperator node) + { + var oldScope = _binder._rowScope; + var oldLocalScope = _binder._localScope; + _binder._rowScope = null; + _binder._localScope = new LocalScope(oldLocalScope); + try + { + node.Parameters.Accept(this); + + _binder.BindGraphMatchPatternDeclarations(node, node.Patterns); + _binder.AddGraphMatchPatternDeclarationsToLocalScope(node.Patterns); node.WhereClause?.Accept(this); node.ProjectClause?.Accept(this); diff --git a/src/Kusto.Language/version.txt b/src/Kusto.Language/version.txt index 393b190a..717f7999 100644 --- a/src/Kusto.Language/version.txt +++ b/src/Kusto.Language/version.txt @@ -1 +1 @@ -11.7.1 \ No newline at end of file +11.7.2 \ No newline at end of file