Exemple #1
0
        // The create window command:
        //      create window windowName[.window_view_list] as [select properties from] type
        //
        // This section expected s single FilterStreamSpecCompiled representing the selected type.
        // It creates a new event type representing the window type and a sets the type selected on the filter stream spec.
        protected internal static CreateWindowCompileResult HandleCreateWindow(
            StatementBaseInfo @base,
            StatementCompileTimeServices services)
        {
            var createWindowDesc = @base.StatementSpec.Raw.CreateWindowDesc;
            var columns = createWindowDesc.Columns;
            var typeName = createWindowDesc.WindowName;
            EventType targetType;

            // determine that the window name is not already in use as an event type name
            var existingType = services.EventTypeCompileTimeResolver.GetTypeByName(typeName);
            if (existingType != null && existingType.Metadata.TypeClass != EventTypeTypeClass.NAMED_WINDOW) {
                throw new ExprValidationException(
                    "Error starting statement: An event type or schema by name '" + typeName + "' already exists");
            }

            // Determine select-from
            var optionalSelectFrom = GetOptionalSelectFrom(createWindowDesc, services);

            // Create Map or Wrapper event type from the select clause of the window.
            // If no columns selected, simply create a wrapper type
            // Build a list of properties
            var newSelectClauseSpecRaw = new SelectClauseSpecRaw();
            LinkedHashMap<string, object> properties;
            var hasProperties = false;
            if (columns != null && !columns.IsEmpty()) {
                properties = EventTypeUtility.BuildType(
                    columns,
                    null,
                    services.ImportServiceCompileTime,
                    services.EventTypeCompileTimeResolver);
                hasProperties = true;
            }
            else {
                if (optionalSelectFrom == null) {
                    throw new IllegalStateException("Missing from-type information for create-window");
                }

                // Validate the select expressions which consists of properties only
                var select = CompileLimitedSelect(optionalSelectFrom, @base, services);

                properties = new LinkedHashMap<string, object>();
                foreach (var selectElement in select) {
                    if (selectElement.FragmentType != null) {
                        properties.Put(selectElement.AssignedName, selectElement.FragmentType);
                    }
                    else {
                        properties.Put(selectElement.AssignedName, selectElement.SelectExpressionType);
                    }

                    // Add any properties to the new select clause for use by consumers to the statement itself
                    newSelectClauseSpecRaw.Add(
                        new SelectClauseExprRawSpec(new ExprIdentNodeImpl(selectElement.AssignedName), null, false));
                    hasProperties = true;
                }
            }

            // Create Map or Wrapper event type from the select clause of the window.
            // If no columns selected, simply create a wrapper type
            var isOnlyWildcard = @base.StatementSpec.Raw.SelectClauseSpec.IsOnlyWildcard;
            var isWildcard = @base.StatementSpec.Raw.SelectClauseSpec.IsUsingWildcard;
            var namedWindowVisibility = services.ModuleVisibilityRules.GetAccessModifierNamedWindow(@base, typeName);
            try {
                if (isWildcard && !isOnlyWildcard) {
                    var metadata = new EventTypeMetadata(
                        typeName,
                        @base.ModuleName,
                        EventTypeTypeClass.NAMED_WINDOW,
                        EventTypeApplicationType.WRAPPER,
                        namedWindowVisibility,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());
                    targetType = WrapperEventTypeUtil.MakeWrapper(
                        metadata,
                        optionalSelectFrom.EventType,
                        properties,
                        null,
                        services.BeanEventTypeFactoryPrivate,
                        services.EventTypeCompileTimeResolver);
                }
                else {
                    // Some columns selected, use the types of the columns
                    Func<EventTypeApplicationType, EventTypeMetadata> metadata = type => new EventTypeMetadata(
                        typeName,
                        @base.ModuleName,
                        EventTypeTypeClass.NAMED_WINDOW,
                        type,
                        namedWindowVisibility,
                        EventTypeBusModifier.NONBUS,
                        false,
                        EventTypeIdPair.Unassigned());

                    if (hasProperties && !isOnlyWildcard) {
                        var compiledProperties = EventTypeUtility.CompileMapTypeProperties(
                            properties,
                            services.EventTypeCompileTimeResolver);
                        var representation = EventRepresentationUtil.GetRepresentation(
                            @base.StatementSpec.Annotations,
                            services.Configuration,
                            AssignedType.NONE);

                        if (representation == EventUnderlyingType.MAP) {
                            targetType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.MAP),
                                compiledProperties,
                                null,
                                null,
                                null,
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (representation == EventUnderlyingType.OBJECTARRAY) {
                            targetType = BaseNestableEventUtil.MakeOATypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                                compiledProperties,
                                null,
                                null,
                                null,
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (representation == EventUnderlyingType.AVRO) {
                            targetType = services.EventTypeAvroHandler.NewEventTypeFromNormalized(
                                metadata.Invoke(EventTypeApplicationType.AVRO),
                                services.EventTypeCompileTimeResolver,
                                services.BeanEventTypeFactoryPrivate.EventBeanTypedEventFactory,
                                compiledProperties,
                                @base.StatementRawInfo.Annotations,
                                null,
                                null,
                                null,
                                @base.StatementName);
                        }
                        else {
                            throw new IllegalStateException("Unrecognized representation " + representation);
                        }
                    }
                    else {
                        if (optionalSelectFrom == null) {
                            throw new IllegalStateException("Missing from-type information for create-window");
                        }

                        var selectFromType = optionalSelectFrom.EventType;

                        // No columns selected, no wildcard, use the type as is or as a wrapped type
                        if (selectFromType is ObjectArrayEventType) {
                            var oaType = (ObjectArrayEventType) selectFromType;
                            targetType = BaseNestableEventUtil.MakeOATypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.OBJECTARR),
                                oaType.Types,
                                null,
                                null,
                                oaType.StartTimestampPropertyName,
                                oaType.EndTimestampPropertyName,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (selectFromType is AvroSchemaEventType) {
                            var avroSchemaEventType = (AvroSchemaEventType) selectFromType;
                            var avro = new ConfigurationCommonEventTypeAvro();
                            avro.AvroSchema = avroSchemaEventType.Schema;
                            targetType = services.EventTypeAvroHandler.NewEventTypeFromSchema(
                                metadata.Invoke(EventTypeApplicationType.AVRO),
                                services.BeanEventTypeFactoryPrivate.EventBeanTypedEventFactory,
                                avro,
                                null,
                                null);
                        }
                        else if (selectFromType is MapEventType) {
                            var mapType = (MapEventType) selectFromType;
                            targetType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                                metadata.Invoke(EventTypeApplicationType.MAP),
                                mapType.Types,
                                null,
                                null,
                                mapType.StartTimestampPropertyName,
                                mapType.EndTimestampPropertyName,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                        else if (selectFromType is BeanEventType) {
                            var beanType = (BeanEventType) selectFromType;
                            targetType = new BeanEventType(
                                services.Container,
                                beanType.Stem,
                                metadata.Invoke(EventTypeApplicationType.CLASS),
                                services.BeanEventTypeFactoryPrivate,
                                null,
                                null,
                                beanType.StartTimestampPropertyName,
                                beanType.EndTimestampPropertyName);
                        }
                        else {
                            targetType = WrapperEventTypeUtil.MakeWrapper(
                                metadata.Invoke(EventTypeApplicationType.WRAPPER),
                                selectFromType,
                                new Dictionary<string, object>(),
                                null,
                                services.BeanEventTypeFactoryPrivate,
                                services.EventTypeCompileTimeResolver);
                        }
                    }
                }

                services.EventTypeCompileTimeRegistry.NewType(targetType);
            }
            catch (EPException ex) {
                throw new ExprValidationException(ex.Message, ex);
            }

            var filter = new FilterSpecCompiled(targetType, typeName, new IList<FilterSpecParamForge>[0], null);
            return new CreateWindowCompileResult(
                filter,
                newSelectClauseSpecRaw,
                optionalSelectFrom == null ? null : optionalSelectFrom.EventType);
        }
Exemple #2
0
 public override object Get(EventBean obj)
 {
     return GetMap(BaseNestableEventUtil.CheckedCastUnderlyingMap(obj));
 }
Exemple #3
0
 public override Object HandleNestedValue(Object value)
 {
     return(BaseNestableEventUtil.HandleNestedValueArrayWithMap(value, _index, _getter));
 }
Exemple #4
0
 public override Object HandleNestedValueFragment(Object value)
 {
     return(BaseNestableEventUtil.HandleNestedValueArrayWithMapFragment(value, _index, _getter, EventAdapterService, FragmentType));
 }
 public Object Get(EventBean eventBean)
 {
     return(GetMap(BaseNestableEventUtil.CheckedCastUnderlyingMap(eventBean)));
 }
Exemple #6
0
 public Object Get(EventBean obj)
 {
     Object[] array = BaseNestableEventUtil.CheckedCastUnderlyingObjectArray(obj);
     return GetObjectArray(array);
 }
Exemple #7
0
 public override bool HandleNestedValueExists(object value)
 {
     return BaseNestableEventUtil.HandleNestedValueArrayWithObjectArrayExists(value, index, getter);
 }
Exemple #8
0
        public StmtForgeMethodResult Make(
            string @namespace,
            string classPostfix,
            StatementCompileTimeServices services)
        {
            var statementSpec = @base.StatementSpec;
            if (statementSpec.Raw.OptionalContextName != null) {
                throw new ExprValidationException(
                    "A create-context statement cannot itself be associated to a context, please declare a nested context instead");
            }

            IList<FilterSpecCompiled> filterSpecCompileds = new List<FilterSpecCompiled>();
            IList<ScheduleHandleCallbackProvider> scheduleHandleCallbackProviders =
                new List<ScheduleHandleCallbackProvider>();
            IList<FilterSpecParamExprNodeForge> filterBooleanExpressions = new List<FilterSpecParamExprNodeForge>();

            var context = statementSpec.Raw.CreateContextDesc;
            if (services.ContextCompileTimeResolver.GetContextInfo(context.ContextName) != null) {
                throw new ExprValidationException("Context by name '" + context.ContextName + "' already exists");
            }

            // compile filter specs, if any
            var validationEnv = new CreateContextValidationEnv(
                context.ContextName,
                @base.StatementRawInfo,
                services,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                filterBooleanExpressions);
            ValidateContextDetail(context.ContextDetail, 0, validationEnv);

            // get controller factory forges
            var controllerFactoryForges = GetForges(
                context.ContextName,
                context.ContextDetail);

            // build context properties type information
            var contextProps = MakeContextProperies(
                controllerFactoryForges,
                @base.StatementRawInfo,
                services);

            // allocate type for context properties
            var contextEventTypeName =
                services.EventTypeNameGeneratorStatement.GetContextPropertyTypeName(context.ContextName);
            var metadata = new EventTypeMetadata(
                contextEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.CONTEXTPROPDERIVED,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            var contextPropertiesType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                metadata,
                contextProps,
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(contextPropertiesType);

            // register context
            var visibilityContext =
                services.ModuleVisibilityRules.GetAccessModifierContext(@base, context.ContextName);
            var validationInfo =
                new ContextControllerPortableInfo[controllerFactoryForges.Length];
            for (var i = 0; i < validationInfo.Length; i++) {
                validationInfo[i] = controllerFactoryForges[i].ValidationInfo;
            }

            var detail = new ContextMetaData(
                context.ContextName,
                @base.ModuleName,
                visibilityContext,
                contextPropertiesType,
                validationInfo);
            services.ContextCompileTimeRegistry.NewContext(detail);

            // define output event type
            var statementEventTypeName =
                services.EventTypeNameGeneratorStatement.GetContextStatementTypeName(context.ContextName);
            var statementTypeMetadata = new EventTypeMetadata(
                statementEventTypeName,
                @base.ModuleName,
                EventTypeTypeClass.STATEMENTOUT,
                EventTypeApplicationType.MAP,
                NameAccessModifier.TRANSIENT,
                EventTypeBusModifier.NONBUS,
                false,
                EventTypeIdPair.Unassigned());
            EventType statementEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                statementTypeMetadata,
                new EmptyDictionary<string, object>(),
                null,
                null,
                null,
                null,
                services.BeanEventTypeFactoryPrivate,
                services.EventTypeCompileTimeResolver);
            services.EventTypeCompileTimeRegistry.NewType(statementEventType);

            IList<StmtClassForgable> forgables = new List<StmtClassForgable>();

            var statementProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix);
            var statementAIFactoryProviderClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementAIFactoryProvider), classPostfix);
            var statementFieldsClassName =
                CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix);
            var packageScope = new CodegenNamespaceScope(
                @namespace,
                statementFieldsClassName,
                services.IsInstrumented);

            var forge =
                new StatementAgentInstanceFactoryCreateContextForge(context.ContextName, statementEventType);
            forgables.Add(
                new StmtClassForgableAIFactoryProviderCreateContext(
                    statementAIFactoryProviderClassName,
                    packageScope,
                    context.ContextName,
                    controllerFactoryForges,
                    contextPropertiesType,
                    forge));

            var selectSubscriberDescriptor = new SelectSubscriberDescriptor();
            var informationals = StatementInformationalsUtil.GetInformationals(
                @base,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                new EmptyList<NamedWindowConsumerStreamSpec>(),
                false,
                selectSubscriberDescriptor,
                packageScope,
                services);
            forgables.Add(
                new StmtClassForgableStmtProvider(
                    statementAIFactoryProviderClassName,
                    statementProviderClassName,
                    informationals,
                    packageScope));
            forgables.Add(
                new StmtClassForgableStmtFields(
                    statementFieldsClassName,
                    packageScope,
                    0));

            return new StmtForgeMethodResult(
                forgables,
                filterSpecCompileds,
                scheduleHandleCallbackProviders,
                new EmptyList<NamedWindowConsumerStreamSpec>(),
                FilterSpecCompiled.MakeExprNodeList(filterSpecCompileds, filterBooleanExpressions));
        }
Exemple #9
0
 public override object HandleNestedValue(object value)
 {
     return BaseNestableEventUtil.HandleNestedValueArrayWithObjectArray(value, index, getter);
 }
Exemple #10
0
 protected override Object HandleCreateFragment(Object value)
 {
     return(BaseNestableEventUtil.HandleCreateFragmentMap(value, FragmentEventType, EventAdapterService));
 }
        public Object GetFragment(EventBean obj)
        {
            Object fragmentUnderlying = Get(obj);

            return(BaseNestableEventUtil.GetFragmentNonPono(_eventAdapterService, fragmentUnderlying, _fragmentType));
        }
        private Object GetMapInternal(IDictionary <String, Object> map, int index)
        {
            Object value = map.Get(_propertyName);

            return(BaseNestableEventUtil.GetIndexedValue(value, index));
        }
        public Object Get(EventBean eventBean)
        {
            IDictionary <String, Object> map = BaseNestableEventUtil.CheckedCastUnderlyingMap(eventBean);

            return(GetMap(map));
        }