예제 #1
0
		public override AstNode Visit(AstNode node)
		{
			switch (node.NodeType)
			{
				case AstNodeType.ConstantScanAlgebraNode:
				case AstNodeType.NullScanAlgebraNode:
					// For theses nodes it is clear that this subtree will produce 
					// at most one row.
					_willProduceAtMostOneRow = true;
					return node;

				case AstNodeType.AggregateAlgebraNode:
				case AstNodeType.TopAlgebraNode:
				case AstNodeType.AssertAlgebraNode:
					// For these nodes it depends on their actual config.
					return base.Visit(node);

				case AstNodeType.ResultAlgebraNode:
				case AstNodeType.ComputeScalarAlgebraNode:                    
				case AstNodeType.SortAlgebraNode:
				case AstNodeType.FilterAlgebraNode:
					// These nodes don't change the at "most one row" property at
					// all. So we visit them, but don't override their visitation.
					// Their "most one row" property depends on their input.
					return base.Visit(node);
                    
				default:
					// For all other rows we assume that they can produce more
					// then one row.
					return node;
			}
		}
예제 #2
0
		private void WriteAstNode(string name, AstNode node)
		{
			if (node != null)
			{
				_xmlWriter.WriteStartElement(name);
				Visit(node);
				_xmlWriter.WriteEndElement();
			}
		}
예제 #3
0
파일: AstNode.cs 프로젝트: chenzuo/nquery
		public bool IsStructuralEqualTo(AstNode astNode)
		{
			if (astNode == null)
				return false;
			
			if (ReferenceEquals(this, astNode))
				return true;
			
			return Comparer.Visit(this, astNode);
		}		
예제 #4
0
		public static void ProduceFile(string fileName, AstNode node)
		{
			using (StreamWriter sw = new StreamWriter(fileName))
			{
				XmlTextWriter xmlWriter = new XmlTextWriter(sw);
				XmlProducer producer = new XmlProducer(xmlWriter);

				xmlWriter.WriteStartElement("ast");
				if (node != null)
					producer.Visit(node);
				xmlWriter.WriteEndElement();
			}
		}
예제 #5
0
        public override AstNode Visit(AstNode node)
        {
            ExpressionNode expr = node as ExpressionNode;

            if (expr != null)
            {
                BinaryExpression binaryExpression = expr as BinaryExpression;

                if (binaryExpression != null && binaryExpression.Op == _operatorToBreakAt)
                    return base.Visit(expr);

                _partList.Add(expr);
            }

            return node;
        }
예제 #6
0
		public void AddParameter(AstNode target, object value, Type type)
		{
			ILParameterDeclaration ilParameterDeclaration = new ILParameterDeclaration();
			ilParameterDeclaration.Index = _parameters.Count;
			ilParameterDeclaration.Value = value;
			ilParameterDeclaration.Type = type;
			_parameters.Add(ilParameterDeclaration);

			List<ILParameterDeclaration> targetParameters;
			if (!_parameterDictionary.TryGetValue(target, out targetParameters))
			{
				targetParameters = new List<ILParameterDeclaration>();
				_parameterDictionary.Add(target, targetParameters);
			}

			targetParameters.Add(ilParameterDeclaration);
		}
예제 #7
0
        public override AstNode Visit(AstNode node)
        {
            if (!(node is ExpressionNode))
            {
                // Non-expressions are visited as usual.
                return base.Visit(node);
            }

            // First, we only visit expressions that contain a subquery.
            //
            // For correct handling of ProbeColumn we to decect whether probing
            // is required or not. Probing is only needed if the existance subquery
            // appears in an expression that is not a logical AND or logical OR (or
            // an existence subquery itself).

            if (AstUtil.ContainsSubselect(node))
            {
                BinaryExpression binaryExpression = node as BinaryExpression;
                bool isLogicalLink = binaryExpression != null &&
                                     (binaryExpression.Op == BinaryOperator.LogicalAnd ||
                                      binaryExpression.Op == BinaryOperator.LogicalOr);

                bool isExistenceSubquery = node.NodeType == AstNodeType.AllAnySubselect ||
                                           node.NodeType == AstNodeType.ExistsSubselect;

                bool requiresProbing = !isLogicalLink && !isExistenceSubquery;

                if (requiresProbing)
                    _probingEnabledStack.Push(true);

                AstNode resultExpression = base.Visit(node);

                if (requiresProbing)
                    _probingEnabledStack.Pop();

                return resultExpression;
            }

            // Don't visit expressions that do not contain suqueries.
            return node;
        }
