/// <summary>
 ///     Ctor
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="namedWindowName">named window name</param>
 public AccessModifierNamedWindowContext(
     StatementBaseInfo @base,
     string namedWindowName)
     : base(@base)
 {
     NamedWindowName = namedWindowName;
 }
Ejemplo n.º 2
0
        private static EventType GetDefineMultimatchEventType(
            LinkedHashMap<string, Pair<int, bool>> variableStreams,
            EventType parentEventType,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            IDictionary<string, object> multievent = new LinkedHashMap<string, object>();
            foreach (var entry in variableStreams) {
                if (entry.Value.Second) {
                    multievent.Put(entry.Key, new[] {parentEventType});
                }
            }

            var multimatchAllTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogMultimatchAllName;
            var multimatchAllTypeMetadata = new EventTypeMetadata(
                multimatchAllTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var multimatchAllEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                multimatchAllTypeMetadata,
                multievent,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(multimatchAllEventType);
            return multimatchAllEventType;
        }
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="expressionName">expression name</param>
 public AccessModifierExpressionContext(
     StatementBaseInfo @base,
     string expressionName)
     : base(@base)
 {
     ExpressionName = expressionName;
 }
 /// <summary>
 ///     Ctor
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="variableName">returns the variable name</param>
 public AccessModifierVariableContext(
     StatementBaseInfo @base,
     string variableName)
     : base(@base)
 {
     VariableName = variableName;
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="contextName">context name</param>
 public AccessModifierContextContext(
     StatementBaseInfo @base,
     string contextName)
     : base(@base)
 {
     ContextName = contextName;
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="tableName">table name</param>
 public AccessModifierTableContext(
     StatementBaseInfo @base,
     string tableName)
     : base(@base)
 {
     TableName = tableName;
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="base">statement info</param>
 public StatementOptionContextBase(StatementBaseInfo @base)
 {
     EplSupplier     = () => @base.Compilable.ToEPL();
     StatementName   = @base.StatementName;
     ModuleName      = @base.ModuleName;
     Annotations     = @base.StatementRawInfo.Annotations;
     StatementNumber = @base.StatementNumber;
 }
 public NameAccessModifier GetAccessModifierContext(
     StatementBaseInfo @base,
     string contextName)
 {
     return GetModifier(
         @base.StatementRawInfo.Annotations,
         opts => opts.AccessModifierContext?.Invoke(new AccessModifierContextContext(@base, contextName)),
         conf => conf.AccessModifierContext);
 }
Ejemplo n.º 9
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="base">statement info</param>
 /// <param name="scriptName">script name</param>
 /// <param name="numParameters">script number of parameters</param>
 public AccessModifierScriptContext(
     StatementBaseInfo @base,
     string scriptName,
     int numParameters)
     : base(@base)
 {
     ScriptName = scriptName;
     NumParameters = numParameters;
 }
 public NameAccessModifier GetAccessModifierTable(
     StatementBaseInfo @base,
     string tableName)
 {
     return GetModifier(
         @base.StatementRawInfo.Annotations,
         opts => opts.AccessModifierTable?.Invoke(new AccessModifierTableContext(@base, tableName)),
         conf => conf.AccessModifierTable);
 }
Ejemplo n.º 11
0
 public StmtForgeMethodCreateClass(
     StatementBaseInfo @base,
     ClassProvidedPrecompileResult classProvidedPrecompileResult,
     string className)
     : base(@base)
 {
     this.classProvidedPrecompileResult = classProvidedPrecompileResult;
     this.className = className;
 }
 public NameAccessModifier GetAccessModifierNamedWindow(
     StatementBaseInfo @base,
     string namedWindowName)
 {
     return GetModifier(
         @base.StatementRawInfo.Annotations,
         opts => opts.AccessModifierNamedWindow?.Invoke(
             new AccessModifierNamedWindowContext(@base, namedWindowName)),
         conf => conf.AccessModifierNamedWindow);
 }
 public NameAccessModifier GetAccessModifierExpression(
     StatementBaseInfo @base,
     string expressionName)
 {
     return GetModifier(
         @base.StatementRawInfo.Annotations,
         opts => opts.AccessModifierExpression?.Invoke(
             new AccessModifierExpressionContext(@base, expressionName)),
         conf => conf.AccessModifierExpression);
 }
 public NameAccessModifier GetAccessModifierScript(
     StatementBaseInfo @base,
     string scriptName,
     int numParameters)
 {
     return GetModifier(
         @base.StatementRawInfo.Annotations,
         opts => opts.AccessModifierScript?.Invoke(
             new AccessModifierScriptContext(@base, scriptName, numParameters)),
         conf => conf.AccessModifierScript);
 }
Ejemplo n.º 15
0
        private static IList<NamedWindowSelectedProps> CompileLimitedSelect(
            SelectFromInfo selectFromInfo,
            StatementBaseInfo @base,
            StatementCompileTimeServices compileTimeServices)
        {
            IList<NamedWindowSelectedProps> selectProps = new List<NamedWindowSelectedProps>();
            StreamTypeService streams = new StreamTypeServiceImpl(
                new[] {selectFromInfo.EventType},
                new[] {"stream_0"},
                new[] {false},
                false,
                false);

            var validationContext =
                new ExprValidationContextBuilder(streams, @base.StatementRawInfo, compileTimeServices).Build();
            foreach (var item in @base.StatementSpec.SelectClauseCompiled.SelectExprList) {
                if (!(item is SelectClauseExprCompiledSpec)) {
                    continue;
                }

                var exprSpec = (SelectClauseExprCompiledSpec) item;
                var validatedExpression = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.SELECT,
                    exprSpec.SelectExpression,
                    validationContext);

                // determine an element name if none assigned
                var asName = exprSpec.ProvidedName;
                if (asName == null) {
                    asName = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validatedExpression);
                }

                // check for fragments
                EventType fragmentType = null;
                if (validatedExpression is ExprIdentNode && !(selectFromInfo.EventType is NativeEventType)) {
                    var identNode = (ExprIdentNode) validatedExpression;
                    var fragmentEventType = selectFromInfo.EventType.GetFragmentType(identNode.FullUnresolvedName);
                    if (fragmentEventType != null && !fragmentEventType.IsNative) {
                        fragmentType = fragmentEventType.FragmentType;
                    }
                }

                var validatedElement = new NamedWindowSelectedProps(
                    validatedExpression.Forge.EvaluationType,
                    asName,
                    fragmentType);
                selectProps.Add(validatedElement);
            }

            return selectProps;
        }
        public override IList<StmtClassForgeableFactory> Validate(
            StreamTypeService typeService,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            int count = 0;
            ExprValidationContext validationContext =
                new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .Build();
            ExprNode[] inputParamNodes = new ExprNode[inputParameters.Length];
            foreach (string inputParam in inputParameters) {
                ExprNode raw = FindSQLExpressionNode(StreamNum, count, @base.StatementSpec.Raw.SqlParameters);
                if (raw == null) {
                    throw new ExprValidationException(
                        "Internal error find expression for historical stream parameter " +
                        count +
                        " stream " +
                        StreamNum);
                }

                ExprNode evaluator = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.DATABASEPOLL,
                    raw,
                    validationContext);
                inputParamNodes[count++] = evaluator;

                ExprNodeIdentifierCollectVisitor visitor = new ExprNodeIdentifierCollectVisitor();
                visitor.Visit(evaluator);
                foreach (ExprIdentNode identNode in visitor.ExprProperties) {
                    if (identNode.StreamId == StreamNum) {
                        throw new ExprValidationException(
                            "Invalid expression '" + inputParam + "' resolves to the historical data itself");
                    }

                    SubordinateStreams.Add(identNode.StreamId);
                }
            }

            InputParamEvaluators = ExprNodeUtilityQuery.GetForges(inputParamNodes);
            
            
            // plan multikey
            MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(InputParamEvaluators, false, @base.StatementRawInfo, services.SerdeResolver);
            MultiKeyClassRef = multiKeyPlan.ClassRef;

            return multiKeyPlan.MultiKeyForgeables;
        }
 public DataFlowOpForgeInitializeContext(
     IContainer container,
     string dataflowName,
     int operatorNumber,
     Attribute[] operatorAnnotations,
     GraphOperatorSpec operatorSpec,
     IDictionary<int, DataFlowOpInputPort> inputPorts,
     IDictionary<int, DataFlowOpOutputPort> outputPorts,
     DataFlowOpForgeCodegenEnv codegenEnv,
     StatementBaseInfo @base,
     StatementCompileTimeServices services)
 {
     DataflowName = dataflowName;
     OperatorNumber = operatorNumber;
     OperatorAnnotations = operatorAnnotations;
     OperatorSpec = operatorSpec;
     InputPorts = inputPorts;
     OutputPorts = outputPorts;
     CodegenEnv = codegenEnv;
     Base = @base;
     Services = services;
     Container = container;
 }
Ejemplo n.º 18
0
        public static MapEventType MakeRegisterPatternType(
            StatementBaseInfo @base,
            int stream,
            PatternStreamSpecCompiled patternStreamSpec,
            StatementCompileTimeServices services)
        {
            var patternEventTypeName = services.EventTypeNameGeneratorStatement.GetPatternTypeName(stream);
            var metadata = new EventTypeMetadata(
                patternEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.MAP,
                NameAccessModifier.PRIVATE,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            IDictionary<string, object> propertyTypes = new LinkedHashMap<string, object>();
            foreach (var entry in patternStreamSpec.TaggedEventTypes) {
                propertyTypes.Put(entry.Key, entry.Value.First);
            }

            foreach (var entry in patternStreamSpec.ArrayEventTypes) {
                propertyTypes.Put(entry.Key, new[] {entry.Value.First});
            }

            var patternType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                metadata,
                propertyTypes,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(patternType);
            return patternType;
        }
        public override IList<StmtClassForgeableFactory> Validate(
            StreamTypeService typeService,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            // validate and visit
            var validationContext = new ExprValidationContextBuilder(typeService, @base.StatementRawInfo, services)
                .WithAllowBindingConsumption(true)
                .Build();

            var visitor = new ExprNodeIdentifierAndStreamRefVisitor(true);
            var validatedInputParameters = new List<ExprNode>();

            foreach (var exprNode in methodStreamSpec.Expressions) {
                var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.METHODINVJOIN,
                    exprNode,
                    validationContext);
                validatedInputParameters.Add(validated);
                validated.Accept(visitor);
            }

            // determine required streams
            foreach (ExprNodePropOrStreamDesc @ref in visitor.Refs) {
                SubordinateStreams.Add(@ref.StreamNum);
            }

            // class-based evaluation
            MethodInfo targetMethod = null;
            if (metadata.MethodProviderClass != null) {
                // resolve actual method to use
                ExprNodeUtilResolveExceptionHandler handler = new ProxyExprNodeUtilResolveExceptionHandler {
                    ProcHandle = e => {
                        if (methodStreamSpec.Expressions.Count == 0) {
                            return new ExprValidationException(
                                "Method footprint does not match the number or type of expression parameters, expecting no parameters in method: " +
                                e.Message);
                        }

                        var resultTypes = ExprNodeUtilityQuery.GetExprResultTypes(validatedInputParameters);
                        return new ExprValidationException(
                            "Method footprint does not match the number or type of expression parameters, expecting a method where parameters are typed '" +
                            TypeHelper.GetParameterAsString(resultTypes) +
                            "': " +
                            e.Message);
                    }
                };
                var desc = ExprNodeUtilityResolve.ResolveMethodAllowWildcardAndStream(
                    metadata.MethodProviderClass.FullName,
                    metadata.IsStaticMethod ? null : metadata.MethodProviderClass,
                    methodStreamSpec.MethodName,
                    validatedInputParameters,
                    false,
                    null,
                    handler,
                    methodStreamSpec.MethodName,
                    @base.StatementRawInfo,
                    services);
                InputParamEvaluators = desc.ChildForges;
                targetMethod = desc.ReflectionMethod;
            }
            else {
                // script-based evaluation
                InputParamEvaluators = ExprNodeUtilityQuery.GetForges(ExprNodeUtilityQuery.ToArray(validatedInputParameters));
            }
            
            // plan multikey
            MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(InputParamEvaluators, false, @base.StatementRawInfo, services.SerdeResolver);
            MultiKeyClassRef = multiKeyPlan.ClassRef;

            Pair<MethodTargetStrategyForge, MethodConversionStrategyForge> strategies =
                PollExecStrategyPlanner.Plan(metadata, targetMethod, EventType);
            target = strategies.First;
            conversion = strategies.Second;
            
            return multiKeyPlan.MultiKeyForgeables;
        }
Ejemplo n.º 20
0
 public StmtForgeMethodCreateSchema(StatementBaseInfo @base)
 {
     this.@base = @base;
 }
Ejemplo n.º 21
0
        public static HistoricalEventViewableMethodForge CreateMethodStatementView(
            int stream,
            MethodStreamSpec methodStreamSpec,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var variableMetaData = services.VariableCompileTimeResolver.Resolve(methodStreamSpec.ClassName);
            MethodPollingExecStrategyEnum strategy;
            MethodInfo methodReflection = null;
            string eventTypeNameProvidedUDFOrScript = null;
            var contextName = @base.StatementSpec.Raw.OptionalContextName;
            var classpathImportService = services.ImportServiceCompileTime;

            // see if this is a script in the from-clause
            ExprNodeScript scriptExpression = null;
            if (methodStreamSpec.ClassName == null && methodStreamSpec.MethodName != null) {
                var script = services.ScriptCompileTimeResolver.Resolve(
                    methodStreamSpec.MethodName,
                    methodStreamSpec.Expressions.Count);
                if (script != null) {
                    scriptExpression = new ExprNodeScript(
                        services.Configuration.Compiler.Scripts.DefaultDialect,
                        script,
                        methodStreamSpec.Expressions);
                }
            }

            try {
                if (scriptExpression != null) {
                    eventTypeNameProvidedUDFOrScript = scriptExpression.EventTypeNameAnnotation;
                    strategy = MethodPollingExecStrategyEnum.TARGET_SCRIPT;
                    EPLValidationUtil.ValidateSimpleGetSubtree(
                        ExprNodeOrigin.METHODINVJOIN,
                        scriptExpression,
                        null,
                        false,
                        @base.StatementRawInfo,
                        services);
                }
                else if (variableMetaData != null) {
                    var variableName = variableMetaData.VariableName;
                    if (variableMetaData.OptionalContextName != null) {
                        if (contextName == null || !contextName.Equals(variableMetaData.OptionalContextName)) {
                            throw new ExprValidationException(
                                "Variable by name '" +
                                variableMetaData.VariableName +
                                "' has been declared for context '" +
                                variableMetaData.OptionalContextName +
                                "' and can only be used within the same context");
                        }

                        strategy = MethodPollingExecStrategyEnum.TARGET_VAR_CONTEXT;
                    }
                    else {
                        if (variableMetaData.IsConstant) {
                            strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                        }
                        else {
                            strategy = MethodPollingExecStrategyEnum.TARGET_VAR;
                        }
                    }

                    methodReflection = classpathImportService.ResolveNonStaticMethodOverloadChecked(
                        variableMetaData.Type,
                        methodStreamSpec.MethodName);
                }
                else if (methodStreamSpec.ClassName == null) { // must be either UDF or script
                    Pair<Type, ImportSingleRowDesc> udf;
                    try {
                        udf = classpathImportService.ResolveSingleRow(
                            methodStreamSpec.MethodName,
                            services.ClassProvidedExtension);
                    }
                    catch (ImportException ex) {
                        throw new ExprValidationException(
                            "Failed to find user-defined function '" + methodStreamSpec.MethodName + "': " + ex.Message,
                            ex);
                    }

                    methodReflection = classpathImportService.ResolveMethodOverloadChecked(
                        udf.First,
                        methodStreamSpec.MethodName);
                    eventTypeNameProvidedUDFOrScript = udf.Second.OptionalEventTypeName;
                    strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                }
                else {
                    methodReflection = classpathImportService.ResolveMethodOverloadChecked(
                        methodStreamSpec.ClassName,
                        methodStreamSpec.MethodName,
                        services.ClassProvidedExtension);
                    strategy = MethodPollingExecStrategyEnum.TARGET_CONST;
                }
            }
            catch (ExprValidationException) {
                throw;
            }
            catch (Exception e) {
                throw new ExprValidationException(e.Message, e);
            }

            Type methodProviderClass = null;
            Type beanClass;
            IDictionary<string, object> oaType = null;
            IDictionary<string, object> mapType = null;
            var isCollection = false;
            var isEnumerator = false;
            EventType eventType;
            EventType eventTypeWhenMethodReturnsEventBeans = null;
            var isStaticMethod = false;

            if (methodReflection != null) {
                methodProviderClass = methodReflection.DeclaringType;
                isStaticMethod = variableMetaData == null;

                // Determine object type returned by method
                beanClass = methodReflection.ReturnType;
                if (beanClass == typeof(void) || beanClass == typeof(void) || beanClass.IsBuiltinDataType()) {
                    throw new ExprValidationException(
                        "Invalid return type for static method '" +
                        methodReflection.Name +
                        "' of class '" +
                        methodStreamSpec.ClassName +
                        "', expecting a type");
                }

                if (methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType() != typeof(EventBean)) {
                    beanClass = methodReflection.ReturnType.GetElementType();
                }

                isCollection = beanClass.IsGenericCollection() && !beanClass.IsGenericDictionary();
                Type collectionClass = null;
                if (isCollection) {
                    collectionClass = TypeHelper.GetGenericReturnType(methodReflection, true);
                    beanClass = collectionClass;
                }

                isEnumerator = beanClass.IsGenericEnumerator();
                Type enumerator = null;
                if (isEnumerator) {
                    enumerator = TypeHelper.GetGenericReturnType(methodReflection, true);
                    beanClass = enumerator;
                }

                // If the method returns a Map, look up the map type
                string mapTypeName = null;
                if (methodReflection.ReturnType.IsGenericDictionary() ||
                    methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType().IsGenericDictionary() ||
                    isCollection && collectionClass.IsGenericDictionary() ||
                    isEnumerator && enumerator.IsGenericDictionary()) {
                    MethodMetadataDesc metadata;
                    if (variableMetaData != null) {
                        metadata = GetCheckMetadataVariable(
                            methodStreamSpec.MethodName,
                            variableMetaData,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }
                    else {
                        metadata = GetCheckMetadataNonVariable(
                            methodStreamSpec.MethodName,
                            methodStreamSpec.ClassName,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }

                    mapTypeName = metadata.TypeName;
                    mapType = (IDictionary<string, object>) metadata.TypeMetadata;
                }

                // If the method returns an Object[] or Object[][], look up the type information
                string oaTypeName = null;
                if (methodReflection.ReturnType == typeof(object[]) ||
                    methodReflection.ReturnType == typeof(object[][]) ||
                    isCollection && collectionClass == typeof(object[]) ||
                    isEnumerator && enumerator == typeof(object[])) {
                    MethodMetadataDesc metadata;
                    if (variableMetaData != null) {
                        metadata = GetCheckMetadataVariable(
                            methodStreamSpec.MethodName,
                            variableMetaData,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }
                    else {
                        metadata = GetCheckMetadataNonVariable(
                            methodStreamSpec.MethodName,
                            methodStreamSpec.ClassName,
                            classpathImportService,
                            typeof(IDictionary<string, object>));
                    }

                    oaTypeName = metadata.TypeName;
                    oaType = (IDictionary<string, object>) metadata.TypeMetadata;
                }

                // Determine event type from class and method name
                // If the method returns EventBean[], require the event type
                Func<EventTypeApplicationType, EventTypeMetadata> metadataFunction = apptype => {
                    var eventTypeName = services.EventTypeNameGeneratorStatement.GetAnonymousMethodHistorical(stream);
                    return new EventTypeMetadata(
                        eventTypeName,
                        @base.ModuleName,
                        EventTypeTypeClass.METHODPOLLDERIVED,
                        apptype,
                        NameAccessModifier.TRANSIENT,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());
                };
                if (methodReflection.ReturnType.IsArray &&
                    methodReflection.ReturnType.GetElementType() == typeof(EventBean) ||
                    isCollection && collectionClass == typeof(EventBean) ||
                    isEnumerator && enumerator == typeof(EventBean)) {
                    var typeName = methodStreamSpec.EventTypeName == null
                        ? eventTypeNameProvidedUDFOrScript
                        : methodStreamSpec.EventTypeName;
                    eventType = EventTypeUtility.RequireEventType(
                        "Method",
                        methodReflection.Name,
                        typeName,
                        services.EventTypeCompileTimeResolver);
                    eventTypeWhenMethodReturnsEventBeans = eventType;
                }
                else if (mapType != null) {
                    eventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                        metadataFunction.Invoke(EventTypeApplicationType.MAP),
                        mapType,
                        null,
                        null,
                        null,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }
                else if (oaType != null) {
                    eventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                        metadataFunction.Invoke(EventTypeApplicationType.OBJECTARR),
                        oaType,
                        null,
                        null,
                        null,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }
                else {
                    var stem = services.BeanEventTypeStemService.GetCreateStem(beanClass, null);
                    eventType = new BeanEventType(
                        services.Container,
                        stem,
                        metadataFunction.Invoke(EventTypeApplicationType.CLASS),
                        services.BeanEventTypeFactoryPrivate,
                        null,
                        null,
                        null,
                        null);
                    services.EventTypeCompileTimeRegistry.NewType(eventType);
                }

                // the @type is only allowed in conjunction with EventBean return types
                if (methodStreamSpec.EventTypeName != null && eventTypeWhenMethodReturnsEventBeans == null) {
                    throw new ExprValidationException(EventTypeUtility.DisallowedAtTypeMessage());
                }
            }
            else {
                var eventTypeName = methodStreamSpec.EventTypeName == null
                    ? scriptExpression.EventTypeNameAnnotation
                    : methodStreamSpec.EventTypeName;
                eventType = EventTypeUtility.RequireEventType(
                    "Script",
                    scriptExpression.Script.Name,
                    eventTypeName,
                    services.EventTypeCompileTimeResolver);
            }

            // metadata
            var meta = new MethodPollingViewableMeta(
                methodProviderClass,
                isStaticMethod,
                mapType,
                oaType,
                strategy,
                isCollection,
                isEnumerator,
                variableMetaData,
                eventTypeWhenMethodReturnsEventBeans,
                scriptExpression);
            return new HistoricalEventViewableMethodForge(stream, eventType, methodStreamSpec, meta);
        }
Ejemplo n.º 22
0
 public StmtForgeMethodUpdate(StatementBaseInfo @base)
 {
     this.@base = @base;
 }
Ejemplo n.º 23
0
 public StmtForgeMethodOnTrigger(StatementBaseInfo @base)
 {
     this.@base = @base;
 }
Ejemplo n.º 24
0
        private static AggregationServiceForgeDesc[] PlanAggregations(
            IList<ExprAggregateNode> measureAggregateExprNodes,
            StreamTypeService compositeTypeServiceMeasure,
            string[] allStreamNames,
            EventType[] allTypes,
            IOrderedDictionary<int, string> streamVariables,
            ISet<string> variablesMultiple,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            IDictionary<int, IList<ExprAggregateNode>> measureExprAggNodesPerStream =
                new Dictionary<int, IList<ExprAggregateNode>>();

            foreach (var aggregateNode in measureAggregateExprNodes) {
                // validate node and params
                var count = 0;
                var visitor = new ExprNodeIdentifierVisitor(true);
                var isIStreamOnly = new bool[allStreamNames.Length];
                var typeServiceAggregateMeasure = new StreamTypeServiceImpl(
                    allTypes,
                    allStreamNames,
                    isIStreamOnly,
                    false,
                    true);

                var validationContext =
                    new ExprValidationContextBuilder(typeServiceAggregateMeasure, @base.StatementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                aggregateNode.ValidatePositionals(validationContext);

                if (aggregateNode.OptionalLocalGroupBy != null) {
                    throw new ExprValidationException(
                        "Match-recognize does not allow aggregation functions to specify a group-by");
                }

                foreach (var child in aggregateNode.ChildNodes) {
                    var validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.MATCHRECOGMEASURE,
                        child,
                        validationContext);
                    validated.Accept(visitor);
                    aggregateNode.SetChildNode(count++, new ExprNodeValidated(validated));
                }

                // verify properties used within the aggregation
                ISet<int> aggregatedStreams = new HashSet<int>();
                foreach (var pair in visitor.ExprProperties) {
                    aggregatedStreams.Add(pair.First);
                }

                int? multipleVarStream = null;
                foreach (var streamNumAggregated in aggregatedStreams) {
                    var variable = streamVariables.Get(streamNumAggregated);
                    if (variablesMultiple.Contains(variable)) {
                        if (multipleVarStream == null) {
                            multipleVarStream = streamNumAggregated;
                            continue;
                        }

                        throw new ExprValidationException(
                            "Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events");
                    }
                }

                if (multipleVarStream == null) {
                    throw new ExprValidationException(
                        "Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events");
                }

                var aggNodesForStream = measureExprAggNodesPerStream.Get(multipleVarStream.Value);
                if (aggNodesForStream == null) {
                    aggNodesForStream = new List<ExprAggregateNode>();
                    measureExprAggNodesPerStream.Put(multipleVarStream.Value, aggNodesForStream);
                }

                aggNodesForStream.Add(aggregateNode);
            }

            // validate aggregation itself
            foreach (var entry in measureExprAggNodesPerStream) {
                foreach (var aggregateNode in entry.Value) {
                    var validationContext = new ExprValidationContextBuilder(
                            compositeTypeServiceMeasure,
                            @base.StatementRawInfo,
                            services)
                        .WithAllowBindingConsumption(true)
                        .WithMemberName(new ExprValidationMemberNameQualifiedRowRecogAgg(entry.Key))
                        .Build();
                    aggregateNode.Validate(validationContext);
                }
            }

            // get aggregation service per variable
            var aggServices = new AggregationServiceForgeDesc[allStreamNames.Length];
            var declareds = Arrays.AsList(@base.StatementSpec.DeclaredExpressions);
            foreach (var entry in measureExprAggNodesPerStream) {
                EventType[] typesPerStream = {allTypes[entry.Key]};
                AggregationServiceForgeDesc desc = AggregationServiceFactoryFactory.GetService(
                    entry.Value,
                    EmptyDictionary<ExprNode, string>.Instance, 
                    declareds,
                    new ExprNode[0],
                    null,
                    EmptyList<ExprAggregateNode>.Instance,
                    EmptyList<ExprAggregateNode>.Instance,
                    EmptyList<ExprAggregateNodeGroupKey>.Instance,
                    false,
                    @base.StatementRawInfo.Annotations,
                    services.VariableCompileTimeResolver,
                    true,
                    null,
                    null,
                    typesPerStream,
                    null,
                    @base.ContextName,
                    null,
                    services.TableCompileTimeResolver,
                    false,
                    true,
                    false,
                    services.ImportServiceCompileTime,
                    @base.StatementRawInfo,
                    services.SerdeResolver);

                aggServices[entry.Key] = desc;
            }

            return aggServices;
        }
Ejemplo n.º 25
0
        public static RowRecogPlan ValidateAndPlan(
            IContainer container,
            EventType parentEventType,
            bool unbound,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var statementRawInfo = @base.StatementRawInfo;
            var matchRecognizeSpec = @base.StatementSpec.Raw.MatchRecognizeSpec;
            var annotations = statementRawInfo.Annotations;
            var iterateOnly = HintEnum.ITERATE_ONLY.GetHint(annotations) != null;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            // Expanded pattern already there
            RowRecogExprNode expandedPatternNode = matchRecognizeSpec.Pattern;

            // Determine single-row and multiple-row variables
            var variablesSingle = new LinkedHashSet<string>();
            var variablesMultiple = new LinkedHashSet<string>();
            RowRecogHelper.RecursiveInspectVariables(expandedPatternNode, false, variablesSingle, variablesMultiple);

            // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
            var streamNum = 0;
            var variableStreams = new LinkedHashMap<string, Pair<int, bool>>();
            foreach (var variableSingle in variablesSingle) {
                variableStreams.Put(variableSingle, new Pair<int, bool>(streamNum, false));
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                variableStreams.Put(variableMultiple, new Pair<int, bool>(streamNum, true));
                streamNum++;
            }

            // mapping of stream to variable
            var streamVariables = new OrderedListDictionary<int, string>();
            foreach (var entry in variableStreams) {
                streamVariables.Put(entry.Value.First, entry.Key);
            }

            // determine visibility rules
            var visibility = RowRecogHelper.DetermineVisibility(expandedPatternNode);

            // assemble all single-row variables for expression validation
            var allStreamNames = new string[variableStreams.Count];
            var allTypes = new EventType[variableStreams.Count];

            streamNum = 0;
            foreach (var variableSingle in variablesSingle) {
                allStreamNames[streamNum] = variableSingle;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            foreach (var variableMultiple in variablesMultiple) {
                allStreamNames[streamNum] = variableMultiple;
                allTypes[streamNum] = parentEventType;
                streamNum++;
            }

            // determine type service for use with DEFINE
            // validate each DEFINE clause expression
            ISet<string> definedVariables = new HashSet<string>();
            IList<ExprAggregateNode> aggregateNodes = new List<ExprAggregateNode>();
            var isExprRequiresMultimatchState = new bool[variableStreams.Count];
            var previousNodes = new OrderedListDictionary<int, IList<ExprPreviousMatchRecognizeNode>>();

            for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++) {
                MatchRecognizeDefineItem defineItem = matchRecognizeSpec.Defines[defineIndex];
                if (definedVariables.Contains(defineItem.Identifier)) {
                    throw new ExprValidationException(
                        "Variable '" + defineItem.Identifier + "' has already been defined");
                }

                definedVariables.Add(defineItem.Identifier);

                // stream-type visibilities handled here
                var typeServiceDefines = BuildDefineStreamTypeServiceDefine(
                    defineIndex,
                    variableStreams,
                    defineItem,
                    visibility,
                    parentEventType,
                    statementRawInfo,
                    services);

                var exprNodeResult = HandlePreviousFunctions(defineItem.Expression, previousNodes);
                var validationContext = new ExprValidationContextBuilder(typeServiceDefines, statementRawInfo, services)
                    .WithAllowBindingConsumption(true)
                    .WithDisablePropertyExpressionEventCollCache(true)
                    .Build();

                ExprNode validated;
                try {
                    // validate
                    validated = ExprNodeUtilityValidate.GetValidatedSubtree(
                        ExprNodeOrigin.MATCHRECOGDEFINE,
                        exprNodeResult,
                        validationContext);

                    // check aggregates
                    defineItem.Expression = validated;
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(validated, aggregateNodes);
                    if (!aggregateNodes.IsEmpty()) {
                        throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
                    }
                }
                catch (ExprValidationException ex) {
                    throw new ExprValidationException(
                        "Failed to validate condition expression for variable '" +
                        defineItem.Identifier +
                        "': " +
                        ex.Message,
                        ex);
                }

                // determine access to event properties from multi-matches
                var visitor = new ExprNodeStreamRequiredVisitor();
                validated.Accept(visitor);
                var streamsRequired = visitor.StreamsRequired;
                foreach (var streamRequired in streamsRequired) {
                    if (streamRequired >= variableStreams.Count) {
                        var streamNumIdent = variableStreams.Get(defineItem.Identifier).First;
                        isExprRequiresMultimatchState[streamNumIdent] = true;
                        break;
                    }
                }
            }

            var defineAsksMultimatches = CollectionUtil.IsAnySet(isExprRequiresMultimatchState);

            // determine type service for use with MEASURE
            IDictionary<string, object> measureTypeDef = new LinkedHashMap<string, object>();
            foreach (var variableSingle in variablesSingle) {
                measureTypeDef.Put(variableSingle, parentEventType);
            }

            foreach (var variableMultiple in variablesMultiple) {
                measureTypeDef.Put(variableMultiple, new[] {parentEventType});
            }

            var compositeTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogCompositeName;
            var compositeTypeMetadata = new EventTypeMetadata(
                compositeTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.OBJECTARR,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var compositeEventType = BaseNestableEventUtil.MakeOATypeCompileTime(
                compositeTypeMetadata,
                measureTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(compositeEventType);
            StreamTypeService compositeTypeServiceMeasure =
                new StreamTypeServiceImpl(compositeEventType, "MATCH_RECOGNIZE", true);

            // find MEASURE clause aggregations
            var measureReferencesMultivar = false;
            IList<ExprAggregateNode> measureAggregateExprNodes = new List<ExprAggregateNode>();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes);
            }

            AggregationServiceForgeDesc[] aggregationServices = null;
            if (!measureAggregateExprNodes.IsEmpty()) {
                aggregationServices = PlanAggregations(
                    measureAggregateExprNodes,
                    compositeTypeServiceMeasure,
                    allStreamNames,
                    allTypes,
                    streamVariables,
                    variablesMultiple,
                    @base,
                    services);
                foreach (AggregationServiceForgeDesc svc in aggregationServices) {
                    if (svc != null) {
                        additionalForgeables.AddAll(svc.AdditionalForgeables);
                    }
                }
            }

            // validate each MEASURE clause expression
            IDictionary<string, object> rowTypeDef = new LinkedHashMap<string, object>();
            var streamRefVisitor = new ExprNodeStreamUseCollectVisitor();
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                if (measureItem.Name == null) {
                    throw new ExprValidationException(
                        "The measures clause requires that each expression utilizes the AS keyword to assign a column name");
                }

                var validated = ValidateMeasureClause(
                    measureItem.Expr,
                    compositeTypeServiceMeasure,
                    variablesMultiple,
                    variablesSingle,
                    statementRawInfo,
                    services);
                measureItem.Expr = validated;
                rowTypeDef.Put(measureItem.Name, validated.Forge.EvaluationType);
                validated.Accept(streamRefVisitor);
            }

            // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
            foreach (var @ref in streamRefVisitor.Referenced) {
                var rootPropName = @ref.RootPropertyNameIfAny;
                if (rootPropName != null) {
                    if (variablesMultiple.Contains(rootPropName)) {
                        measureReferencesMultivar = true;
                        break;
                    }
                }

                var streamRequired = @ref.StreamReferencedIfAny;
                if (streamRequired != null) {
                    var streamVariable = streamVariables.Get(streamRequired.Value);
                    if (streamVariable != null) {
                        var def = variableStreams.Get(streamVariable);
                        if (def != null && def.Second) {
                            measureReferencesMultivar = true;
                            break;
                        }
                    }
                }
            }

            var collectMultimatches = measureReferencesMultivar || defineAsksMultimatches;

            // create rowevent type
            var rowTypeName = services.EventTypeNameGeneratorStatement.AnonymousRowrecogRowName;
            var rowTypeMetadata = new EventTypeMetadata(
                rowTypeName,
                @base.ModuleName,
                EventTypeTypeClass.MATCHRECOGDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var rowEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                rowTypeMetadata,
                rowTypeDef,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(rowEventType);

            // validate partition-by expressions, if any
            ExprNode[] partitionBy;
            MultiKeyClassRef partitionMultiKey;
            if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty()) {
                StreamTypeService typeServicePartition = new StreamTypeServiceImpl(
                    parentEventType,
                    "MATCH_RECOGNIZE_PARTITION",
                    true);
                IList<ExprNode> validated = new List<ExprNode>();
                var validationContext =
                    new ExprValidationContextBuilder(typeServicePartition, statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions) {
                    validated.Add(
                        ExprNodeUtilityValidate.GetValidatedSubtree(
                            ExprNodeOrigin.MATCHRECOGPARTITION,
                            partitionExpr,
                            validationContext));
                }

                matchRecognizeSpec.PartitionByExpressions = validated;
                partitionBy = ExprNodeUtilityQuery.ToArray(validated);
                MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey(partitionBy, false, @base.StatementRawInfo, services.SerdeResolver);
                partitionMultiKey = multiKeyPlan.ClassRef;
                additionalForgeables.AddAll(multiKeyPlan.MultiKeyForgeables);
            }
            else {
                partitionBy = null;
                partitionMultiKey = null;
            }

            // validate interval if present
            if (matchRecognizeSpec.Interval != null) {
                var validationContext =
                    new ExprValidationContextBuilder(new StreamTypeServiceImpl(false), statementRawInfo, services)
                        .WithAllowBindingConsumption(true)
                        .Build();
                var validated = (ExprTimePeriod) ExprNodeUtilityValidate.GetValidatedSubtree(
                    ExprNodeOrigin.MATCHRECOGINTERVAL,
                    matchRecognizeSpec.Interval.TimePeriodExpr,
                    validationContext);
                matchRecognizeSpec.Interval.TimePeriodExpr = validated;
            }

            // compile variable definition expressions
            IDictionary<string, ExprNode> variableDefinitions = new Dictionary<string, ExprNode>();
            foreach (var defineItem in matchRecognizeSpec.Defines) {
                variableDefinitions.Put(defineItem.Identifier, defineItem.Expression);
            }

            // create evaluators
            var columnNames = new string[matchRecognizeSpec.Measures.Count];
            var columnForges = new ExprNode[matchRecognizeSpec.Measures.Count];
            var count = 0;
            foreach (var measureItem in matchRecognizeSpec.Measures) {
                columnNames[count] = measureItem.Name;
                columnForges[count] = measureItem.Expr;
                count++;
            }

            // build states
            var strand = RowRecogHelper.BuildStartStates(
                expandedPatternNode,
                variableDefinitions,
                variableStreams,
                isExprRequiresMultimatchState);
            var startStates = strand.StartStates.ToArray();
            RowRecogNFAStateForge[] allStates = strand.AllStates.ToArray();

            if (Log.IsInfoEnabled) {
                Log.Info("NFA tree:\n" + RowRecogNFAViewUtil.Print(startStates));
            }

            // determine names of multimatching variables
            string[] multimatchVariablesArray;
            int[] multimatchStreamNumToVariable;
            int[] multimatchVariableToStreamNum;
            if (variablesSingle.Count == variableStreams.Count) {
                multimatchVariablesArray = new string[0];
                multimatchStreamNumToVariable = new int[0];
                multimatchVariableToStreamNum = new int[0];
            }
            else {
                multimatchVariablesArray = new string[variableStreams.Count - variablesSingle.Count];
                multimatchVariableToStreamNum = new int[multimatchVariablesArray.Length];
                multimatchStreamNumToVariable = new int[variableStreams.Count];
                CompatExtensions.Fill(multimatchStreamNumToVariable, -1);
                count = 0;
                foreach (var entry in variableStreams) {
                    if (entry.Value.Second) {
                        var index = count;
                        multimatchVariablesArray[index] = entry.Key;
                        multimatchVariableToStreamNum[index] = entry.Value.First;
                        multimatchStreamNumToVariable[entry.Value.First] = index;
                        count++;
                    }
                }
            }

            var numEventsEventsPerStreamDefine =
                defineAsksMultimatches ? variableStreams.Count + 1 : variableStreams.Count;

            // determine interval-or-terminated
            var orTerminated = matchRecognizeSpec.Interval != null && matchRecognizeSpec.Interval.IsOrTerminated;
            TimePeriodComputeForge intervalCompute = null;
            if (matchRecognizeSpec.Interval != null) {
                intervalCompute = matchRecognizeSpec.Interval.TimePeriodExpr.TimePeriodComputeForge;
            }

            EventType multimatchEventType = null;
            if (defineAsksMultimatches) {
                multimatchEventType = GetDefineMultimatchEventType(variableStreams, parentEventType, @base, services);
            }

            // determine previous-access indexes and assign "prev" node indexes
            // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
            // Map the expression-supplied index to a relative index
            int[] previousRandomAccessIndexes = null;
            if (!previousNodes.IsEmpty()) {
                previousRandomAccessIndexes = new int[previousNodes.Count];
                var countPrev = 0;
                foreach (var entry in previousNodes) {
                    previousRandomAccessIndexes[countPrev] = entry.Key;
                    foreach (var callback in entry.Value) {
                        callback.AssignedIndex = countPrev;
                    }

                    countPrev++;
                }
            }

            RowRecogDescForge forge = new RowRecogDescForge(
                parentEventType,
                rowEventType,
                compositeEventType,
                multimatchEventType,
                multimatchStreamNumToVariable,
                multimatchVariableToStreamNum,
                partitionBy,
                partitionMultiKey,
                variableStreams,
                matchRecognizeSpec.Interval != null,
                iterateOnly,
                unbound,
                orTerminated,
                collectMultimatches,
                defineAsksMultimatches,
                numEventsEventsPerStreamDefine,
                multimatchVariablesArray,
                startStates,
                allStates,
                matchRecognizeSpec.IsAllMatches,
                matchRecognizeSpec.Skip.Skip,
                columnForges,
                columnNames,
                intervalCompute,
                previousRandomAccessIndexes,
                aggregationServices);
            
            return new RowRecogPlan(forge, additionalForgeables);
        }
Ejemplo n.º 26
0
 public StmtForgeMethodCreateContext(StatementBaseInfo @base)
 {
     this.@base = @base;
 }
Ejemplo n.º 27
0
        public static OnTriggerPlanValidationResult ValidateOnTriggerPlan(
            EventType namedWindowOrTableType,
            OnTriggerWindowDesc onTriggerDesc,
            StreamSpecCompiled streamSpec,
            OnTriggerActivatorDesc activatorResult,
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var zeroStreamAliasName = onTriggerDesc.OptionalAsName;
            if (zeroStreamAliasName == null) {
                zeroStreamAliasName = "stream_0";
            }

            var streamName = streamSpec.OptionalStreamName;
            if (streamName == null) {
                streamName = "stream_1";
            }

            var namedWindowTypeName = onTriggerDesc.WindowName;

            // Materialize sub-select views
            // 0 - named window stream
            // 1 - arriving stream
            // 2 - initial value before update
            string[] subselectStreamNames = {zeroStreamAliasName, streamSpec.OptionalStreamName};
            EventType[] subselectEventTypes = {namedWindowOrTableType, activatorResult.ActivatorResultEventType};
            string[] subselectEventTypeNames = {namedWindowTypeName, activatorResult.TriggerEventTypeName};
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                subselectStreamNames,
                subselectEventTypes,
                subselectEventTypeNames,
                services);

            var typeService = new StreamTypeServiceImpl(
                new[] {namedWindowOrTableType, activatorResult.ActivatorResultEventType},
                new[] {zeroStreamAliasName, streamName},
                new[] {false, true},
                true,
                false);

            // allow "initial" as a prefix to properties
            StreamTypeServiceImpl assignmentTypeService;
            if (zeroStreamAliasName.Equals(INITIAL_VALUE_STREAM_NAME) || streamName.Equals(INITIAL_VALUE_STREAM_NAME)) {
                assignmentTypeService = typeService;
            }
            else {
                assignmentTypeService = new StreamTypeServiceImpl(
                    new[] {namedWindowOrTableType, activatorResult.ActivatorResultEventType, namedWindowOrTableType},
                    new[] {zeroStreamAliasName, streamName, INITIAL_VALUE_STREAM_NAME},
                    new[] {false, true, true},
                    false,
                    false);
                assignmentTypeService.IsStreamZeroUnambigous = true;
            }

            if (onTriggerDesc is OnTriggerWindowUpdateDesc) {
                var updateDesc = (OnTriggerWindowUpdateDesc) onTriggerDesc;
                var validationContext = new ExprValidationContextBuilder(
                        assignmentTypeService,
                        @base.StatementRawInfo,
                        services)
                    .WithAllowBindingConsumption(true)
                    .Build();
                foreach (var assignment in updateDesc.Assignments) {
                    var validated = ExprNodeUtilityValidate.GetValidatedAssignment(assignment, validationContext);
                    assignment.Expression = validated;
                    EPStatementStartMethodHelperValidate.ValidateNoAggregations(
                        validated,
                        "Aggregation functions may not be used within an on-update-clause");
                }
            }

            if (onTriggerDesc is OnTriggerMergeDesc) {
                var mergeDesc = (OnTriggerMergeDesc) onTriggerDesc;
                ValidateMergeDesc(
                    mergeDesc,
                    namedWindowOrTableType,
                    zeroStreamAliasName,
                    activatorResult.ActivatorResultEventType,
                    streamName,
                    @base.StatementRawInfo,
                    services);
            }

            // validate join expression
            var validatedJoin = ValidateJoinNamedWindow(
                ExprNodeOrigin.WHERE,
                @base.StatementSpec.Raw.WhereClause,
                namedWindowOrTableType,
                zeroStreamAliasName,
                namedWindowTypeName,
                activatorResult.ActivatorResultEventType,
                streamName,
                activatorResult.TriggerEventTypeName,
                null,
                @base.StatementRawInfo,
                services);

            // validate filter, output rate limiting
            EPStatementStartMethodHelperValidate.ValidateNodes(
                @base.StatementSpec.Raw,
                typeService,
                null,
                @base.StatementRawInfo,
                services);

            // Construct a processor for results; for use in on-select to process selection results
            // Use a wildcard select if the select-clause is empty, such as for on-delete.
            // For on-select the select clause is not empty.
            if (@base.StatementSpec.SelectClauseCompiled.SelectExprList.Length == 0) {
                @base.StatementSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard());
            }

            var resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                new ResultSetSpec(@base.StatementSpec),
                typeService,
                null,
                new bool[0],
                true,
                @base.ContextPropertyRegistry,
                false,
                true,
                @base.StatementRawInfo,
                services);

            // plan table access
            var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);

            return new OnTriggerPlanValidationResult(
                subselectForges,
                tableAccessForges,
                resultSetProcessorPrototype,
                validatedJoin,
                zeroStreamAliasName);
        }
