Ejemplo n.º 1
0
        public static SelectClauseSpecCompiled CompileSelectClause(SelectClauseSpecRaw spec)
        {
            IList <SelectClauseElementCompiled> selectElements = new List <SelectClauseElementCompiled>();

            foreach (SelectClauseElementRaw raw in spec.SelectExprList)
            {
                if (raw is SelectClauseExprRawSpec)
                {
                    SelectClauseExprRawSpec rawExpr = (SelectClauseExprRawSpec)raw;
                    selectElements.Add(new SelectClauseExprCompiledSpec(rawExpr.SelectExpression, rawExpr.OptionalAsName, rawExpr.OptionalAsName, rawExpr.IsEvents));
                }
                else if (raw is SelectClauseStreamRawSpec)
                {
                    SelectClauseStreamRawSpec rawExpr = (SelectClauseStreamRawSpec)raw;
                    selectElements.Add(new SelectClauseStreamCompiledSpec(rawExpr.StreamName, rawExpr.OptionalAsName));
                }
                else if (raw is SelectClauseElementWildcard)
                {
                    SelectClauseElementWildcard wildcard = (SelectClauseElementWildcard)raw;
                    selectElements.Add(wildcard);
                }
                else
                {
                    throw new IllegalStateException("Unexpected select clause element class : " + raw.GetType().FullName);
                }
            }
            return(new SelectClauseSpecCompiled(selectElements.ToArray(), spec.IsDistinct));
        }
 private static void WalkSubselectSelectClause(
     IList<SelectClauseElementRaw> selectClause,
     ExprNodeSubselectDeclaredDotVisitor visitor)
 {
     foreach (SelectClauseElementRaw element in selectClause) {
         if (element is SelectClauseExprRawSpec) {
             SelectClauseExprRawSpec selectExpr = (SelectClauseExprRawSpec) element;
             selectExpr.SelectExpression.Accept(visitor);
         }
     }
 }
Ejemplo n.º 3
0
        public static void WalkStatement(StatementSpecRaw spec, ExprNodeSubselectDeclaredDotVisitor visitor)
        {
            // Look for expressions with sub-selects in select expression list and filter expression
            // Recursively compile the statement within the statement.
            foreach (SelectClauseElementRaw raw in spec.SelectClauseSpec.SelectExprList)
            {
                if (raw is SelectClauseExprRawSpec)
                {
                    SelectClauseExprRawSpec rawExpr = (SelectClauseExprRawSpec)raw;
                    rawExpr.SelectExpression.Accept(visitor);
                }
                else
                {
                    continue;
                }
            }
            if (spec.FilterRootNode != null)
            {
                spec.FilterRootNode.Accept(visitor);
            }
            if (spec.HavingExprRootNode != null)
            {
                spec.HavingExprRootNode.Accept(visitor);
            }
            if (spec.UpdateDesc != null)
            {
                if (spec.UpdateDesc.OptionalWhereClause != null)
                {
                    spec.UpdateDesc.OptionalWhereClause.Accept(visitor);
                }
                foreach (OnTriggerSetAssignment assignment in spec.UpdateDesc.Assignments)
                {
                    assignment.Expression.Accept(visitor);
                }
            }
            if (spec.OnTriggerDesc != null)
            {
                VisitSubselectOnTrigger(spec.OnTriggerDesc, visitor);
            }
            // Determine pattern-filter subqueries
            foreach (StreamSpecRaw streamSpecRaw in spec.StreamSpecs)
            {
                if (streamSpecRaw is PatternStreamSpecRaw)
                {
                    PatternStreamSpecRaw   patternStreamSpecRaw = (PatternStreamSpecRaw)streamSpecRaw;
                    EvalNodeAnalysisResult analysisResult       = EvalNodeUtil.RecursiveAnalyzeChildNodes(patternStreamSpecRaw.EvalFactoryNode);
                    foreach (EvalFactoryNode evalNode in analysisResult.ActiveNodes)
                    {
                        if (evalNode is EvalFilterFactoryNode)
                        {
                            EvalFilterFactoryNode filterNode = (EvalFilterFactoryNode)evalNode;
                            foreach (ExprNode filterExpr in filterNode.RawFilterSpec.FilterExpressions)
                            {
                                filterExpr.Accept(visitor);
                            }
                        }
                        else if (evalNode is EvalObserverFactoryNode)
                        {
                            int beforeCount = visitor.Subselects.Count;
                            EvalObserverFactoryNode observerNode = (EvalObserverFactoryNode)evalNode;
                            foreach (ExprNode param in observerNode.PatternObserverSpec.ObjectParameters)
                            {
                                param.Accept(visitor);
                            }
                            if (visitor.Subselects.Count != beforeCount)
                            {
                                throw new ExprValidationException("Subselects are not allowed within pattern observer parameters, please consider using a variable instead");
                            }
                        }
                    }
                }
            }

            // walk streams
            WalkStreamSpecs(spec, visitor);
        }
