public StmtForgeMethodResult Make( string @namespace, string classPostfix, StatementCompileTimeServices services) { var statementSpec = @base.StatementSpec; var spec = statementSpec.Raw.CreateSchemaDesc; if (services.EventTypeCompileTimeResolver.GetTypeByName(spec.SchemaName) != null) { throw new ExprValidationException( "Event type named '" + spec.SchemaName + "' has already been declared"); } EPLValidationUtil.ValidateTableExists(services.TableCompileTimeResolver, spec.SchemaName); var eventTypeForgeablesPair = HandleCreateSchema(spec, services); var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementFields), classPostfix); var namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); var fieldsForgable = new StmtClassForgeableStmtFields(statementFieldsClassName, namespaceScope, 0); var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementAIFactoryProvider), classPostfix); var forge = new StatementAgentInstanceFactoryCreateSchemaForge( eventTypeForgeablesPair.EventType); var aiFactoryForgeable = new StmtClassForgeableAIFactoryProviderCreateSchema( aiFactoryProviderClassName, namespaceScope, forge); var selectSubscriberDescriptor = new SelectSubscriberDescriptor(); var informationals = StatementInformationalsUtil.GetInformationals( @base, EmptyList<FilterSpecCompiled>.Instance, EmptyList<ScheduleHandleCallbackProvider>.Instance, EmptyList<NamedWindowConsumerStreamSpec>.Instance, false, selectSubscriberDescriptor, namespaceScope, services); informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, spec.SchemaName); var statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); var stmtProvider = new StmtClassForgeableStmtProvider( aiFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope); var forgables = new List<StmtClassForgeable>(); eventTypeForgeablesPair.AdditionalForgeables.ForEach( a => forgables.Add(a.Make(namespaceScope, classPostfix))); forgables.Add(fieldsForgable); forgables.Add(aiFactoryForgeable); forgables.Add(stmtProvider); return new StmtForgeMethodResult( forgables, EmptyList<FilterSpecCompiled>.Instance, EmptyList<ScheduleHandleCallbackProvider>.Instance, EmptyList<NamedWindowConsumerStreamSpec>.Instance, EmptyList<FilterSpecParamExprNodeForge>.Instance); }
public StmtForgeMethodResult Make( string @namespace, string classPostfix, StatementCompileTimeServices services) { string objectName = Register(services); // define output event type string statementEventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName; EventTypeMetadata statementTypeMetadata = new EventTypeMetadata( statementEventTypeName, _base.ModuleName, EventTypeTypeClass.STATEMENTOUT, EventTypeApplicationType.MAP, NameAccessModifier.TRANSIENT, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned()); EventType statementEventType = BaseNestableEventUtil.MakeMapTypeCompileTime( statementTypeMetadata, EmptyDictionary <string, object> .Instance, null, null, null, null, services.BeanEventTypeFactoryPrivate, services.EventTypeCompileTimeResolver); services.EventTypeCompileTimeRegistry.NewType(statementEventType); string statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix); CodegenNamespaceScope namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); string aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementAIFactoryProvider), classPostfix); StmtClassForgeable aiFactoryForgeable = AiFactoryForgable(aiFactoryProviderClassName, namespaceScope, statementEventType, objectName); SelectSubscriberDescriptor selectSubscriberDescriptor = new SelectSubscriberDescriptor(); StatementInformationalsCompileTime informationals = StatementInformationalsUtil.GetInformationals( _base, EmptyList <FilterSpecCompiled> .Instance, EmptyList <ScheduleHandleCallbackProvider> .Instance, EmptyList <NamedWindowConsumerStreamSpec> .Instance, false, selectSubscriberDescriptor, namespaceScope, services); informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, objectName); string statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); StmtClassForgeableStmtProvider stmtProvider = new StmtClassForgeableStmtProvider( aiFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope); var stmtClassForgeableStmtFields = new StmtClassForgeableStmtFields( statementFieldsClassName, namespaceScope, 1); IList <StmtClassForgeable> forgeables = new List <StmtClassForgeable>(); forgeables.Add(aiFactoryForgeable); forgeables.Add(stmtProvider); forgeables.Add(stmtClassForgeableStmtFields); return(new StmtForgeMethodResult( forgeables, EmptyList <FilterSpecCompiled> .Instance, EmptyList <ScheduleHandleCallbackProvider> .Instance, EmptyList <NamedWindowConsumerStreamSpec> .Instance, EmptyList <FilterSpecParamExprNodeForge> .Instance)); }
public StmtForgeMethodResult Make( string @namespace, string classPostfix, StatementCompileTimeServices services) { var statementSpec = _base.StatementSpec; var createDesc = statementSpec.Raw.CreateVariableDesc; // Check if the variable is already declared EPLValidationUtil.ValidateAlreadyExistsTableOrVariable( createDesc.VariableName, services.VariableCompileTimeResolver, services.TableCompileTimeResolver, services.EventTypeCompileTimeResolver); // Get assignment value when compile-time-constant object initialValue = null; ExprForge initialValueExpr = null; if (createDesc.Assignment != null) { // Evaluate assignment expression StreamTypeService typeService = new StreamTypeServiceImpl( new EventType[0], new string[0], new bool[0], false, false); var validationContext = new ExprValidationContextBuilder(typeService, _base.StatementRawInfo, services).Build(); var validated = ExprNodeUtilityValidate.GetValidatedSubtree( ExprNodeOrigin.VARIABLEASSIGN, createDesc.Assignment, validationContext); if (validated.Forge.ForgeConstantType == ExprForgeConstantType.COMPILETIMECONST) { initialValue = validated.Forge.ExprEvaluator.Evaluate(null, true, null); } createDesc.Assignment = validated; initialValueExpr = validated.Forge; } var contextName = statementSpec.Raw.OptionalContextName; NameAccessModifier? contextVisibility = null; string contextModuleName = null; if (contextName != null) { var contextDetail = services.ContextCompileTimeResolver.GetContextInfo(contextName); if (contextDetail == null) { throw new ExprValidationException("Failed to find context '" + contextName + "'"); } contextVisibility = contextDetail.ContextVisibility; contextModuleName = contextDetail.ContextModuleName; } // get visibility var visibility = services.ModuleVisibilityRules.GetAccessModifierVariable(_base, createDesc.VariableName); // Compile metadata var compileTimeConstant = createDesc.IsConstant && initialValueExpr != null && initialValueExpr.ForgeConstantType.IsCompileTimeConstant; var metaData = VariableUtil.CompileVariable( createDesc.VariableName, _base.ModuleName, visibility, contextName, contextVisibility, contextModuleName, createDesc.VariableType, createDesc.IsConstant, compileTimeConstant, initialValue, services.ImportServiceCompileTime, services.ClassProvidedExtension, EventBeanTypedEventFactoryCompileTime.INSTANCE, services.EventTypeRepositoryPreconfigured, services.BeanEventTypeFactoryPrivate); // Register variable services.VariableCompileTimeRegistry.NewVariable(metaData); // Statement event type var eventTypePropertyTypes = Collections.SingletonDataMap( metaData.VariableName, metaData.Type); var eventTypeName = services.EventTypeNameGeneratorStatement.AnonymousTypeName; var eventTypeMetadata = new EventTypeMetadata( eventTypeName, _base.ModuleName, EventTypeTypeClass.STATEMENTOUT, EventTypeApplicationType.MAP, NameAccessModifier.TRANSIENT, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned()); var outputEventType = BaseNestableEventUtil.MakeMapTypeCompileTime( eventTypeMetadata, eventTypePropertyTypes, null, null, null, null, services.BeanEventTypeFactoryPrivate, services.EventTypeCompileTimeResolver); services.EventTypeCompileTimeRegistry.NewType(outputEventType); // Handle output format var defaultSelectAllSpec = new StatementSpecCompiled(); defaultSelectAllSpec.SelectClauseCompiled.WithSelectExprList(new SelectClauseElementWildcard()); defaultSelectAllSpec.Raw.SelectStreamDirEnum = SelectClauseStreamSelectorEnum.RSTREAM_ISTREAM_BOTH; StreamTypeService streamTypeService = new StreamTypeServiceImpl( new EventType[] {outputEventType}, new string[] {"trigger_stream"}, new bool[] {true}, false, false); var resultSetProcessor = ResultSetProcessorFactoryFactory.GetProcessorPrototype( new ResultSetSpec(defaultSelectAllSpec), streamTypeService, null, new bool[1], false, _base.ContextPropertyRegistry, false, false, _base.StatementRawInfo, services); // Code generation var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix); var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementAIFactoryProvider), classPostfix); var classNameRSP = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(ResultSetProcessorFactoryProvider), classPostfix); var namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); // serde DataInputOutputSerdeForge serde = DataInputOutputSerdeForgeNotApplicable.INSTANCE; if (metaData.EventType == null) { serde = services.SerdeResolver.SerdeForVariable( metaData.Type, metaData.VariableName, _base.StatementRawInfo); } var forge = new StatementAgentInstanceFactoryCreateVariableForge( createDesc.VariableName, initialValueExpr, classNameRSP); var aiFactoryForgeable = new StmtClassForgeableAIFactoryProviderCreateVariable( aiFactoryProviderClassName, namespaceScope, forge, createDesc.VariableName, serde); var informationals = StatementInformationalsUtil.GetInformationals( _base, Collections.GetEmptyList<FilterSpecCompiled>(), Collections.GetEmptyList<ScheduleHandleCallbackProvider>(), Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(), true, resultSetProcessor.SelectSubscriberDescriptor, namespaceScope, services); informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, createDesc.VariableName); var statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); var stmtProvider = new StmtClassForgeableStmtProvider( aiFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope); var forgeables = new List<StmtClassForgeable>(); forgeables.Add( new StmtClassForgeableRSPFactoryProvider( classNameRSP, resultSetProcessor, namespaceScope, _base.StatementRawInfo)); forgeables.Add(aiFactoryForgeable); forgeables.Add(stmtProvider); forgeables.Add(new StmtClassForgeableStmtFields(statementFieldsClassName, namespaceScope, 0)); return new StmtForgeMethodResult( forgeables, Collections.GetEmptyList<FilterSpecCompiled>(), Collections.GetEmptyList<ScheduleHandleCallbackProvider>(), Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(), Collections.GetEmptyList<FilterSpecParamExprNodeForge>()); }
public StmtForgeMethodResult Make( string @namespace, string classPostfix, StatementCompileTimeServices services) { var statementSpec = _base.StatementSpec; // determine context var contextName = _base.StatementSpec.Raw.OptionalContextName; if (contextName != null) { throw new ExprValidationException("Update IStream is not supported in conjunction with a context"); } var streamSpec = statementSpec.StreamSpecs[0]; var updateSpec = statementSpec.Raw.UpdateDesc; string triggereventTypeName; EventType streamEventType; List<StmtClassForgeableFactory> additionalForgeables = new List<StmtClassForgeableFactory>(); if (streamSpec is FilterStreamSpecCompiled) { var filterStreamSpec = (FilterStreamSpecCompiled) streamSpec; triggereventTypeName = filterStreamSpec.FilterSpecCompiled.FilterForEventTypeName; streamEventType = filterStreamSpec.FilterSpecCompiled.FilterForEventType; } else if (streamSpec is NamedWindowConsumerStreamSpec) { var namedSpec = (NamedWindowConsumerStreamSpec) streamSpec; streamEventType = namedSpec.NamedWindow.EventType; triggereventTypeName = streamEventType.Name; } else if (streamSpec is TableQueryStreamSpec) { throw new ExprValidationException("Tables cannot be used in an update-istream statement"); } else { throw new ExprValidationException("Unknown stream specification streamEventType: " + streamSpec); } // determine a stream name var streamName = triggereventTypeName; if (updateSpec.OptionalStreamName != null) { streamName = updateSpec.OptionalStreamName; } StreamTypeService typeService = new StreamTypeServiceImpl( new[] {streamEventType}, new[] {streamName}, new[] {true}, false, false); // create subselect information IList<FilterSpecCompiled> filterSpecCompileds = new List<FilterSpecCompiled>(); IList<NamedWindowConsumerStreamSpec> namedWindowConsumers = new List<NamedWindowConsumerStreamSpec>(); SubSelectActivationDesc subSelectActivationDesc = SubSelectHelperActivations.CreateSubSelectActivation( filterSpecCompileds, namedWindowConsumers, _base, services); additionalForgeables.AddAll(subSelectActivationDesc.AdditionalForgeables); IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation = subSelectActivationDesc.Subselects; // handle subselects SubSelectHelperForgePlan subSelectForgePlan = SubSelectHelperForgePlanner.PlanSubSelect( _base, subselectActivation, typeService.StreamNames, typeService.EventTypes, new String[]{triggereventTypeName}, services); IDictionary<ExprSubselectNode, SubSelectFactoryForge> subselectForges = subSelectForgePlan.Subselects; additionalForgeables.AddAll(subSelectForgePlan.AdditionalForgeables); var validationContext = new ExprValidationContextBuilder(typeService, _base.StatementRawInfo, services).Build(); foreach (var assignment in updateSpec.Assignments) { ExprNodeUtilityValidate.ValidateAssignment( false, ExprNodeOrigin.UPDATEASSIGN, assignment, validationContext); } if (updateSpec.OptionalWhereClause != null) { var validated = ExprNodeUtilityValidate.GetValidatedSubtree( ExprNodeOrigin.WHERE, updateSpec.OptionalWhereClause, validationContext); updateSpec.OptionalWhereClause = validated; EPStatementStartMethodHelperValidate.ValidateNoAggregations( validated, "Aggregation functions may not be used within an update-clause"); } // build route information var routerDesc = InternalEventRouterDescFactory.GetValidatePreprocessing( streamEventType, updateSpec, _base.StatementRawInfo.Annotations); var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementFields), classPostfix); var namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementAIFactoryProvider), classPostfix); var forge = new StatementAgentInstanceFactoryUpdateForge(routerDesc, subselectForges); var aiFactoryForgeable = new StmtClassForgeableAIFactoryProviderUpdate( aiFactoryProviderClassName, namespaceScope, forge); var selectSubscriberDescriptor = new SelectSubscriberDescriptor( new[] {streamEventType.UnderlyingType}, new[] {"*"}, false, null, null); var informationals = StatementInformationalsUtil.GetInformationals( _base, filterSpecCompileds, Collections.GetEmptyList<ScheduleHandleCallbackProvider>(), Collections.GetEmptyList<NamedWindowConsumerStreamSpec>(), false, selectSubscriberDescriptor, namespaceScope, services); var statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); var stmtProvider = new StmtClassForgeableStmtProvider( aiFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope); IList<StmtClassForgeable> forgeables = new List<StmtClassForgeable>(); additionalForgeables.ForEach(_ => forgeables.Add(_.Make(namespaceScope, classPostfix))); forgeables.Add(aiFactoryForgeable); forgeables.Add(stmtProvider); forgeables.Add(new StmtClassForgeableStmtFields(statementFieldsClassName, namespaceScope, 0)); return new StmtForgeMethodResult( forgeables, filterSpecCompileds, Collections.GetEmptyList<ScheduleHandleCallbackProvider>(), namedWindowConsumers, Collections.GetEmptyList<FilterSpecParamExprNodeForge>()); }
public StmtForgeMethodResult Make( string @namespace, string classPostfix, StatementCompileTimeServices services) { var spec = _base.StatementSpec.Raw.CreateIndexDesc; var infraName = spec.WindowName; var namedWindow = services.NamedWindowCompileTimeResolver.Resolve(infraName); var table = services.TableCompileTimeResolver.Resolve(infraName); if (namedWindow == null && table == null) { throw new ExprValidationException("A named window or table by name '" + infraName + "' does not exist"); } if (namedWindow != null && table != null) { throw new ExprValidationException("A named window or table by name '" + infraName + "' are both found"); } string infraModuleName; NameAccessModifier infraVisibility; EventType indexedEventType; string infraContextName; if (namedWindow != null) { infraModuleName = namedWindow.NamedWindowModuleName; infraVisibility = namedWindow.EventType.Metadata.AccessModifier; indexedEventType = namedWindow.EventType; infraContextName = namedWindow.ContextName; } else { infraModuleName = table.TableModuleName; infraVisibility = table.TableVisibility; indexedEventType = table.InternalEventType; infraContextName = table.OptionalContextName; if (!table.IsKeyed) { throw new ExprValidationException( "Tables without primary key column(s) do not allow creating an index"); } } EPLValidationUtil.ValidateContextName( namedWindow == null, infraName, infraContextName, _base.StatementSpec.Raw.OptionalContextName, true); // validate index var explicitIndexDesc = EventTableIndexUtil.ValidateCompileExplicitIndex( spec.IndexName, spec.IsUnique, spec.Columns, indexedEventType, _base.StatementRawInfo, services); var advancedIndexDesc = explicitIndexDesc.AdvancedIndexProvisionDesc == null ? null : explicitIndexDesc.AdvancedIndexProvisionDesc.IndexDesc.AdvancedIndexDescRuntime; var imk = new IndexMultiKey( spec.IsUnique, explicitIndexDesc.HashPropsAsList, explicitIndexDesc.BtreePropsAsList, advancedIndexDesc); // add index as a new index to module-init var indexKey = new IndexCompileTimeKey( infraModuleName, infraName, infraVisibility, namedWindow != null, spec.IndexName, _base.ModuleName); services.IndexCompileTimeRegistry.NewIndex(indexKey, new IndexDetailForge(imk, explicitIndexDesc)); // add index current named window information if (namedWindow != null) { namedWindow.AddIndex(spec.IndexName, _base.ModuleName, imk, explicitIndexDesc.ToRuntime()); } else { table.AddIndex(spec.IndexName, _base.ModuleName, imk, explicitIndexDesc.ToRuntime()); } // determine multikey plan MultiKeyPlan multiKeyPlan = MultiKeyPlanner.PlanMultiKey( explicitIndexDesc.HashTypes, false, _base.StatementRawInfo, services.SerdeResolver); explicitIndexDesc.HashMultiKeyClasses = multiKeyPlan.ClassRef; DataInputOutputSerdeForge[] rangeSerdes = new DataInputOutputSerdeForge[explicitIndexDesc.RangeProps.Length]; for (int i = 0; i < explicitIndexDesc.RangeProps.Length; i++) { rangeSerdes[i] = services.SerdeResolver.SerdeForIndexBtree( explicitIndexDesc.RangeTypes[i], _base.StatementRawInfo); } explicitIndexDesc.RangeSerdes = rangeSerdes; var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementFields), classPostfix); var namespaceScope = new CodegenNamespaceScope( @namespace, statementFieldsClassName, services.IsInstrumented); var fieldsForgeable = new StmtClassForgeableStmtFields(statementFieldsClassName, namespaceScope, 0); var aiFactoryProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementAIFactoryProvider), classPostfix); var forge = new StatementAgentInstanceFactoryCreateIndexForge( indexedEventType, spec.IndexName, _base.ModuleName, explicitIndexDesc, imk, namedWindow, table); var aiFactoryForgeable = new StmtClassForgeableAIFactoryProviderCreateIndex( aiFactoryProviderClassName, namespaceScope, forge); var selectSubscriberDescriptor = new SelectSubscriberDescriptor(); var informationals = StatementInformationalsUtil.GetInformationals( _base, EmptyList<FilterSpecCompiled>.Instance, EmptyList<ScheduleHandleCallbackProvider>.Instance, EmptyList<NamedWindowConsumerStreamSpec>.Instance, true, selectSubscriberDescriptor, namespaceScope, services); informationals.Properties.Put(StatementProperty.CREATEOBJECTNAME, spec.IndexName); var statementProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(StatementProvider), classPostfix); var stmtProvider = new StmtClassForgeableStmtProvider( aiFactoryProviderClassName, statementProviderClassName, informationals, namespaceScope); var forgeables = new List<StmtClassForgeable>(); foreach (var additional in multiKeyPlan.MultiKeyForgeables) { forgeables.Add(additional.Make(namespaceScope, classPostfix)); } forgeables.Add(fieldsForgeable); forgeables.Add(aiFactoryForgeable); forgeables.Add(stmtProvider); return new StmtForgeMethodResult( forgeables, EmptyList<FilterSpecCompiled>.Instance, EmptyList<ScheduleHandleCallbackProvider>.Instance, EmptyList<NamedWindowConsumerStreamSpec>.Instance, EmptyList<FilterSpecParamExprNodeForge>.Instance); }