When a table in the FROM clause is not given an alias, this table will be assigned its table name as its alias, and all references with schema name corresponding to this table should be replaced with the assigned alias by removing the schema name since it is invalid to have a schema identifier before an alias.
Inheritance: WSqlFragmentVisitor
コード例 #1
0
        /// <summary>
        /// Update FROM clause, adds DOWNSIZE predicates in the corresponding join conditions,
        /// and add corresponding predicates on the spilt nodes in the WHERE clause using 
        /// optimal component of each connected sub-graph.
        /// </summary>
        /// <param name="node">The SELECT statement</param>
        /// <param name="components">The optimal components of each fully-connected graph</param>
        private void UpdateQuery(WSelectQueryBlock node, List<MatchComponent> components)
        {
            // Removes schema name in SELECT clause and all column references.
            var removeSchemaVisitor = new RemoveSchemanameInIdentifersVisitor();
            removeSchemaVisitor.Visit(node);

            foreach (var component in components)
            {
                //// Cross apply the unmaterilized edges which point to the optimized tail nodes
                //Dictionary<MatchNode, MatchEdge> UnMatEdgeJoinDict = new Dictionary<MatchNode, MatchEdge>();
                //foreach (var unMatEdge in component.EdgeMaterilizedDict.Where(e => !e.Value).Select(e => e.Key))
                //{
                //    component.TableRef = component.SpanTableRef(component.TableRef,
                //        unMatEdge, component.GetNodeRefName(unMatEdge.SourceNode), _graphMetaData);
                //    MatchEdge joinEdge;
                //    if (UnMatEdgeJoinDict.TryGetValue(unMatEdge.SinkNode, out joinEdge))
                //    {
                //        if (!string.IsNullOrEmpty(newWhereString))
                //            newWhereString += " AND ";
                //        newWhereString += string.Format("{0}.Sink = {1}.Sink", joinEdge.EdgeAlias, unMatEdge.EdgeAlias);
                //    }
                //    else
                //    {
                //        UnMatEdgeJoinDict[unMatEdge.SinkNode] = unMatEdge;
                //    }
                //}

                // Updates from clause
                node.FromClause.TableReferences.Add(component.TableRef);
            }

            WBooleanExpression attachWhereCondition = null;
            foreach (var component in components)
            {
                attachWhereCondition = WBooleanBinaryExpression.Conjunction(attachWhereCondition,
                    component.WhereCondition);
            }

            if (attachWhereCondition != null)
            {
                if (node.WhereClause != null && node.WhereClause.SearchCondition != null)
                    node.WhereClause.SearchCondition = new WBooleanParenthesisExpression
                    {
                        Expression = node.WhereClause.SearchCondition
                    };
                else
                {
                    node.WhereClause = new WWhereClause();
                }
                node.WhereClause.SearchCondition = WBooleanBinaryExpression.Conjunction(attachWhereCondition,
                    node.WhereClause.SearchCondition);
            }
        }
コード例 #2
0
        /// <summary>
        /// Update FROM clause, adds DOWNSIZE predicates in the corresponding join conditions,
        /// and add corresponding predicates on the spilt nodes in the WHERE clause using 
        /// optimal component of each connected sub-graph.
        /// </summary>
        /// <param name="node">The SELECT statement</param>
        /// <param name="components">The optimal components of each fully-connected graph</param>
        private void UpdateQuery(WSelectQueryBlock node, List<MatchComponent> components)
        {
            // Removes schema name in SELECT clause and all column references.
            var removeSchemaVisitor = new RemoveSchemanameInIdentifersVisitor();
            removeSchemaVisitor.Visit(node);

            string newWhereString = "";
            foreach (var component in components)
            {
                // Adds predicates for split nodes
                var component1 = component;
                foreach (
                    var compNode in
                        component.MaterializedNodeSplitCount.Where(
                            e => e.Value > 0 && e.Key.Predicates != null && e.Key.Predicates.Any()))
                {
                    var matchNode = compNode.Key;

                    WBooleanExpression newExpression =
                        matchNode.Predicates.Aggregate<WBooleanExpression, WBooleanExpression>(null,
                            WBooleanBinaryExpression.Conjunction);
                    string predicateString = newExpression.ToString();
                    var nodeCount = component1.MaterializedNodeSplitCount[matchNode];

                    while (nodeCount > 0)
                    {
                        newWhereString += " AND ";
                        string tempStr = predicateString.Replace(string.Format("[{0}]", matchNode.RefAlias.ToUpper()),
                            string.Format("[{0}_{1}]", matchNode.RefAlias.ToUpper(), nodeCount));
                        tempStr = tempStr.Replace(string.Format("[{0}]", matchNode.RefAlias.ToLower()),
                            string.Format("[{0}_{1}]", matchNode.RefAlias.ToLower(), nodeCount));
                        newWhereString += tempStr;
                        nodeCount--;
                    }
                }

                // Cross apply the unmaterilized edges which point to the optimized tail nodes
                Dictionary<MatchNode,MatchEdge> UnMatEdgeJoinDict = new Dictionary<MatchNode, MatchEdge>();
                foreach (var unMatEdge in component.EdgeMaterilizedDict.Where(e => !e.Value).Select(e=>e.Key))
                {
                    component.TableRef = component.SpanTableRef(component.TableRef,
                        unMatEdge, component.GetNodeRefName(unMatEdge.SourceNode),_graphMetaData);
                    MatchEdge joinEdge;
                    if (UnMatEdgeJoinDict.TryGetValue(unMatEdge.SinkNode, out joinEdge))
                    {
                        if (!string.IsNullOrEmpty(newWhereString))
                            newWhereString += " AND ";
                        newWhereString += string.Format("{0}.Sink = {1}.Sink", joinEdge.EdgeAlias, unMatEdge.EdgeAlias);
                    }
                    else
                    {
                        UnMatEdgeJoinDict[unMatEdge.SinkNode] = unMatEdge;
                    }
                }

                // Updates from clause
                node.FromClause.TableReferences.Add(component.TableRef);
            }

            if (!string.IsNullOrEmpty(newWhereString))
            {
                if (node.WhereClause!=null && node.WhereClause.SearchCondition!=null)
                    node.WhereClause.SearchCondition = new WBooleanParenthesisExpression
                    {
                        Expression = node.WhereClause.SearchCondition
                    };
                else
                {
                    node.WhereClause = new WWhereClause();
                }
                node.WhereClause.GhostString = newWhereString;
            }
            
        }