Ejemplo n.º 28
0
        public static OnTriggerPlan HandleSplitStream(
            string aiFactoryProviderClassName,
            CodegenNamespaceScope namespaceScope,
            string classPostfix,
            OnTriggerSplitStreamDesc desc,
            StreamSpecCompiled streamSpec,
            OnTriggerActivatorDesc activatorResult,
            IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation,
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var raw = @base.StatementSpec.Raw;
            if (raw.InsertIntoDesc == null) {
                throw new ExprValidationException(
                    "Required insert-into clause is not provided, the clause is required for split-stream syntax");
            }

            if (raw.GroupByExpressions != null && raw.GroupByExpressions.Count > 0 ||
                raw.HavingClause != null ||
                raw.OrderByList.Count > 0) {
                throw new ExprValidationException(
                    "A group-by clause, having-clause or order-by clause is not allowed for the split stream syntax");
            }

            var streamName = streamSpec.OptionalStreamName;
            if (streamName == null) {
                streamName = "stream_0";
            }

            StreamTypeService typeServiceTrigger = new StreamTypeServiceImpl(
                new[] {activatorResult.ActivatorResultEventType},
                new[] {streamName},
                new[] {true},
                false,
                false);

            // materialize sub-select views
            var subselectForges = SubSelectHelperForgePlanner.PlanSubSelect(
                @base,
                subselectActivation,
                new[] {streamSpec.OptionalStreamName},
                new[] {activatorResult.ActivatorResultEventType},
                new[] {activatorResult.TriggerEventTypeName},
                services);

            // compile top-level split
            var items = new OnSplitItemForge[desc.SplitStreams.Count + 1];
            items[0] = OnSplitValidate(
                typeServiceTrigger,
                @base.StatementSpec,
                @base.ContextPropertyRegistry,
                null,
                @base.StatementRawInfo,
                services);

            // compile each additional split
            var index = 1;
            foreach (var splits in desc.SplitStreams) {
                var splitSpec = new StatementSpecCompiled();

                splitSpec.Raw.InsertIntoDesc = splits.InsertInto;
                splitSpec.SelectClauseCompiled = CompileSelectAllowSubselect(splits.SelectClause);
                splitSpec.Raw.WhereClause = splits.WhereClause;

                PropertyEvaluatorForge optionalPropertyEvaluator = null;
                StreamTypeService typeServiceProperty;
                if (splits.FromClause != null) {
                    optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        splits.FromClause.PropertyEvalSpec,
                        activatorResult.ActivatorResultEventType,
                        streamName,
                        @base.StatementRawInfo,
                        services);
                    typeServiceProperty = new StreamTypeServiceImpl(
                        new[] {optionalPropertyEvaluator.FragmentEventType},
                        new[] {splits.FromClause.OptionalStreamName},
                        new[] {true},
                        false,
                        false);
                }
                else {
                    typeServiceProperty = typeServiceTrigger;
                }

                items[index] = OnSplitValidate(
                    typeServiceProperty,
                    splitSpec,
                    @base.ContextPropertyRegistry,
                    optionalPropertyEvaluator,
                    @base.StatementRawInfo,
                    services);
                index++;
            }

            // handle result set processor classes
            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();
            for (var i = 0; i < items.Length; i++) {
                var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple(
                    typeof(ResultSetProcessorFactoryProvider),
                    classPostfix + "_" + i);
                forgables.Add(
                    new StmtClassForgableRSPFactoryProvider(
                        classNameRSP,
                        items[i].ResultSetProcessorDesc,
                        namespaceScope,
                        @base.StatementRawInfo));
                items[i].ResultSetProcessorClassName = classNameRSP;
            }

            // plan table access
            var tableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(@base.StatementSpec.TableAccessNodes);

            // build forge
            var splitStreamForge = new StatementAgentInstanceFactoryOnTriggerSplitStreamForge(
                activatorResult.Activator,
                activatorResult.ActivatorResultEventType,
                subselectForges,
                tableAccessForges,
                items,
                desc.IsFirst);
            var triggerForge = new StmtClassForgableAIFactoryProviderOnTrigger(
                aiFactoryProviderClassName,
                namespaceScope,
                splitStreamForge);

            return new OnTriggerPlan(triggerForge, forgables, new SelectSubscriberDescriptor());
        }
        public SubSelectStrategyFactoryIndexShareForge(
            int subqueryNumber,
            SubSelectActivationPlan subselectActivation,
            EventType[] outerEventTypesSelect,
            NamedWindowMetaData namedWindow,
            TableMetaData table,
            bool fullTableScan,
            IndexHint indexHint,
            SubordPropPlan joinedPropPlan,
            ExprForge filterExprEval,
            ExprNode[] groupKeys,
            AggregationServiceForgeDesc aggregationServiceForgeDesc,
            StatementBaseInfo statement,
            StatementCompileTimeServices services)
        {
            _subqueryNumber = subqueryNumber;
            _namedWindow    = namedWindow;
            _table          = table;
            _filterExprEval = filterExprEval;
            _groupKeys      = groupKeys;
            _aggregationServiceForgeDesc = aggregationServiceForgeDesc;

            bool queryPlanLogging = services.Configuration.Common.Logging.IsEnableQueryPlan;

            // We only use existing indexes in all cases. This means "create index" is required.
            SubordinateQueryPlan plan;

            if (table != null)
            {
                plan = SubordinateQueryPlanner.PlanSubquery(
                    outerEventTypesSelect,
                    joinedPropPlan,
                    false,
                    fullTableScan,
                    indexHint,
                    true,
                    subqueryNumber,
                    false,
                    table.IndexMetadata,
                    table.UniquenessAsSet,
                    true,
                    table.InternalEventType,
                    statement.StatementRawInfo,
                    services);
            }
            else
            {
                plan = SubordinateQueryPlanner.PlanSubquery(
                    outerEventTypesSelect,
                    joinedPropPlan,
                    false,
                    fullTableScan,
                    indexHint,
                    true,
                    subqueryNumber,
                    namedWindow.IsVirtualDataWindow,
                    namedWindow.IndexMetadata,
                    namedWindow.UniquenessAsSet,
                    true,
                    namedWindow.EventType,
                    statement.StatementRawInfo,
                    services);
            }

            _queryPlan = plan == null ? null : plan.Forge;
            if (plan != null)
            {
                _additionalForgeables.AddAll(plan.AdditionalForgeables);
            }

            if (_queryPlan != null && _queryPlan.IndexDescs != null)
            {
                for (int i = 0; i < _queryPlan.IndexDescs.Length; i++)
                {
                    SubordinateQueryIndexDescForge index = _queryPlan.IndexDescs[i];

                    if (table != null)
                    {
                        if (table.TableVisibility == NameAccessModifier.PUBLIC)
                        {
                            services.ModuleDependenciesCompileTime.AddPathIndex(
                                false,
                                table.TableName,
                                table.TableModuleName,
                                index.IndexName,
                                index.IndexModuleName,
                                services.NamedWindowCompileTimeRegistry,
                                services.TableCompileTimeRegistry);
                        }
                    }
                    else
                    {
                        if (namedWindow.EventType.Metadata.AccessModifier == NameAccessModifier.PUBLIC)
                        {
                            services.ModuleDependenciesCompileTime.AddPathIndex(
                                true,
                                namedWindow.EventType.Name,
                                namedWindow.NamedWindowModuleName,
                                index.IndexName,
                                index.IndexModuleName,
                                services.NamedWindowCompileTimeRegistry,
                                services.TableCompileTimeRegistry);
                        }
                    }
                }
            }

            SubordinateQueryPlannerUtil.QueryPlanLogOnSubq(
                queryPlanLogging,
                QUERY_PLAN_LOG,
                _queryPlan,
                subqueryNumber,
                statement.StatementRawInfo.Annotations,
                services.ImportServiceCompileTime);

            if (groupKeys == null || groupKeys.Length == 0)
            {
                _groupByMultiKey = null;
            }
            else
            {
                MultiKeyPlan mkplan = MultiKeyPlanner.PlanMultiKey(groupKeys, false, statement.StatementRawInfo, services.SerdeResolver);
                _additionalForgeables.AddAll(mkplan.MultiKeyForgeables);
                _groupByMultiKey = mkplan.ClassRef;
            }
        }