예제 #8
0
		public override AstNode Visit(AstNode node)
		{
			switch (node.NodeType)
			{
				case AstNodeType.Literal:
				case AstNodeType.UnaryExpression:
				case AstNodeType.BinaryExpression:
				case AstNodeType.IsNullExpression:
				case AstNodeType.CastExpression:
				case AstNodeType.CaseExpression:
				case AstNodeType.NullIfExpression:
				case AstNodeType.ParameterExpression:
				case AstNodeType.PropertyAccessExpression:
				case AstNodeType.FunctionInvocationExpression:
				case AstNodeType.MethodInvocationExpression:
				case AstNodeType.RowBufferEntryExpression:
					return base.Visit(node);

				default:
					throw ExceptionBuilder.UnhandledCaseLabel(node.NodeType);
			}
		}
예제 #9
0
		public override AstNode Visit(AstNode node)
		{
			// Since we are going to visit the next node we must reset this flag.
			_lastExpressionsYieldsNullOrFalse = false;
			
			// Only for node types listed below we can predict if the expression will yield
			// null/false. For all other node types this is unknown. To avoid that children
			// of those nodes can set the _lastExpressionsYieldsNullOrFalse we don't visit them.
			switch (node.NodeType)
			{
				case AstNodeType.IsNullExpression:
				case AstNodeType.UnaryExpression:
				case AstNodeType.BinaryExpression:
				case AstNodeType.ColumnExpression:
				case AstNodeType.RowBufferEntryExpression:
				case AstNodeType.PropertyAccessExpression:
				case AstNodeType.MethodInvocationExpression:
					return base.Visit(node);									
			}
						
			return node;
		}
        public override AstNode Visit(AstNode node)
        {
            if (_groupByExpressions != null)
            {
                // First we check if the expression is directly contained the in GROUP BY.
                // In this case we don't traverse the children.
                //
                // This way we get only those columns which are not contained in GROUP BY.

                ExpressionNode nodeAsExpr = node as ExpressionNode;

                if (nodeAsExpr != null)
                {
                    foreach (ExpressionNode groupyByExpression in _groupByExpressions)
                    {
                        if (groupyByExpression.IsStructuralEqualTo(nodeAsExpr))
                            return node;
                    }
                }
            }

            return base.Visit (node);
        }
예제 #11
0
            public override AstNode Visit(AstNode node)
            {
                ExpressionNode expression = node as ExpressionNode;
                if (expression != null)
                {
                    foreach (ComputedValueDefinition computedBufferedValue in _computedValues)
                    {
                        if (expression.IsStructuralEqualTo(computedBufferedValue.Expression))
                        {
                            RowBufferEntryExpression rowBufferExpression = new RowBufferEntryExpression();
                            rowBufferExpression.RowBufferEntry = computedBufferedValue.Target;
                            return rowBufferExpression;
                        }
                    }
                }

                return base.Visit(node);
            }
