Example #1
0
        /// <summary>
        /// A root node of the parse tree.
        /// Jumps to the node under the root.
        /// All patterns must have at least one match node.
        /// There is always at least one pattern.
        /// </summary>
        public void Visit(MatchNode node)
        {
            result.Add(currentPattern);
            node.next.Accept(this);

            for (int i = 0; i < result.Count; i++)
            {
                if (result[i].GetCount() <= 0)
                {
                    throw new ArgumentException($"{this.GetType()}, failed to parse match expr.");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Parsing a match expression, chains of vertex -> edge -> vertex expressions.
        /// Match -> MATCH MatchTerm (, MatchTerm)*
        /// MatchTerm -> Vertex (Edge Vertex)*
        /// Vertex -> (MatchVariable)
        /// Edge -> (EmptyAnyEdge|EmptyOutEdge|EmptyInEdge|AnyEdge|InEdge|OutEdge)
        /// EmptyAnyEdge -> -
        /// EmptyOutEdge -> o-
        /// EmptyInEdge -> ->
        /// AnyEdge -> -[MatchVariable]-
        /// InEdge -> o-[MatchVariable]-
        /// OutEdge -> -[MatchVariable]->
        /// MatchVariable -> (VariableNameReference)?(:TableType)?
        /// TableType -> IDENTIFIER
        /// VariableNameReference -> IDENTIFIER
        /// </summary>
        /// <returns> A tree representation of Match expression. </returns>
        static public MatchNode ParseMatch(ref int position, List <Token> tokens)
        {
            MatchNode matchNode = new MatchNode();

            // We expect after reading Select expr that the position is set on the Match token.
            if (!CheckToken(position, Token.TokenType.Match, tokens))
            {
                ThrowError("Match parser", "Failed to find MATCH token.", position, tokens);
            }
            else
            {
                position++;
                Node node = ParseVertex(ref position, tokens);
                if (node == null)
                {
                    ThrowError("Match parser", "Failed to parse Match expression.", position, tokens);
                }
                matchNode.AddNext(node);
            }
            return(matchNode);
        }
Example #3
0
 public void Visit(MatchNode node)
 {
     throw new NotImplementedException();
 }
Example #4
0
        /// <summary>
        /// Creates Streamed Match object.
        /// </summary>
        /// <param name="graph"> Graph to conduct a query on. </param>
        /// <param name="variableMap"> Empty map of variables. </param>
        /// <param name="executionHelper"> Match execution helper. </param>
        /// <param name="matchNode"> Parse tree of match expression. </param>
        /// <param name="exprInfo"> A query expression information. </param>
        public MatchObjectStreamed(Graph graph, VariableMap variableMap, IMatchExecutionHelper executionHelper, MatchNode matchNode, QueryExpressionInfo exprInfo)
        {
            if (executionHelper == null || matchNode == null || variableMap == null || graph == null)
            {
                throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor.");
            }

            this.helper = executionHelper;
            MatchVisitor matchVisitor = new MatchVisitor(graph.nodeTables, graph.edgeTables);

            matchNode.Accept(matchVisitor);

            //Create real pattern and variableMap
            var result = matchVisitor.GetResult();

            this.CheckParsedPatternCorrectness(result);

            // Create  matcher and pattern based on the name of matcher and pattern
            // Change if necessary
            this.pattern = MatchFactory.CreatePattern(helper.ParallelPatternMatcherName, helper.PatternName, variableMap, result);
            this.matcher = (IPatternMatcherStreamed)MatchFactory.CreateMatcher(helper.ParallelPatternMatcherName, pattern, graph, executionHelper);
        }
Example #5
0
        /// <summary>
        /// Creates a Match object.
        /// </summary>
        /// <param name="graph"> A graph to conduct a query on. </param>
        /// <param name="variableMap"> An empty map of variables. </param>
        /// <param name="executionHelper"> A match execution helper. </param>
        /// <param name="matchNode"> A parse tree of match expression. </param>
        /// <param name="exprInfo"> A query expression information. </param>
        public MatchObject(Graph graph, VariableMap variableMap, IMatchExecutionHelper executionHelper, MatchNode matchNode, QueryExpressionInfo exprInfo)
        {
            if (executionHelper == null || matchNode == null || variableMap == null || graph == null)
            {
                throw new ArgumentNullException($"{this.GetType()}, passing null arguments to the constructor.");
            }

            this.helper = executionHelper;
            MatchVisitor matchVisitor = new MatchVisitor(graph.nodeTables, graph.edgeTables);

            matchNode.Accept(matchVisitor);

            // Create real pattern and variableMap.
            var result = matchVisitor.GetResult();

            this.CheckParsedPatternCorrectness(result);

            // Create  matcher and pattern based on the name of matcher and pattern.
            // Change if necessary .
            this.pattern = MatchFactory.CreatePattern(helper.ParallelPatternMatcherName, helper.PatternName, variableMap, result);

            // Now we have got enough information about results.
            // After creating pattern the variable map is filled and we know extend of the results.
            this.queryResults = new MatchFixedResults(this.helper.FixedArraySize, variableMap.GetCount(), executionHelper.ThreadCount);

            this.matcher = MatchFactory.CreateMatcher(helper.ParallelPatternMatcherName, pattern, graph, this.queryResults, executionHelper);
        }