Ejemplo n.º 30
0
        public static ConfigurationCommonEventTypeXMLDOM Configure(
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var config      = new ConfigurationCommonEventTypeXMLDOM();
            var annotations = @base.StatementRawInfo.Annotations;

            var schemaAnnotations = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaAttribute));

            if (schemaAnnotations == null || schemaAnnotations.IsEmpty())
            {
                throw new ExprValidationException("Required annotation @" + nameof(XMLSchemaAttribute) + " could not be found");
            }

            if (schemaAnnotations.Count > 1)
            {
                throw new ExprValidationException("Found multiple @" + nameof(XMLSchemaAttribute) + " annotations but expected a single annotation");
            }

            var schema = (XMLSchemaAttribute)schemaAnnotations[0];

            if (string.IsNullOrEmpty(schema.RootElementName))
            {
                throw new ExprValidationException(
                          "Required annotation field 'RootElementName' for annotation @" + nameof(XMLSchemaAttribute) + " could not be found");
            }

            config.RootElementName                  = schema.RootElementName.Trim();
            config.SchemaResource                   = NullIfEmpty(schema.SchemaResource);
            config.SchemaText                       = NullIfEmpty(schema.SchemaText);
            config.IsXPathPropertyExpr              = schema.XPathPropertyExpr;
            config.DefaultNamespace                 = schema.DefaultNamespace;
            config.IsEventSenderValidatesRoot       = schema.EventSenderValidatesRoot;
            config.IsAutoFragment                   = schema.AutoFragment;
            config.XPathFunctionResolver            = NullIfEmpty(schema.XPathFunctionResolver);
            config.XPathVariableResolver            = NullIfEmpty(schema.XPathVariableResolver);
            config.IsXPathResolvePropertiesAbsolute = schema.XPathResolvePropertiesAbsolute;
            config.RootElementNamespace             = NullIfEmpty(schema.RootElementNamespace);

            var prefixes = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaNamespacePrefixAttribute));

            foreach (var prefixAnnotation in prefixes)
            {
                var prefix = (XMLSchemaNamespacePrefixAttribute)prefixAnnotation;
                config.AddNamespacePrefix(prefix.Prefix, prefix.Namespace);
            }

            var fields = AnnotationUtil.FindAnnotations(annotations, typeof(XMLSchemaFieldAttribute));

            foreach (var fieldAnnotation in fields)
            {
                var field = (XMLSchemaFieldAttribute)fieldAnnotation;
                var rtype = GetResultType(field.Type);
                if (string.IsNullOrWhiteSpace(field.EventTypeName))
                {
                    var castToType = NullIfEmpty(field.CastToType);
                    config.AddXPathProperty(field.Name, field.XPath, rtype, castToType);
                }
                else
                {
                    config.AddXPathPropertyFragment(field.Name, field.XPath, rtype, field.EventTypeName);
                }
            }

            return(config);
        }