예제 #12
0
파일: Comparer.cs 프로젝트: chenzuo/nquery
		public static bool Visit(AstNode node1, AstNode node2)
		{
			switch (node1.NodeType)
			{
				case AstNodeType.Literal:
					return VisitLiteralValue((LiteralExpression)node1, node2 as LiteralExpression);

				case AstNodeType.UnaryExpression:
					return VisitUnaryExpression((UnaryExpression)node1, node2 as UnaryExpression);
				case AstNodeType.BinaryExpression:
					return VisitBinaryExpression((BinaryExpression)node1, node2 as BinaryExpression);
				case AstNodeType.BetweenExpression:
					return VisitBetweenExpression((BetweenExpression)node1, node2 as BetweenExpression);
				case AstNodeType.IsNullExpression:
					return VisitIsNullExpression((IsNullExpression)node1, node2 as IsNullExpression);
				case AstNodeType.CastExpression:
					return VisitCastExpression((CastExpression)node1, node2 as CastExpression);
				case AstNodeType.CaseExpression:
					return VisitCaseExpression((CaseExpression)node1, node2 as CaseExpression);
				case AstNodeType.CoalesceExpression:
					return VisitCoalesceExpression((CoalesceExpression)node1, node2 as CoalesceExpression);
				case AstNodeType.NullIfExpression:
					return VisitNullIfExpression((NullIfExpression)node1, node2 as NullIfExpression);
				case AstNodeType.InExpression:
					return VisitInExpression((InExpression)node1, node2 as InExpression);

				case AstNodeType.NamedConstantExpression:
					return VisitNamedConstantExpression((NamedConstantExpression)node1, node2 as NamedConstantExpression);
				case AstNodeType.ParameterExpression:
					return VisitParameterExpression((ParameterExpression)node1, node2 as ParameterExpression);
				case AstNodeType.NameExpression:
					return VisitNameExpression((NameExpression)node1, node2 as NameExpression);
				case AstNodeType.PropertyAccessExpression:
					return VisitPropertyAccessExpression((PropertyAccessExpression)node1, node2 as PropertyAccessExpression);
				case AstNodeType.FunctionInvocationExpression:
					return VisitFunctionInvocationExpression((FunctionInvocationExpression)node1, node2 as FunctionInvocationExpression);
				case AstNodeType.MethodInvocationExpression:
					return VisitMethodInvocationExpression((MethodInvocationExpression)node1, node2 as MethodInvocationExpression);

				case AstNodeType.ColumnExpression:
					return VisitColumnExpression((ColumnExpression)node1, node2 as ColumnExpression);
				case AstNodeType.RowBufferEntryExpression:
					return VisitRowBufferExpression((RowBufferEntryExpression)node1, node2 as RowBufferEntryExpression);
				case AstNodeType.AggregateExpression:
					return VisitAggregagateExpression((AggregateExpression)node1, node2 as AggregateExpression);
				case AstNodeType.SingleRowSubselect:
					return VisitSingleRowSubselect((SingleRowSubselect)node1, node2 as SingleRowSubselect);
				case AstNodeType.ExistsSubselect:
					return VisitExistsSubselect((ExistsSubselect)node1, node2 as ExistsSubselect);
				case AstNodeType.AllAnySubselect:
					return VisitAllAnySubselect((AllAnySubselect)node1, node2 as AllAnySubselect);

				case AstNodeType.NamedTableReference:
					return VisitNamedTableReference((NamedTableReference)node1, node2 as NamedTableReference);
				case AstNodeType.JoinedTableReference:
					return VisitJoinedTableReference((JoinedTableReference)node1, node2 as JoinedTableReference);
				case AstNodeType.DerivedTableReference:
					return VisitDerivedTableReference((DerivedTableReference)node1, node2 as DerivedTableReference);

				case AstNodeType.SelectQuery:
					return VisitSelectQuery((SelectQuery)node1, node2 as SelectQuery);
				case AstNodeType.BinaryQuery:
					return VisitBinaryQuery((BinaryQuery)node1, node2 as BinaryQuery);
				case AstNodeType.SortedQuery:
					return VisitSortedQuery((SortedQuery)node1, node2 as SortedQuery);
				case AstNodeType.CommonTableExpressionQuery:
					return VisitCommonTableExpressionQuery((CommonTableExpressionQuery)node1, node2 as CommonTableExpressionQuery);

				default:
					throw ExceptionBuilder.UnhandledCaseLabel(node1.NodeType);
			}
		}
