Beispiel #1
0
        private NamedWindowOnMergeActionIns SetupInsert(string namedWindowName, InternalEventRouter internalEventRouter, EventTypeSPI eventTypeNamedWindow, int selectClauseNumber, OnTriggerMergeActionInsert desc, EventType triggeringEventType, string triggeringStreamName, StatementContext statementContext)
        {
            // Compile insert-into INFO
            string streamName     = desc.OptionalStreamName ?? eventTypeNamedWindow.Name;
            var    insertIntoDesc = InsertIntoDesc.FromColumns(streamName, desc.Columns);

            // rewrite any wildcards to use "stream.wildcard"
            if (triggeringStreamName == null)
            {
                triggeringStreamName = UuidGenerator.Generate();
            }
            var selectNoWildcard = CompileSelectNoWildcard(triggeringStreamName, desc.SelectClauseCompiled);

            // Set up event types for select-clause evaluation: The first type does not contain anything as its the named window row which is not present for insert
            var dummyTypeNoProperties = new MapEventType(EventTypeMetadata.CreateAnonymous("merge_named_window_insert", ApplicationType.MAP), "merge_named_window_insert", 0, null, Collections.EmptyDataMap, null, null, null);
            var eventTypes            = new EventType[] { dummyTypeNoProperties, triggeringEventType };
            var streamNames           = new string[] { UuidGenerator.Generate(), triggeringStreamName };
            var streamTypeService     = new StreamTypeServiceImpl(eventTypes, streamNames, new bool[1], statementContext.EngineURI, false);

            // Get select expr processor
            var selectExprEventTypeRegistry = new SelectExprEventTypeRegistry(statementContext.StatementName, statementContext.StatementEventTypeRef);
            var exprEvaluatorContext        = new ExprEvaluatorContextStatement(statementContext, false);
            var insertHelper = SelectExprProcessorFactory.GetProcessor(
                statementContext.Container,
                Collections.SingletonList(selectClauseNumber),
                selectNoWildcard.ToArray(), false,
                insertIntoDesc, null, null, streamTypeService,
                statementContext.EventAdapterService,
                statementContext.StatementResultService,
                statementContext.ValueAddEventService,
                selectExprEventTypeRegistry,
                statementContext.EngineImportService,
                exprEvaluatorContext,
                statementContext.VariableService,
                statementContext.ScriptingService,
                statementContext.TableService,
                statementContext.TimeProvider,
                statementContext.EngineURI,
                statementContext.StatementId,
                statementContext.StatementName,
                statementContext.Annotations,
                statementContext.ContextDescriptor,
                statementContext.ConfigSnapshot, null,
                statementContext.NamedWindowMgmtService, null, null,
                statementContext.StatementExtensionServicesContext);
            var filterEval = desc.OptionalWhereClause == null ? null : desc.OptionalWhereClause.ExprEvaluator;

            var routerToUser = streamName.Equals(namedWindowName) ? null : internalEventRouter;
            var audit        = AuditEnum.INSERT.GetAudit(statementContext.Annotations) != null;

            string insertIntoTableName = null;

            if (statementContext.TableService.GetTableMetadata(insertIntoDesc.EventTypeName) != null)
            {
                insertIntoTableName = insertIntoDesc.EventTypeName;
            }

            return(new NamedWindowOnMergeActionIns(filterEval, insertHelper, routerToUser, insertIntoTableName, statementContext.TableService, statementContext.EpStatementHandle, statementContext.InternalEventEngineRouteDest, audit));
        }
Beispiel #2
0
        public override EPPreparedExecuteIUDSingleStreamExec GetExecutor(FilterSpecCompiled filter, string aliasName)
        {
            var selectNoWildcard = NamedWindowOnMergeHelper.CompileSelectNoWildcard(UuidGenerator.Generate(), StatementSpec.SelectClauseSpec.SelectExprList);

            StreamTypeService streamTypeService = new StreamTypeServiceImpl(StatementContext.EngineURI, true);
            var exprEvaluatorContextStatement   = new ExprEvaluatorContextStatement(StatementContext, true);

            // assign names
            var validationContext = new ExprValidationContext(
                streamTypeService,
                StatementContext.EngineImportService,
                StatementContext.StatementExtensionServicesContext,
                null, StatementContext.TimeProvider,
                StatementContext.VariableService,
                StatementContext.TableService,
                exprEvaluatorContextStatement,
                StatementContext.EventAdapterService,
                StatementContext.StatementName,
                StatementContext.StatementId,
                StatementContext.Annotations,
                StatementContext.ContextDescriptor,
                StatementContext.ScriptingService,
                false, false, true, false, null, false);

            // determine whether column names are provided
            // if the "values" keyword was used, allow sequential automatic name assignment
            string[] assignedSequentialNames = null;
            if (StatementSpec.InsertIntoDesc.ColumnNames.IsEmpty())
            {
                var insert = (FireAndForgetSpecInsert)StatementSpec.FireAndForgetSpec;
                if (insert.IsUseValuesKeyword)
                {
                    assignedSequentialNames = Processor.EventTypePublic.PropertyNames;
                }
            }

            var count = -1;

            foreach (var compiled in StatementSpec.SelectClauseSpec.SelectExprList)
            {
                count++;
                if (compiled is SelectClauseExprCompiledSpec)
                {
                    var      expr = (SelectClauseExprCompiledSpec)compiled;
                    ExprNode validatedExpression = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.SELECT, expr.SelectExpression, validationContext);
                    expr.SelectExpression = validatedExpression;
                    if (expr.AssignedName == null)
                    {
                        if (expr.ProvidedName == null)
                        {
                            if (assignedSequentialNames != null && count < assignedSequentialNames.Length)
                            {
                                expr.AssignedName = assignedSequentialNames[count];
                            }
                            else
                            {
                                expr.AssignedName = ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(expr.SelectExpression);
                            }
                        }
                        else
                        {
                            expr.AssignedName = expr.ProvidedName;
                        }
                    }
                }
            }

            EventType optionalInsertIntoEventType = Processor.EventTypeResultSetProcessor;
            var       selectExprEventTypeRegistry = new SelectExprEventTypeRegistry(StatementContext.StatementName, StatementContext.StatementEventTypeRef);
            var       insertHelper = SelectExprProcessorFactory.GetProcessor(
                Collections.SingletonList(0),
                selectNoWildcard.ToArray(), false,
                StatementSpec.InsertIntoDesc, optionalInsertIntoEventType, null, streamTypeService,
                StatementContext.EventAdapterService,
                StatementContext.StatementResultService,
                StatementContext.ValueAddEventService, selectExprEventTypeRegistry,
                StatementContext.EngineImportService, exprEvaluatorContextStatement,
                StatementContext.VariableService,
                StatementContext.ScriptingService,
                StatementContext.TableService,
                StatementContext.TimeProvider,
                StatementContext.EngineURI,
                StatementContext.StatementId,
                StatementContext.StatementName,
                StatementContext.Annotations,
                StatementContext.ContextDescriptor,
                StatementContext.ConfigSnapshot, null,
                StatementContext.NamedWindowMgmtService, null, null,
                StatementContext.StatementExtensionServicesContext);

            return(new EPPreparedExecuteIUDSingleStreamExecInsert(exprEvaluatorContextStatement, insertHelper, StatementSpec.TableNodes, Services));
        }