Ejemplo n.º 4
0
        private static void VisitSubselectOnTrigger(OnTriggerDesc onTriggerDesc, ExprNodeSubselectDeclaredDotVisitor visitor)
        {
            if (onTriggerDesc is OnTriggerWindowUpdateDesc)
            {
                OnTriggerWindowUpdateDesc updates = (OnTriggerWindowUpdateDesc)onTriggerDesc;
                foreach (OnTriggerSetAssignment assignment in updates.Assignments)
                {
                    assignment.Expression.Accept(visitor);
                }
            }
            else if (onTriggerDesc is OnTriggerSetDesc)
            {
                OnTriggerSetDesc sets = (OnTriggerSetDesc)onTriggerDesc;
                foreach (OnTriggerSetAssignment assignment in sets.Assignments)
                {
                    assignment.Expression.Accept(visitor);
                }
            }
            else if (onTriggerDesc is OnTriggerSplitStreamDesc)
            {
                OnTriggerSplitStreamDesc splits = (OnTriggerSplitStreamDesc)onTriggerDesc;
                foreach (OnTriggerSplitStream split in splits.SplitStreams)
                {
                    if (split.WhereClause != null)
                    {
                        split.WhereClause.Accept(visitor);
                    }
                    if (split.SelectClause.SelectExprList != null)
                    {
                        foreach (SelectClauseElementRaw element in split.SelectClause.SelectExprList)
                        {
                            if (element is SelectClauseExprRawSpec)
                            {
                                SelectClauseExprRawSpec selectExpr = (SelectClauseExprRawSpec)element;
                                selectExpr.SelectExpression.Accept(visitor);
                            }
                        }
                    }
                }
            }
            else if (onTriggerDesc is OnTriggerMergeDesc)
            {
                OnTriggerMergeDesc merge = (OnTriggerMergeDesc)onTriggerDesc;
                foreach (OnTriggerMergeMatched matched in merge.Items)
                {
                    if (matched.OptionalMatchCond != null)
                    {
                        matched.OptionalMatchCond.Accept(visitor);
                    }
                    foreach (OnTriggerMergeAction action in matched.Actions)
                    {
                        if (action.OptionalWhereClause != null)
                        {
                            action.OptionalWhereClause.Accept(visitor);
                        }

                        if (action is OnTriggerMergeActionUpdate)
                        {
                            OnTriggerMergeActionUpdate update = (OnTriggerMergeActionUpdate)action;
                            foreach (OnTriggerSetAssignment assignment in update.Assignments)
                            {
                                assignment.Expression.Accept(visitor);
                            }
                        }
                        if (action is OnTriggerMergeActionInsert)
                        {
                            OnTriggerMergeActionInsert insert = (OnTriggerMergeActionInsert)action;
                            foreach (SelectClauseElementRaw element in insert.SelectClause)
                            {
                                if (element is SelectClauseExprRawSpec)
                                {
                                    SelectClauseExprRawSpec selectExpr = (SelectClauseExprRawSpec)element;
                                    selectExpr.SelectExpression.Accept(visitor);
                                }
                            }
                        }
                    }
                }
            }
        }