예제 #13
0
			public override AstNode Visit(AstNode node)
			{
				node = base.Visit(node);

				AlgebraNode algebraNode = node as AlgebraNode;
				if (algebraNode != null && algebraNode.OutputList != null)
				{
					for (int i = 0; i < algebraNode.OutputList.Length; i++)
						algebraNode.OutputList[i] = ReplaceRowBuffer(algebraNode.OutputList[i]);
				}

				return node;
			}
예제 #14
0
파일: AstUtil.cs 프로젝트: chenzuo/nquery
		public static MetaInfo GetMetaInfo(AstNode astNode)
		{
			MetaInfoFinder metaInfoFinder = new MetaInfoFinder();
			metaInfoFinder.Visit(astNode);
			return metaInfoFinder.GetMetaInfo();
		}
예제 #15
0
		private AlgebraNode ConvertAstNode(AstNode astNode)
		{
			Visit(astNode);
			return GetLastAlgebraNode();
		}
예제 #16
0
파일: AstUtil.cs 프로젝트: chenzuo/nquery
		public static bool ContainsSubselect(AstNode astNode)
		{
			MetaInfo metaInfo = GetMetaInfo(astNode);
			return metaInfo.ContainsExistenceSubselects || metaInfo.ContainsSingleRowSubselects;
		}
예제 #17
0
파일: AstUtil.cs 프로젝트: chenzuo/nquery
		public static RowBufferEntry[] GetRowBufferEntryReferences(AstNode astNode)
		{
			RowBufferEntryReferenceFinder rowBufferEntryReferenceFinder = new RowBufferEntryReferenceFinder();
			rowBufferEntryReferenceFinder.Visit(astNode);
			return rowBufferEntryReferenceFinder.GetReferences();
		}
예제 #18
0
		public virtual AstNode Visit(AstNode node)
		{
			switch (node.NodeType)
			{
				case AstNodeType.Literal:
					return VisitLiteralValue((LiteralExpression)node);

				case AstNodeType.UnaryExpression:
					return VisitUnaryExpression((UnaryExpression)node);
				case AstNodeType.BinaryExpression:
					return VisitBinaryExpression((BinaryExpression)node);
				case AstNodeType.BetweenExpression:
					return VisitBetweenExpression((BetweenExpression)node);
				case AstNodeType.IsNullExpression:
					return VisitIsNullExpression((IsNullExpression)node);
				case AstNodeType.CastExpression:
					return VisitCastExpression((CastExpression)node);
				case AstNodeType.CaseExpression:
					return VisitCaseExpression((CaseExpression)node);
				case AstNodeType.CoalesceExpression:
					return VisitCoalesceExpression((CoalesceExpression)node);
				case AstNodeType.NullIfExpression:
					return VisitNullIfExpression((NullIfExpression)node);
				case AstNodeType.InExpression:
					return VisitInExpression((InExpression)node);

				case AstNodeType.NamedConstantExpression:
					return VisitNamedConstantExpression((NamedConstantExpression)node);
				case AstNodeType.ParameterExpression:
					return VisitParameterExpression((ParameterExpression)node);
				case AstNodeType.NameExpression:
					return VisitNameExpression((NameExpression)node);
				case AstNodeType.PropertyAccessExpression:
					return VisitPropertyAccessExpression((PropertyAccessExpression)node);
				case AstNodeType.FunctionInvocationExpression:
					return VisitFunctionInvocationExpression((FunctionInvocationExpression)node);
				case AstNodeType.MethodInvocationExpression:
					return VisitMethodInvocationExpression((MethodInvocationExpression)node);

				case AstNodeType.ColumnExpression:
					return VisitColumnExpression((ColumnExpression)node);
				case AstNodeType.RowBufferEntryExpression:
					return VisitRowBufferEntryExpression((RowBufferEntryExpression)node);
				case AstNodeType.AggregateExpression:
					return VisitAggregagateExpression((AggregateExpression)node);
				case AstNodeType.SingleRowSubselect:
					return VisitSingleRowSubselect((SingleRowSubselect)node);
				case AstNodeType.ExistsSubselect:
					return VisitExistsSubselect((ExistsSubselect)node);
				case AstNodeType.AllAnySubselect:
					return VisitAllAnySubselect((AllAnySubselect)node);

				case AstNodeType.NamedTableReference:
					return VisitNamedTableReference((NamedTableReference)node);
				case AstNodeType.JoinedTableReference:
					return VisitJoinedTableReference((JoinedTableReference)node);
				case AstNodeType.DerivedTableReference:
					return VisitDerivedTableReference((DerivedTableReference)node);

				case AstNodeType.SelectQuery:
					return VisitSelectQuery((SelectQuery)node);
				case AstNodeType.BinaryQuery:
					return VisitBinaryQuery((BinaryQuery)node);
				case AstNodeType.SortedQuery:
					return VisitSortedQuery((SortedQuery)node);
				case AstNodeType.CommonTableExpressionQuery:
					return VisitCommonTableExpressionQuery((CommonTableExpressionQuery)node);

				case AstNodeType.TableAlgebraNode:
					return VisitTableAlgebraNode((TableAlgebraNode)node);
				case AstNodeType.JoinAlgebraNode:
					return VisitJoinAlgebraNode((JoinAlgebraNode)node);
				case AstNodeType.ConstantScanAlgebraNode:
					return VisitConstantScanAlgebraNode((ConstantScanAlgebraNode)node);
				case AstNodeType.NullScanAlgebraNode:
					return VisitNullScanAlgebraNode((NullScanAlgebraNode)node);
				case AstNodeType.ConcatAlgebraNode:
					return VisitConcatAlgebraNode((ConcatAlgebraNode)node);
				case AstNodeType.SortAlgebraNode:
					return VisitSortAlgebraNode((SortAlgebraNode)node);
				case AstNodeType.AggregateAlgebraNode:
					return VisitAggregateAlgebraNode((AggregateAlgebraNode)node);
				case AstNodeType.TopAlgebraNode:
					return VisitTopAlgebraNode((TopAlgebraNode)node);
				case AstNodeType.FilterAlgebraNode:
					return VisitFilterAlgebraNode((FilterAlgebraNode)node);
				case AstNodeType.ComputeScalarAlgebraNode:
					return VisitComputeScalarAlgebraNode((ComputeScalarAlgebraNode)node);
				case AstNodeType.ResultAlgebraNode:
					return VisitResultAlgebraNode((ResultAlgebraNode)node);
				case AstNodeType.AssertAlgebraNode:
					return VisitAssertAlgebraNode((AssertAlgebraNode)node);
				case AstNodeType.IndexSpoolAlgebraNode:
					return VisitIndexSpoolAlgebraNode((IndexSpoolAlgebraNode)node);
				case AstNodeType.StackedTableSpoolAlgebraNode:
					return VisitStackedTableSpoolAlgebraNode((StackedTableSpoolAlgebraNode)node);
				case AstNodeType.StackedTableSpoolRefAlgebraNode:
					return VisitTableSpoolRefAlgebraNode((StackedTableSpoolRefAlgebraNode)node);
				case AstNodeType.HashMatchAlgebraNode:
					return VisitHashMatchAlgebraNode((HashMatchAlgebraNode)node);

				default:
					throw ExceptionBuilder.UnhandledCaseLabel(node.NodeType);
			}
		}
예제 #19
0
		public ILParameterDeclaration[] GetParameters(AstNode target)
		{
			return _parameterDictionary[target].ToArray();
		}
예제 #20
0
			public override AstNode Visit(AstNode node)
			{
				switch (node.NodeType)
				{
					case AstNodeType.JoinAlgebraNode:
					case AstNodeType.FilterAlgebraNode:
					case AstNodeType.TableAlgebraNode:
						return base.Visit(node);
                        
					default:
						_consistsOnlyOfInnerJoinsFiltersAndTables = false;
						return node;
				}
			}