public override void Run(EPServiceProvider epService) { EPStatement statementOne = epService.EPAdministrator.CreateEPL( "select base1 as v1, base2.n1 as v2, base3? as v3, base2.n2? as v4 from MyEvent"); EPStatement statementOneSelectAll = epService.EPAdministrator.CreateEPL("select * from MyEvent"); Assert.AreEqual("[base1, base2]", CompatExtensions.Render(statementOneSelectAll.EventType.PropertyNames)); var listenerOne = new SupportUpdateListener(); statementOne.Events += listenerOne.Update; string[] fields = "v1,v2,v3,v4".Split(','); epService.EPRuntime.SendEvent(ExecEventMap.MakeMap(new object[][] { new object[] { "base1", "abc" }, new object[] { "base2", ExecEventMap.MakeMap(new object[][] { new object[] { "n1", 10 } }) } }), "MyEvent"); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), fields, new object[] { "abc", 10, null, null }); // update type IDictionary <string, Object> typeNew = ExecEventMap.MakeMap(new object[][] { new object[] { "base3", typeof(long) }, new object[] { "base2", ExecEventMap.MakeMap(new object[][] { new object[] { "n2", typeof(string) } }) } }); epService.EPAdministrator.Configuration.UpdateMapEventType("MyEvent", typeNew); EPStatement statementTwo = epService.EPAdministrator.CreateEPL("select base1 as v1, base2.n1 as v2, base3 as v3, base2.n2 as v4 from MyEvent"); EPStatement statementTwoSelectAll = epService.EPAdministrator.CreateEPL("select * from MyEvent"); var listenerTwo = new SupportUpdateListener(); statementTwo.Events += listenerTwo.Update; epService.EPRuntime.SendEvent(ExecEventMap.MakeMap(new object[][] { new object[] { "base1", "def" }, new object[] { "base2", ExecEventMap.MakeMap(new object[][] { new object[] { "n1", 9 }, new object[] { "n2", "xyz" } }) }, new object[] { "base3", 20L }, }), "MyEvent"); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), fields, new object[] { "def", 9, 20L, "xyz" }); EPAssertionUtil.AssertProps(listenerTwo.AssertOneGetNewAndReset(), fields, new object[] { "def", 9, 20L, "xyz" }); // assert event type Assert.AreEqual("[base1, base2, base3]", CompatExtensions.Render(statementOneSelectAll.EventType.PropertyNames)); Assert.AreEqual("[base1, base2, base3]", CompatExtensions.Render(statementTwoSelectAll.EventType.PropertyNames)); EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] { new EventPropertyDescriptor("base3", typeof(long), null, false, false, false, false, false), new EventPropertyDescriptor("base2", typeof(IDictionary <string, object>), null, false, false, false, true, false), new EventPropertyDescriptor("base1", typeof(string), typeof(char), false, false, true, false, false), }, statementTwoSelectAll.EventType.PropertyDescriptors); try { epService.EPAdministrator.Configuration.UpdateMapEventType("dummy", typeNew); Assert.Fail(); } catch (ConfigurationException ex) { Assert.AreEqual("Error updating Map event type: Event type named 'dummy' has not been declared", ex.Message); } epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); try { epService.EPAdministrator.Configuration.UpdateMapEventType("SupportBean", typeNew); Assert.Fail(); } catch (ConfigurationException ex) { Assert.AreEqual("Error updating Map event type: Event type by name 'SupportBean' is not a Map event type", ex.Message); } }
public override String ToString() { return("CompositeTableLookupStrategy indexProps=" + CompatExtensions.Render(_rangeKeyPairs.ToArray()) + " index=(" + _index + ')'); }
/// <summary> /// Ctor. /// </summary> /// <param name="statementSpec"> /// is a container for the definition of all statement constructs that may have been used in the /// statement, i.e. if defines the select clauses, insert into, outer joins etc. /// </param> /// <param name="services">is the service instances for dependency injection</param> /// <param name="statementContext">is statement-level information and statement services</param> /// <throws>ExprValidationException if the preparation failed</throws> public EPPreparedExecuteMethodQuery( StatementSpecCompiled statementSpec, EPServicesContext services, StatementContext statementContext) { var queryPlanLogging = services.ConfigSnapshot.EngineDefaults.Logging.IsEnableQueryPlan; if (queryPlanLogging) { QueryPlanLog.Info("Query plans for Fire-and-forget query '" + statementContext.Expression + "'"); } _hasTableAccess = (statementSpec.TableNodes != null && statementSpec.TableNodes.Length > 0); foreach (var streamSpec in statementSpec.StreamSpecs) { _hasTableAccess |= streamSpec is TableQueryStreamSpec; } _statementSpec = statementSpec; _services = services; EPPreparedExecuteMethodHelper.ValidateFAFQuery(statementSpec); var numStreams = statementSpec.StreamSpecs.Length; var typesPerStream = new EventType[numStreams]; var namesPerStream = new string[numStreams]; _processors = new FireAndForgetProcessor[numStreams]; _agentInstanceContext = new AgentInstanceContext(statementContext, null, -1, null, null, statementContext.DefaultAgentInstanceScriptContext); // resolve types and processors for (var i = 0; i < numStreams; i++) { var streamSpec = statementSpec.StreamSpecs[i]; _processors[i] = FireAndForgetProcessorFactory.ValidateResolveProcessor(streamSpec, services); string streamName = _processors[i].NamedWindowOrTableName; if (streamSpec.OptionalStreamName != null) { streamName = streamSpec.OptionalStreamName; } namesPerStream[i] = streamName; typesPerStream[i] = _processors[i].EventTypeResultSetProcessor; } // compile filter to optimize access to named window _filters = new FilterSpecCompiled[numStreams]; if (statementSpec.FilterRootNode != null) { var tagged = new LinkedHashMap <string, Pair <EventType, string> >(); for (var i = 0; i < numStreams; i++) { try { var types = new StreamTypeServiceImpl(typesPerStream, namesPerStream, new bool[numStreams], services.EngineURI, false); _filters[i] = FilterSpecCompiler.MakeFilterSpec(typesPerStream[i], namesPerStream[i], Collections.SingletonList(statementSpec.FilterRootNode), null, tagged, tagged, types, null, statementContext, Collections.SingletonList(i)); } catch (Exception ex) { Log.Warn("Unexpected exception analyzing filter paths: " + ex.Message, ex); } } } // obtain result set processor var isIStreamOnly = new bool[namesPerStream.Length]; CompatExtensions.Fill(isIStreamOnly, true); StreamTypeService typeService = new StreamTypeServiceImpl(typesPerStream, namesPerStream, isIStreamOnly, services.EngineURI, true); EPStatementStartMethodHelperValidate.ValidateNodes(statementSpec, statementContext, typeService, null); var resultSetProcessorPrototype = ResultSetProcessorFactoryFactory.GetProcessorPrototype(statementSpec, statementContext, typeService, null, new bool[0], true, ContextPropertyRegistryImpl.EMPTY_REGISTRY, null, services.ConfigSnapshot, services.ResultSetProcessorHelperFactory, true, false); _resultSetProcessor = EPStatementStartMethodHelperAssignExpr.GetAssignResultSetProcessor(_agentInstanceContext, resultSetProcessorPrototype, false, null, true); if (statementSpec.SelectClauseSpec.IsDistinct) { if (_resultSetProcessor.ResultEventType is EventTypeSPI) { _eventBeanReader = ((EventTypeSPI)_resultSetProcessor.ResultEventType).Reader; } if (_eventBeanReader == null) { _eventBeanReader = new EventBeanReaderDefaultImpl(_resultSetProcessor.ResultEventType); } } // check context partition use if (statementSpec.OptionalContextName != null) { if (numStreams > 1) { throw new ExprValidationException("Joins in runtime queries for context partitions are not supported"); } } // plan joins or simple queries if (numStreams > 1) { var streamJoinAnalysisResult = new StreamJoinAnalysisResult(numStreams); CompatExtensions.Fill(streamJoinAnalysisResult.NamedWindow, true); for (var i = 0; i < numStreams; i++) { var processorInstance = _processors[i].GetProcessorInstance(_agentInstanceContext); if (_processors[i].IsVirtualDataWindow) { streamJoinAnalysisResult.ViewExternal[i] = agentInstanceContext => processorInstance.VirtualDataWindow; } var uniqueIndexes = _processors[i].GetUniqueIndexes(processorInstance); streamJoinAnalysisResult.UniqueKeys[i] = uniqueIndexes; } var hasAggregations = !resultSetProcessorPrototype.AggregationServiceFactoryDesc.Expressions.IsEmpty(); _joinSetComposerPrototype = JoinSetComposerPrototypeFactory.MakeComposerPrototype(null, -1, statementSpec.OuterJoinDescList, statementSpec.FilterRootNode, typesPerStream, namesPerStream, streamJoinAnalysisResult, queryPlanLogging, statementContext, new HistoricalViewableDesc(numStreams), _agentInstanceContext, false, hasAggregations, services.TableService, true, services.EventTableIndexService.AllowInitIndex(false)); } }
public FAFQueryMethodSelectDesc( StatementSpecCompiled statementSpec, Compilable compilable, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { Annotations = statementSpec.Annotations; ContextName = statementSpec.Raw.OptionalContextName; var queryPlanLogging = services.Configuration.Common.Logging.IsEnableQueryPlan; if (queryPlanLogging) { QUERY_PLAN_LOG.Info("Query plans for Fire-and-forget query '" + compilable.ToEPL() + "'"); } HasTableAccess = statementSpec.TableAccessNodes != null && statementSpec.TableAccessNodes.Count > 0; foreach (var streamSpec in statementSpec.StreamSpecs) { HasTableAccess |= streamSpec is TableQueryStreamSpec; } HasTableAccess |= StatementLifecycleSvcUtil.IsSubqueryWithTable( statementSpec.SubselectNodes, services.TableCompileTimeResolver); IsDistinct = statementSpec.SelectClauseCompiled.IsDistinct; FAFQueryMethodHelper.ValidateFAFQuery(statementSpec); var numStreams = statementSpec.StreamSpecs.Length; var typesPerStream = new EventType[numStreams]; var namesPerStream = new string[numStreams]; var eventTypeNames = new string[numStreams]; Processors = new FireAndForgetProcessorForge[numStreams]; ConsumerFilters = new ExprNode[numStreams]; // check context partition use if (statementSpec.Raw.OptionalContextName != null) { if (numStreams > 1) { throw new ExprValidationException( "Joins in runtime queries for context partitions are not supported"); } } // resolve types and processors for (var i = 0; i < numStreams; i++) { var streamSpec = statementSpec.StreamSpecs[i]; Processors[i] = FireAndForgetProcessorForgeFactory.ValidateResolveProcessor(streamSpec); if (numStreams > 1 && Processors[i].ContextName != null) { throw new ExprValidationException( "Joins against named windows that are under context are not supported"); } var streamName = Processors[i].NamedWindowOrTableName; if (streamSpec.OptionalStreamName != null) { streamName = streamSpec.OptionalStreamName; } namesPerStream[i] = streamName; typesPerStream[i] = Processors[i].EventTypeRspInputEvents; eventTypeNames[i] = typesPerStream[i].Name; IList<ExprNode> consumerFilterExprs; if (streamSpec is NamedWindowConsumerStreamSpec) { var namedSpec = (NamedWindowConsumerStreamSpec) streamSpec; consumerFilterExprs = namedSpec.FilterExpressions; } else { var tableSpec = (TableQueryStreamSpec) streamSpec; consumerFilterExprs = tableSpec.FilterExpressions; } ConsumerFilters[i] = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(consumerFilterExprs); } // compile filter to optimize access to named window var optionalStreamsIfAny = OuterJoinAnalyzer.OptionalStreamsIfAny(statementSpec.Raw.OuterJoinDescList); var types = new StreamTypeServiceImpl( typesPerStream, namesPerStream, new bool[numStreams], false, optionalStreamsIfAny); var excludePlanHint = ExcludePlanHint.GetHint(types.StreamNames, statementRawInfo, services); QueryGraph = new QueryGraphForge(numStreams, excludePlanHint, false); if (statementSpec.Raw.WhereClause != null) { for (var i = 0; i < numStreams; i++) { try { var validationContext = new ExprValidationContextBuilder(types, statementRawInfo, services) .WithAllowBindingConsumption(true) .WithIsFilterExpression(true) .Build(); var validated = ExprNodeUtilityValidate.GetValidatedSubtree( ExprNodeOrigin.FILTER, statementSpec.Raw.WhereClause, validationContext); FilterExprAnalyzer.Analyze(validated, QueryGraph, false); } catch (Exception ex) { Log.Warn("Unexpected exception analyzing filter paths: " + ex.Message, ex); } } } // handle subselects // first we create streams for subselects, if there are any var @base = new StatementBaseInfo(compilable, statementSpec, null, statementRawInfo, null); var subqueryNamedWindowConsumers = new List<NamedWindowConsumerStreamSpec>(); SubSelectActivationDesc subSelectActivationDesc = SubSelectHelperActivations.CreateSubSelectActivation( EmptyList<FilterSpecCompiled>.Instance, subqueryNamedWindowConsumers, @base, services); IDictionary<ExprSubselectNode, SubSelectActivationPlan> subselectActivation = subSelectActivationDesc.Subselects; AdditionalForgeables.AddAll(subSelectActivationDesc.AdditionalForgeables); SubSelectHelperForgePlan subSelectForgePlan = SubSelectHelperForgePlanner.PlanSubSelect( @base, subselectActivation, namesPerStream, typesPerStream, eventTypeNames, services); SubselectForges = subSelectForgePlan.Subselects; AdditionalForgeables.AddAll(subSelectForgePlan.AdditionalForgeables); // obtain result set processor var isIStreamOnly = new bool[namesPerStream.Length]; isIStreamOnly.Fill(true); StreamTypeService typeService = new StreamTypeServiceImpl( typesPerStream, namesPerStream, isIStreamOnly, true, optionalStreamsIfAny); WhereClause = EPStatementStartMethodHelperValidate.ValidateNodes( statementSpec.Raw, typeService, null, statementRawInfo, services); var resultSetSpec = new ResultSetSpec(statementSpec); ResultSetProcessor = ResultSetProcessorFactoryFactory.GetProcessorPrototype( resultSetSpec, typeService, null, new bool[0], true, null, true, false, statementRawInfo, services); AdditionalForgeables.AddAll(ResultSetProcessor.AdditionalForgeables); // plan table access TableAccessForges = ExprTableEvalHelperPlan.PlanTableAccess(statementSpec.Raw.TableExpressions); // plan joins or simple queries if (numStreams > 1) { var streamJoinAnalysisResult = new StreamJoinAnalysisResultCompileTime(numStreams); CompatExtensions.Fill(streamJoinAnalysisResult.NamedWindowsPerStream, (NamedWindowMetaData) null); for (var i = 0; i < numStreams; i++) { var uniqueIndexes = Processors[i].UniqueIndexes; streamJoinAnalysisResult.UniqueKeys[i] = uniqueIndexes; } var hasAggregations = ResultSetProcessor.ResultSetProcessorType.IsAggregated(); var desc = JoinSetComposerPrototypeForgeFactory.MakeComposerPrototype( statementSpec, streamJoinAnalysisResult, types, new HistoricalViewableDesc(numStreams), true, hasAggregations, statementRawInfo, services); AdditionalForgeables.AddAll(desc.AdditionalForgeables); Joins = desc.Forge; } else { Joins = null; } var multiKeyPlan = MultiKeyPlanner.PlanMultiKeyDistinct( IsDistinct, ResultSetProcessor.ResultEventType, statementRawInfo, SerdeCompileTimeResolverNonHA.INSTANCE); AdditionalForgeables.AddAll(multiKeyPlan.MultiKeyForgeables); DistinctMultiKey = multiKeyPlan.ClassRef; }
public string ToQueryPlan() { return(this.GetType().Name + " streamNum=" + organization.StreamNum + " propertyGetters=" + CompatExtensions.Render(propertyGetters)); }
public override bool EqualsNode(ExprNode node) { var other = node as ExprNewStructNode; return(other != null && CompatExtensions.DeepEquals(other._columnNames, _columnNames)); }
public string ToQueryPlan() { return GetType().Name + " expressions " + CompatExtensions.Render(Expressions); }
public override int GetHashCode() { return CompatExtensions.HashAll<object>(propertyName, eventType); }
public DataFlowOpForgeInitializeResult InitializeForge(DataFlowOpForgeInitializeContext context) { if (context.InputPorts.IsEmpty()) { throw new ArgumentException("Select operator requires at least one input stream"); } if (context.OutputPorts.Count != 1) { throw new ArgumentException( "Select operator requires one output stream but produces " + context.OutputPorts.Count + " streams"); } var portZero = context.OutputPorts[0]; if (portZero.OptionalDeclaredType != null && !portZero.OptionalDeclaredType.IsUnderlying) { submitEventBean = true; } // determine adapter factories for each type var numStreams = context.InputPorts.Count; eventTypes = new EventType[numStreams]; for (var i = 0; i < numStreams; i++) { eventTypes[i] = context.InputPorts.Get(i).TypeDesc.EventType; } // validate if (select.InsertIntoDesc != null) { throw new ExprValidationException("Insert-into clause is not supported"); } if (select.SelectStreamSelectorEnum != SelectClauseStreamSelectorEnum.ISTREAM_ONLY) { throw new ExprValidationException("Selecting remove-stream is not supported"); } ExprNodeSubselectDeclaredDotVisitor visitor = StatementSpecRawWalkerSubselectAndDeclaredDot.WalkSubselectAndDeclaredDotExpr(select); GroupByClauseExpressions groupByExpressions = GroupByExpressionHelper.GetGroupByRollupExpressions( select.GroupByExpressions, select.SelectClauseSpec, select.WhereClause, select.OrderByList, null); if (!visitor.Subselects.IsEmpty()) { throw new ExprValidationException("Subselects are not supported"); } IDictionary<int, FilterStreamSpecRaw> streams = new Dictionary<int, FilterStreamSpecRaw>(); for (var streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { StreamSpecRaw rawStreamSpec = select.StreamSpecs[streamNum]; if (!(rawStreamSpec is FilterStreamSpecRaw)) { throw new ExprValidationException( "From-clause must contain only streams and cannot contain patterns or other constructs"); } streams.Put(streamNum, (FilterStreamSpecRaw) rawStreamSpec); } // compile offered streams IList<StreamSpecCompiled> streamSpecCompileds = new List<StreamSpecCompiled>(); originatingStreamToViewableStream = new int[select.StreamSpecs.Count]; for (var streamNum = 0; streamNum < select.StreamSpecs.Count; streamNum++) { var filter = streams.Get(streamNum); var inputPort = FindInputPort(filter.RawFilterSpec.EventTypeName, context.InputPorts); if (inputPort == null) { throw new ExprValidationException( "Failed to find stream '" + filter.RawFilterSpec.EventTypeName + "' among input ports, input ports are " + CompatExtensions.RenderAny(GetInputPortNames(context.InputPorts))); } var inputPortValue = inputPort.Value; var eventType = inputPortValue.Value.TypeDesc.EventType; originatingStreamToViewableStream[inputPortValue.Key] = streamNum; var streamAlias = filter.OptionalStreamName; var filterSpecCompiled = new FilterSpecCompiled( eventType, streamAlias, new IList<FilterSpecParamForge>[] { new EmptyList<FilterSpecParamForge>() }, null); ViewSpec[] viewSpecs = select.StreamSpecs[streamNum].ViewSpecs; var filterStreamSpecCompiled = new FilterStreamSpecCompiled( filterSpecCompiled, viewSpecs, streamAlias, StreamSpecOptions.DEFAULT); streamSpecCompileds.Add(filterStreamSpecCompiled); } // create compiled statement spec var selectClauseCompiled = StatementLifecycleSvcUtil.CompileSelectClause(select.SelectClauseSpec); Attribute[] mergedAnnotations = AnnotationUtil.MergeAnnotations( context.StatementRawInfo.Annotations, context.OperatorAnnotations); mergedAnnotations = AddObjectArrayRepresentation(mergedAnnotations); var streamSpecArray = streamSpecCompileds.ToArray(); // determine if snapshot output is needed var outputLimitSpec = select.OutputLimitSpec; if (iterate) { if (outputLimitSpec != null) { throw new ExprValidationException("Output rate limiting is not supported with 'iterate'"); } outputLimitSpec = new OutputLimitSpec(OutputLimitLimitType.SNAPSHOT, OutputLimitRateType.TERM); select.OutputLimitSpec = outputLimitSpec; } // override the statement spec var compiled = new StatementSpecCompiled( select, streamSpecArray, selectClauseCompiled, mergedAnnotations, groupByExpressions, new EmptyList<ExprSubselectNode>(), new EmptyList<ExprDeclaredNode>(), new EmptyList<ExprTableAccessNode>()); var dataflowClassPostfix = context.CodegenEnv.ClassPostfix + "__dfo" + context.OperatorNumber; var containerStatement = context.Base.StatementSpec; context.Base.StatementSpec = compiled; // make forgable var forablesResult = StmtForgeMethodSelectUtil.Make( context.Container, true, context.CodegenEnv.Namespace, dataflowClassPostfix, context.Base, context.Services); // return the statement spec context.Base.StatementSpec = containerStatement; EventType outputEventType = forablesResult.EventType; var initializeResult = new DataFlowOpForgeInitializeResult(); initializeResult.TypeDescriptors = new[] {new GraphTypeDesc(false, true, outputEventType)}; initializeResult.AdditionalForgables = forablesResult.ForgeResult; foreach (StmtClassForgable forgable in forablesResult.ForgeResult.Forgables) { if (forgable.ForgableType == StmtClassForgableType.AIFACTORYPROVIDER) { classNameAIFactoryProvider = forgable.ClassName; } else if (forgable.ForgableType == StmtClassForgableType.FIELDS) { classNameFieldsFactoryProvider = forgable.ClassName; } } return initializeResult; }
public override int GetHashCode() { return CompatExtensions.Hash(Array); }
public static StreamTypeService BuildDefineStreamTypeServiceDefine( StatementContext statementContext, LinkedHashMap <String, Pair <int, bool> > variableStreams, MatchRecognizeDefineItem defineItem, IDictionary <String, ISet <String> > visibilityByIdentifier, EventType parentViewType) { if (!variableStreams.ContainsKey(defineItem.Identifier)) { throw new ExprValidationException("Variable '" + defineItem.Identifier + "' does not occur in pattern"); } var streamNamesDefine = new String[variableStreams.Count + 1]; var typesDefine = new EventType[variableStreams.Count + 1]; var isIStreamOnly = new bool[variableStreams.Count + 1]; CompatExtensions.Fill(isIStreamOnly, true); var streamNumDefine = variableStreams.Get(defineItem.Identifier).First; streamNamesDefine[streamNumDefine] = defineItem.Identifier; typesDefine[streamNumDefine] = parentViewType; // add visible single-value var visibles = visibilityByIdentifier.Get(defineItem.Identifier); var hasVisibleMultimatch = false; if (visibles != null) { foreach (var visible in visibles) { var def = variableStreams.Get(visible); if (!def.Second) { streamNamesDefine[def.First] = visible; typesDefine[def.First] = parentViewType; } else { hasVisibleMultimatch = true; } } } // compile multi-matching event type (in last position), if any are used if (hasVisibleMultimatch) { IDictionary <String, Object> multievent = new LinkedHashMap <String, Object>(); foreach (var entry in variableStreams) { var identifier = entry.Key; if (entry.Value.Second) { if (visibles.Contains(identifier)) { multievent.Put( identifier, new EventType[] { parentViewType }); } else { multievent.Put("esper_matchrecog_internal", null); } } } var multimatch = statementContext.EventAdapterService.CreateAnonymousObjectArrayType( "esper_matchrecog_internal", multievent); typesDefine[typesDefine.Length - 1] = multimatch; streamNamesDefine[streamNamesDefine.Length - 1] = multimatch.Name; } return(new StreamTypeServiceImpl( typesDefine, streamNamesDefine, isIStreamOnly, statementContext.EngineURI, false)); }
public void Next() { if (_iterationNumber == 0 && _initialDelayMSec > 0) { try { Thread.Sleep((int)_initialDelayMSec); } catch (ThreadInterruptedException) { graphContext.SubmitSignal( new DataFlowSignalFinalMarker()); } } if (_iterationNumber > 0 && _periodDelayMSec > 0) { var nsecDelta = _lastSendTime - PerformanceObserver.NanoTime; var sleepTime = _periodDelayMSec - nsecDelta / 1000000; if (sleepTime > 0) { try { Thread.Sleep((int)sleepTime); } catch (ThreadInterruptedException) { graphContext.SubmitSignal( new DataFlowSignalFinalMarker()); } } } if (iterations > 0 && _iterationNumber >= iterations) { graphContext.SubmitSignal( new DataFlowSignalFinalMarker()); } else { _iterationNumber++; if (_evaluators != null) { var evaluateParams = new EvaluateParams(null, true, null); var row = new Object[_evaluators.Length]; for (var i = 0; i < row.Length; i++) { if (_evaluators[i] != null) { row[i] = _evaluators[i].Evaluate(evaluateParams); } } if (Log.IsDebugEnabled) { Log.Debug("BeaconSource submitting row " + CompatExtensions.Render(row)); } Object outputEvent = row; if (_manufacturer != null) { if (!_produceEventBean) { outputEvent = _manufacturer.MakeUnderlying(row); } else { outputEvent = _manufacturer.Make(row); } } graphContext.Submit(outputEvent); } else { if (Log.IsDebugEnabled) { Log.Debug("BeaconSource submitting empty row"); } graphContext.Submit(new Object[0]); } if (interval > 0) { _lastSendTime = PerformanceObserver.NanoTime; } } }
private static ParseMakePropertiesDesc SetupProperties(bool requireOneMatch, string[] propertyNamesOffered, EventType outputEventType, StatementContext statementContext, string dateFormat) { var writeables = EventTypeUtility.GetWriteableProperties(outputEventType, false); IList <int> indexesList = new List <int>(); IList <SimpleTypeParser> parserList = new List <SimpleTypeParser>(); IList <WriteablePropertyDescriptor> writablesList = new List <WriteablePropertyDescriptor>(); for (var i = 0; i < propertyNamesOffered.Length; i++) { var propertyName = propertyNamesOffered[i]; Type propertyType; try { propertyType = outputEventType.GetPropertyType(propertyName); } catch (PropertyAccessException ex) { throw new EPException("Invalid property name '" + propertyName + "': " + ex.Message, ex); } if (propertyType == null) { continue; } SimpleTypeParser parser; if ((propertyType == typeof(DateTime)) || (propertyType == typeof(DateTimeOffset)) || (propertyType == typeof(DateTimeEx))) { var dateTimeFormat = dateFormat != null ? DateTimeFormat.For(dateFormat) : DateTimeFormat.ISO_DATE_TIME; if (propertyType == typeof(DateTime?)) { parser = new ProxySimpleTypeParser( text => (dateTimeFormat.Parse(text)?.DateTime)?.DateTime); } else if (propertyType == typeof(DateTime)) { parser = new ProxySimpleTypeParser( text => dateTimeFormat.Parse(text).DateTime.DateTime); } else if (propertyType == typeof(DateTimeOffset?)) { parser = new ProxySimpleTypeParser( text => dateTimeFormat.Parse(text)?.DateTime); } else if (propertyType == typeof(DateTimeOffset)) { parser = new ProxySimpleTypeParser( text => dateTimeFormat.Parse(text).DateTime); } else { parser = new ProxySimpleTypeParser( text => dateTimeFormat.Parse(text)); } } else { parser = SimpleTypeParserFactory.GetParser(propertyType); } var writable = EventTypeUtility.FindWritable(propertyName, writeables); if (writable == null) { continue; } indexesList.Add(i); parserList.Add(parser); writablesList.Add(writable); } if (indexesList.IsEmpty() && requireOneMatch) { throw new EPException( "Failed to match any of the properties " + CompatExtensions.RenderAny(propertyNamesOffered) + " to the event type properties of event type '" + outputEventType.Name + "'"); } var parsers = parserList.ToArray(); var writables = writablesList.ToArray(); var indexes = CollectionUtil.IntArray(indexesList); EventBeanManufacturer manufacturer; try { manufacturer = EventTypeUtility.GetManufacturer( outputEventType, writables, statementContext.ImportServiceRuntime, false, statementContext.EventTypeAvroHandler) .GetManufacturer(statementContext.EventBeanTypedEventFactory); } catch (EventBeanManufactureException e) { throw new EPException("Event type '" + outputEventType.Name + "' cannot be written to: " + e.Message, e); } return(new ParseMakePropertiesDesc(indexes, parsers, manufacturer)); }
public override int GetHashCode() { int result = CompatExtensions.Hash(HashIndexedProps); result = 31 * result + CompatExtensions.Hash(RangeIndexedProps); return result; }
public static void SummarizeUnderlying( object underlying, TextWriter writer) { CompatExtensions.RenderAny(underlying, writer); }
internal static void AssertFileConfig(Configuration config) { // assert name for class Assert.AreEqual(2, config.EventTypeAutoNamePackages.Count); Assert.AreEqual("com.mycompany.eventsone", config.EventTypeAutoNamePackages.ToArray()[0]); Assert.AreEqual("com.mycompany.eventstwo", config.EventTypeAutoNamePackages.ToArray()[1]); // assert name for class Assert.AreEqual(3, config.EventTypeNames.Count); Assert.AreEqual("com.mycompany.myapp.MySampleEventOne", config.EventTypeNames.Get("MySampleEventOne")); Assert.AreEqual("com.mycompany.myapp.MySampleEventTwo", config.EventTypeNames.Get("MySampleEventTwo")); Assert.AreEqual("com.mycompany.package.MyLegacyTypeEvent", config.EventTypeNames.Get("MyLegacyTypeEvent")); // assert auto imports Assert.AreEqual(10, config.Imports.Count); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc(typeof(NameAttribute).Namespace))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.espertech.esper.client.annotation"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.espertech.esper.dataflow.ops"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.mycompany.myapp"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.mycompany.myapp.ClassOne"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.mycompany.myapp", "AssemblyA"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.mycompany.myapp", "AssemblyB.dll"))); Assert.IsTrue(config.Imports.Contains(new AutoImportDesc("com.mycompany.myapp.ClassTwo", "AssemblyB.dll"))); Assert.That(config.AnnotationImports.Count, Is.EqualTo(2)); Assert.That(config.AnnotationImports, Contains.Item(new AutoImportDesc("com.mycompany.myapp.annotations"))); Assert.That(config.AnnotationImports, Contains.Item(new AutoImportDesc("com.mycompany.myapp.annotations.ClassOne"))); // assert XML DOM - no schema Assert.AreEqual(2, config.EventTypesXMLDOM.Count); var noSchemaDesc = config.EventTypesXMLDOM.Get("MyNoSchemaXMLEventName"); Assert.AreEqual("MyNoSchemaEvent", noSchemaDesc.RootElementName); Assert.AreEqual("/myevent/element1", noSchemaDesc.XPathProperties.Get("element1").XPath); Assert.AreEqual(XPathResultType.Number, noSchemaDesc.XPathProperties.Get("element1").ResultType); Assert.AreEqual(null, noSchemaDesc.XPathProperties.Get("element1").OptionalCastToType); Assert.IsNull(noSchemaDesc.XPathFunctionResolver); Assert.IsNull(noSchemaDesc.XPathVariableResolver); Assert.IsFalse(noSchemaDesc.IsXPathPropertyExpr); // assert XML DOM - with schema var schemaDesc = config.EventTypesXMLDOM.Get("MySchemaXMLEventName"); Assert.AreEqual("MySchemaEvent", schemaDesc.RootElementName); Assert.AreEqual("MySchemaXMLEvent.xsd", schemaDesc.SchemaResource); Assert.AreEqual("actual-xsd-text-here", schemaDesc.SchemaText); Assert.AreEqual("samples:schemas:simpleSchema", schemaDesc.RootElementNamespace); Assert.AreEqual("default-name-space", schemaDesc.DefaultNamespace); Assert.AreEqual("/myevent/element2", schemaDesc.XPathProperties.Get("element2").XPath); Assert.AreEqual(XPathResultType.String, schemaDesc.XPathProperties.Get("element2").ResultType); Assert.AreEqual(typeof(long), schemaDesc.XPathProperties.Get("element2").OptionalCastToType); Assert.AreEqual("/bookstore/book", schemaDesc.XPathProperties.Get("element3").XPath); Assert.AreEqual(XPathResultType.NodeSet, schemaDesc.XPathProperties.Get("element3").ResultType); Assert.AreEqual(null, schemaDesc.XPathProperties.Get("element3").OptionalCastToType); Assert.AreEqual("MyOtherXMLNodeEvent", schemaDesc.XPathProperties.Get("element3").OptionalEventTypeName); Assert.AreEqual(1, schemaDesc.NamespacePrefixes.Count); Assert.AreEqual("samples:schemas:simpleSchema", schemaDesc.NamespacePrefixes.Get("ss")); Assert.IsFalse(schemaDesc.IsXPathResolvePropertiesAbsolute); Assert.AreEqual("com.mycompany.OptionalFunctionResolver", schemaDesc.XPathFunctionResolver); Assert.AreEqual("com.mycompany.OptionalVariableResolver", schemaDesc.XPathVariableResolver); Assert.IsTrue(schemaDesc.IsXPathPropertyExpr); Assert.IsFalse(schemaDesc.IsEventSenderValidatesRoot); Assert.IsFalse(schemaDesc.IsAutoFragment); Assert.AreEqual("startts", schemaDesc.StartTimestampPropertyName); Assert.AreEqual("endts", schemaDesc.EndTimestampPropertyName); // assert mapped events Assert.AreEqual(1, config.EventTypesMapEvents.Count); Assert.IsTrue(config.EventTypesMapEvents.Keys.Contains("MyMapEvent")); Properties expectedProps = new Properties(); expectedProps.Put("myInt", "int"); expectedProps.Put("myString", "string"); Assert.AreEqual(expectedProps, config.EventTypesMapEvents.Get("MyMapEvent")); Assert.AreEqual(1, config.MapTypeConfigurations.Count); var superTypes = config.MapTypeConfigurations.Get("MyMapEvent").SuperTypes; EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "MyMapSuperType1", "MyMapSuperType2" }, superTypes.ToArray()); Assert.AreEqual("startts", config.MapTypeConfigurations.Get("MyMapEvent").StartTimestampPropertyName); Assert.AreEqual("endts", config.MapTypeConfigurations.Get("MyMapEvent").EndTimestampPropertyName); // assert objectarray events Assert.AreEqual(1, config.EventTypesNestableObjectArrayEvents.Count); Assert.IsTrue(config.EventTypesNestableObjectArrayEvents.ContainsKey("MyObjectArrayEvent")); IDictionary <string, object> expectedPropsObjectArray = new Dictionary <string, object>(); expectedPropsObjectArray.Put("myInt", "int"); expectedPropsObjectArray.Put("myString", "string"); Assert.That(config.EventTypesNestableObjectArrayEvents.Get("MyObjectArrayEvent"), Is.InstanceOf <IDictionary <string, object> >()); Assert.That(config.EventTypesNestableObjectArrayEvents.Get("MyObjectArrayEvent").AsBasicDictionary <string, object>(), Is.EqualTo(expectedPropsObjectArray)); Assert.AreEqual(expectedPropsObjectArray, config.EventTypesNestableObjectArrayEvents.Get("MyObjectArrayEvent")); Assert.AreEqual(1, config.ObjectArrayTypeConfigurations.Count); var superTypesOA = config.ObjectArrayTypeConfigurations.Get("MyObjectArrayEvent").SuperTypes; EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "MyObjectArraySuperType1", "MyObjectArraySuperType2" }, superTypesOA.ToArray()); Assert.AreEqual("startts", config.ObjectArrayTypeConfigurations.Get("MyObjectArrayEvent").StartTimestampPropertyName); Assert.AreEqual("endts", config.ObjectArrayTypeConfigurations.Get("MyObjectArrayEvent").EndTimestampPropertyName); // assert avro events Assert.AreEqual(2, config.EventTypesAvro.Count); ConfigurationEventTypeAvro avroOne = config.EventTypesAvro.Get("MyAvroEvent"); Assert.AreEqual("{\"type\":\"record\",\"name\":\"typename\",\"fields\":[{\"name\":\"num\",\"type\":\"int\"}]}", avroOne.AvroSchemaText); Assert.IsNull(avroOne.AvroSchema); Assert.IsNull(avroOne.StartTimestampPropertyName); Assert.IsNull(avroOne.EndTimestampPropertyName); Assert.IsTrue(avroOne.SuperTypes.IsEmpty()); ConfigurationEventTypeAvro avroTwo = config.EventTypesAvro.Get("MyAvroEventTwo"); Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyAvroEvent\",\"fields\":[{\"name\":\"carId\",\"type\":\"int\"},{\"name\":\"carType\",\"type\":{\"type\":\"string\",\"avro.string\":\"string\"}}]}", avroTwo.AvroSchemaText); Assert.AreEqual("startts", avroTwo.StartTimestampPropertyName); Assert.AreEqual("endts", avroTwo.EndTimestampPropertyName); Assert.AreEqual("[SomeSuperAvro, SomeSuperAvroTwo]", CompatExtensions.Render(avroTwo.SuperTypes)); // assert legacy type declaration Assert.AreEqual(1, config.EventTypesLegacy.Count); var legacy = config.EventTypesLegacy.Get("MyLegacyTypeEvent"); Assert.AreEqual(CodeGenerationEnum.ENABLED, legacy.CodeGeneration); Assert.AreEqual(AccessorStyleEnum.PUBLIC, legacy.AccessorStyle); Assert.AreEqual(1, legacy.FieldProperties.Count); Assert.AreEqual("myFieldName", legacy.FieldProperties[0].AccessorFieldName); Assert.AreEqual("myfieldprop", legacy.FieldProperties[0].Name); Assert.AreEqual(1, legacy.MethodProperties.Count); Assert.AreEqual("myAccessorMethod", legacy.MethodProperties[0].AccessorMethodName); Assert.AreEqual("mymethodprop", legacy.MethodProperties[0].Name); Assert.AreEqual(PropertyResolutionStyle.CASE_INSENSITIVE, legacy.PropertyResolutionStyle); Assert.AreEqual("com.mycompany.myapp.MySampleEventFactory.createMyLegacyTypeEvent", legacy.FactoryMethod); Assert.AreEqual("myCopyMethod", legacy.CopyMethod); Assert.AreEqual("startts", legacy.StartTimestampPropertyName); Assert.AreEqual("endts", legacy.EndTimestampPropertyName); // assert database reference - data source config Assert.AreEqual(2, config.DatabaseReferences.Count); ConfigurationDBRef configDBRef = config.DatabaseReferences.Get("mydb1"); DbDriverFactoryConnection dsDef = (DbDriverFactoryConnection)configDBRef.ConnectionFactoryDesc; Assert.AreEqual("com.espertech.esper.epl.db.drivers.DbDriverMySQL", dsDef.Driver.GetType().FullName); Assert.AreEqual("Server=mysql-server;Database=tempdb;Uid=esper;Pwd=3sp3rP@ssw0rd;", dsDef.Driver.ConnectionString); Assert.AreEqual(ConnectionLifecycleEnum.POOLED, configDBRef.ConnectionLifecycle); Assert.IsNull(configDBRef.ConnectionSettings.AutoCommit); Assert.IsNull(configDBRef.ConnectionSettings.Catalog); Assert.IsNull(configDBRef.ConnectionSettings.TransactionIsolation); var lruCache = (ConfigurationLRUCache)configDBRef.DataCacheDesc; Assert.AreEqual(10, lruCache.Size); Assert.AreEqual(ConfigurationDBRef.ColumnChangeCaseEnum.LOWERCASE, configDBRef.ColumnChangeCase); Assert.AreEqual(ConfigurationDBRef.MetadataOriginEnum.SAMPLE, configDBRef.MetadataRetrievalEnum); //Assert.AreEqual(2, configDBRef.SqlTypesMapping.Count); //Assert.AreEqual("int", configDBRef.SqlTypesMapping[2]); //Assert.AreEqual("float", configDBRef.SqlTypesMapping[6]); // assert database reference - driver manager config configDBRef = config.DatabaseReferences.Get("mydb2"); DbDriverFactoryConnection dmDef = (DbDriverFactoryConnection)configDBRef.ConnectionFactoryDesc; Assert.AreEqual("com.espertech.esper.epl.db.drivers.DbDriverODBC", dmDef.Driver.GetType().FullName); Assert.AreEqual( "Driver={MySQL ODBC 5.3 Unicode Driver};Server=mysql-server;Database=test;User=esper;Password=3sp3rP@ssw0rd;Option=3", dmDef.Driver.ConnectionString); Assert.AreEqual(ConnectionLifecycleEnum.RETAIN, configDBRef.ConnectionLifecycle); Assert.AreEqual(false, configDBRef.ConnectionSettings.AutoCommit); Assert.AreEqual("test", configDBRef.ConnectionSettings.Catalog); Assert.AreEqual(IsolationLevel.ReadCommitted, configDBRef.ConnectionSettings.TransactionIsolation); ConfigurationExpiryTimeCache expCache = (ConfigurationExpiryTimeCache)configDBRef.DataCacheDesc; Assert.AreEqual(60.5, expCache.MaxAgeSeconds); Assert.AreEqual(120.1, expCache.PurgeIntervalSeconds); Assert.AreEqual(ConfigurationCacheReferenceType.HARD, expCache.CacheReferenceType); Assert.AreEqual(ConfigurationDBRef.ColumnChangeCaseEnum.UPPERCASE, configDBRef.ColumnChangeCase); Assert.AreEqual(ConfigurationDBRef.MetadataOriginEnum.METADATA, configDBRef.MetadataRetrievalEnum); //Assert.AreEqual(1, configDBRef.SqlTypesMapping.Count); //Assert.AreEqual("System.String", configDBRef.SqlTypesMapping.Get(99)); // assert custom view implementations var configViews = config.PlugInViews; Assert.AreEqual(2, configViews.Count); for (var i = 0; i < configViews.Count; i++) { var entry = configViews[i]; Assert.AreEqual("ext" + i, entry.Namespace); Assert.AreEqual("myview" + i, entry.Name); Assert.AreEqual("com.mycompany.MyViewFactory" + i, entry.FactoryClassName); } // assert custom virtual data window implementations var configVDW = config.PlugInVirtualDataWindows; Assert.AreEqual(2, configVDW.Count); for (var i = 0; i < configVDW.Count; i++) { var entry = configVDW[i]; Assert.AreEqual("vdw" + i, entry.Namespace); Assert.AreEqual("myvdw" + i, entry.Name); Assert.AreEqual("com.mycompany.MyVdwFactory" + i, entry.FactoryClassName); if (i == 1) { Assert.AreEqual("abc", entry.Config); } } // assert adapter loaders parsed var plugins = config.PluginLoaders; Assert.AreEqual(2, plugins.Count); var pluginOne = plugins[0]; Assert.AreEqual("Loader1", pluginOne.LoaderName); Assert.AreEqual("com.espertech.esper.support.plugin.SupportLoaderOne", pluginOne.TypeName); Assert.AreEqual(2, pluginOne.ConfigProperties.Count); Assert.AreEqual("val1", pluginOne.ConfigProperties.Get("name1")); Assert.AreEqual("val2", pluginOne.ConfigProperties.Get("name2")); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><sample-initializer xmlns=\"http://www.espertech.com/schema/esper\"><some-any-xml-can-be-here>This section for use by a plugin loader.</some-any-xml-can-be-here></sample-initializer>", pluginOne.ConfigurationXML); var pluginTwo = plugins[1]; Assert.AreEqual("Loader2", pluginTwo.LoaderName); Assert.AreEqual("com.espertech.esper.support.plugin.SupportLoaderTwo", pluginTwo.TypeName); Assert.AreEqual(0, pluginTwo.ConfigProperties.Count); // assert plug-in aggregation function loaded Assert.AreEqual(2, config.PlugInAggregationFunctions.Count); var pluginAgg = config.PlugInAggregationFunctions[0]; Assert.AreEqual("func1a", pluginAgg.Name); Assert.AreEqual("com.mycompany.MyMatrixAggregationMethod0Factory", pluginAgg.FactoryClassName); pluginAgg = config.PlugInAggregationFunctions[1]; Assert.AreEqual("func2a", pluginAgg.Name); Assert.AreEqual("com.mycompany.MyMatrixAggregationMethod1Factory", pluginAgg.FactoryClassName); // assert plug-in aggregation multi-function loaded Assert.AreEqual(1, config.PlugInAggregationMultiFunctions.Count); var pluginMultiAgg = config.PlugInAggregationMultiFunctions[0]; EPAssertionUtil.AssertEqualsExactOrder(new String[] { "func1", "func2" }, pluginMultiAgg.FunctionNames); Assert.AreEqual("com.mycompany.MyAggregationMultiFunctionFactory", pluginMultiAgg.MultiFunctionFactoryClassName); Assert.AreEqual(1, pluginMultiAgg.AdditionalConfiguredProperties.Count); Assert.AreEqual("value1", pluginMultiAgg.AdditionalConfiguredProperties.Get("prop1")); // assert plug-in singlerow function loaded Assert.AreEqual(2, config.PlugInSingleRowFunctions.Count); var pluginSingleRow = config.PlugInSingleRowFunctions[0]; Assert.AreEqual("com.mycompany.MyMatrixSingleRowMethod0", pluginSingleRow.FunctionClassName); Assert.AreEqual("method1", pluginSingleRow.FunctionMethodName); Assert.AreEqual("func3", pluginSingleRow.Name); Assert.AreEqual(ValueCacheEnum.DISABLED, pluginSingleRow.ValueCache); Assert.AreEqual(FilterOptimizableEnum.ENABLED, pluginSingleRow.FilterOptimizable); Assert.IsFalse(pluginSingleRow.IsRethrowExceptions); pluginSingleRow = config.PlugInSingleRowFunctions[1]; Assert.AreEqual("com.mycompany.MyMatrixSingleRowMethod1", pluginSingleRow.FunctionClassName); Assert.AreEqual("func4", pluginSingleRow.Name); Assert.AreEqual("method2", pluginSingleRow.FunctionMethodName); Assert.AreEqual(ValueCacheEnum.ENABLED, pluginSingleRow.ValueCache); Assert.AreEqual(FilterOptimizableEnum.DISABLED, pluginSingleRow.FilterOptimizable); Assert.IsTrue(pluginSingleRow.IsRethrowExceptions); Assert.AreEqual("XYZEventTypeName", pluginSingleRow.EventTypeName); // assert plug-in guard objects loaded Assert.AreEqual(4, config.PlugInPatternObjects.Count); var pluginPattern = config.PlugInPatternObjects[0]; Assert.AreEqual("com.mycompany.MyGuardFactory0", pluginPattern.FactoryClassName); Assert.AreEqual("ext0", pluginPattern.Namespace); Assert.AreEqual("guard1", pluginPattern.Name); Assert.AreEqual(ConfigurationPlugInPatternObject.PatternObjectTypeEnum.GUARD, pluginPattern.PatternObjectType); pluginPattern = config.PlugInPatternObjects[1]; Assert.AreEqual("com.mycompany.MyGuardFactory1", pluginPattern.FactoryClassName); Assert.AreEqual("ext1", pluginPattern.Namespace); Assert.AreEqual("guard2", pluginPattern.Name); Assert.AreEqual(ConfigurationPlugInPatternObject.PatternObjectTypeEnum.GUARD, pluginPattern.PatternObjectType); pluginPattern = config.PlugInPatternObjects[2]; Assert.AreEqual("com.mycompany.MyObserverFactory0", pluginPattern.FactoryClassName); Assert.AreEqual("ext0", pluginPattern.Namespace); Assert.AreEqual("observer1", pluginPattern.Name); Assert.AreEqual(ConfigurationPlugInPatternObject.PatternObjectTypeEnum.OBSERVER, pluginPattern.PatternObjectType); pluginPattern = config.PlugInPatternObjects[3]; Assert.AreEqual("com.mycompany.MyObserverFactory1", pluginPattern.FactoryClassName); Assert.AreEqual("ext1", pluginPattern.Namespace); Assert.AreEqual("observer2", pluginPattern.Name); Assert.AreEqual(ConfigurationPlugInPatternObject.PatternObjectTypeEnum.OBSERVER, pluginPattern.PatternObjectType); // assert engine defaults Assert.IsFalse(config.EngineDefaults.Threading.IsInsertIntoDispatchPreserveOrder); Assert.AreEqual(3000, config.EngineDefaults.Threading.InsertIntoDispatchTimeout); Assert.AreEqual(ConfigurationEngineDefaults.ThreadingConfig.Locking.SUSPEND, config.EngineDefaults.Threading.InsertIntoDispatchLocking); Assert.IsFalse(config.EngineDefaults.Threading.IsNamedWindowConsumerDispatchPreserveOrder); Assert.AreEqual(4000, config.EngineDefaults.Threading.NamedWindowConsumerDispatchTimeout); Assert.AreEqual(ConfigurationEngineDefaults.ThreadingConfig.Locking.SUSPEND, config.EngineDefaults.Threading.NamedWindowConsumerDispatchLocking); Assert.IsFalse(config.EngineDefaults.Threading.IsListenerDispatchPreserveOrder); Assert.AreEqual(2000, config.EngineDefaults.Threading.ListenerDispatchTimeout); Assert.AreEqual(ConfigurationEngineDefaults.ThreadingConfig.Locking.SUSPEND, config.EngineDefaults.Threading.ListenerDispatchLocking); Assert.IsTrue(config.EngineDefaults.Threading.IsThreadPoolInbound); Assert.IsTrue(config.EngineDefaults.Threading.IsThreadPoolOutbound); Assert.IsTrue(config.EngineDefaults.Threading.IsThreadPoolRouteExec); Assert.IsTrue(config.EngineDefaults.Threading.IsThreadPoolTimerExec); Assert.AreEqual(1, config.EngineDefaults.Threading.ThreadPoolInboundNumThreads); Assert.AreEqual(2, config.EngineDefaults.Threading.ThreadPoolOutboundNumThreads); Assert.AreEqual(3, config.EngineDefaults.Threading.ThreadPoolTimerExecNumThreads); Assert.AreEqual(4, config.EngineDefaults.Threading.ThreadPoolRouteExecNumThreads); Assert.AreEqual(1000, (int)config.EngineDefaults.Threading.ThreadPoolInboundCapacity); Assert.AreEqual(1500, (int)config.EngineDefaults.Threading.ThreadPoolOutboundCapacity); Assert.AreEqual(null, config.EngineDefaults.Threading.ThreadPoolTimerExecCapacity); Assert.AreEqual(2000, (int)config.EngineDefaults.Threading.ThreadPoolRouteExecCapacity); Assert.IsFalse(config.EngineDefaults.Threading.IsInternalTimerEnabled); Assert.AreEqual(1234567, config.EngineDefaults.Threading.InternalTimerMsecResolution); Assert.IsFalse(config.EngineDefaults.ViewResources.IsShareViews); Assert.IsTrue(config.EngineDefaults.ViewResources.IsAllowMultipleExpiryPolicies); Assert.IsTrue(config.EngineDefaults.ViewResources.IsIterableUnbound); Assert.AreEqual(PropertyResolutionStyle.DISTINCT_CASE_INSENSITIVE, config.EngineDefaults.EventMeta.ClassPropertyResolutionStyle); Assert.AreEqual(AccessorStyleEnum.PUBLIC, config.EngineDefaults.EventMeta.DefaultAccessorStyle); Assert.AreEqual(EventUnderlyingType.MAP, config.EngineDefaults.EventMeta.DefaultEventRepresentation); Assert.AreEqual(100, config.EngineDefaults.EventMeta.AnonymousCacheSize); Assert.IsFalse(config.EngineDefaults.EventMeta.AvroSettings.IsEnableAvro); Assert.IsFalse(config.EngineDefaults.EventMeta.AvroSettings.IsEnableNativeString); Assert.IsFalse(config.EngineDefaults.EventMeta.AvroSettings.IsEnableSchemaDefaultNonNull); Assert.AreEqual("myObjectValueTypeWidenerFactoryClass", config.EngineDefaults.EventMeta.AvroSettings.ObjectValueTypeWidenerFactoryClass); Assert.AreEqual("myTypeToRepresentationMapperClass", config.EngineDefaults.EventMeta.AvroSettings.TypeRepresentationMapperClass); Assert.IsTrue(config.EngineDefaults.Logging.IsEnableExecutionDebug); Assert.IsFalse(config.EngineDefaults.Logging.IsEnableTimerDebug); Assert.IsTrue(config.EngineDefaults.Logging.IsEnableQueryPlan); Assert.IsTrue(config.EngineDefaults.Logging.IsEnableADO); Assert.AreEqual("[%u] %m", config.EngineDefaults.Logging.AuditPattern); Assert.AreEqual(30000, config.EngineDefaults.Variables.MsecVersionRelease); Assert.AreEqual(3L, (long)config.EngineDefaults.Patterns.MaxSubexpressions); Assert.AreEqual(false, config.EngineDefaults.Patterns.IsMaxSubexpressionPreventStart); Assert.AreEqual(3L, (long)config.EngineDefaults.MatchRecognize.MaxStates); Assert.AreEqual(false, config.EngineDefaults.MatchRecognize.IsMaxStatesPreventStart); Assert.AreEqual(StreamSelector.RSTREAM_ISTREAM_BOTH, config.EngineDefaults.StreamSelection.DefaultStreamSelector); Assert.AreEqual(ConfigurationEngineDefaults.TimeSourceType.NANO, config.EngineDefaults.TimeSource.TimeSourceType); Assert.AreEqual(TimeUnit.MICROSECONDS, config.EngineDefaults.TimeSource.TimeUnit); Assert.IsTrue(config.EngineDefaults.Execution.IsPrioritized); Assert.IsTrue(config.EngineDefaults.Execution.IsFairlock); Assert.IsTrue(config.EngineDefaults.Execution.IsDisableLocking); Assert.IsTrue(config.EngineDefaults.Execution.IsAllowIsolatedService); Assert.AreEqual(ConfigurationEngineDefaults.ThreadingProfile.LARGE, config.EngineDefaults.Execution.ThreadingProfile); Assert.AreEqual(ConfigurationEngineDefaults.FilterServiceProfile.READWRITE, config.EngineDefaults.Execution.FilterServiceProfile); Assert.AreEqual(100, config.EngineDefaults.Execution.FilterServiceMaxFilterWidth); var metrics = config.EngineDefaults.MetricsReporting; Assert.IsTrue(metrics.IsEnableMetricsReporting); Assert.AreEqual(4000L, metrics.EngineInterval); Assert.AreEqual(500L, metrics.StatementInterval); Assert.IsFalse(metrics.IsThreading); Assert.AreEqual(2, metrics.StatementGroups.Count); //Assert.IsTrue(metrics.IsJmxEngineMetrics); var def = metrics.StatementGroups.Get("MyStmtGroup"); Assert.AreEqual(5000, def.Interval); Assert.IsTrue(def.IsDefaultInclude); Assert.AreEqual(50, def.NumStatements); Assert.IsTrue(def.IsReportInactive); Assert.AreEqual(5, def.Patterns.Count); Assert.AreEqual(def.Patterns[0], new Pair <StringPatternSet, Boolean>(new StringPatternSetRegex(".*"), true)); Assert.AreEqual(def.Patterns[1], new Pair <StringPatternSet, Boolean>(new StringPatternSetRegex(".*test.*"), false)); Assert.AreEqual(def.Patterns[2], new Pair <StringPatternSet, Boolean>(new StringPatternSetLike("%MyMetricsStatement%"), false)); Assert.AreEqual(def.Patterns[3], new Pair <StringPatternSet, Boolean>(new StringPatternSetLike("%MyFraudAnalysisStatement%"), true)); Assert.AreEqual(def.Patterns[4], new Pair <StringPatternSet, Boolean>(new StringPatternSetLike("%SomerOtherStatement%"), true)); def = metrics.StatementGroups.Get("MyStmtGroupTwo"); Assert.AreEqual(200, def.Interval); Assert.IsFalse(def.IsDefaultInclude); Assert.AreEqual(100, def.NumStatements); Assert.IsFalse(def.IsReportInactive); Assert.AreEqual(0, def.Patterns.Count); Assert.IsTrue(config.EngineDefaults.Language.IsSortUsingCollator); Assert.IsTrue(config.EngineDefaults.Expression.IsIntegerDivision); Assert.IsTrue(config.EngineDefaults.Expression.IsDivisionByZeroReturnsNull); Assert.IsFalse(config.EngineDefaults.Expression.IsSelfSubselectPreeval); Assert.IsFalse(config.EngineDefaults.Expression.IsUdfCache); Assert.IsFalse(config.EngineDefaults.Expression.IsExtendedAggregation); Assert.IsTrue(config.EngineDefaults.Expression.IsDuckTyping); Assert.AreEqual(2, config.EngineDefaults.Expression.MathContext.Precision); Assert.AreEqual(MidpointRounding.ToEven, config.EngineDefaults.Expression.MathContext.RoundingMode); Assert.AreEqual(TimeZoneHelper.GetTimeZoneInfo("GMT-4:00"), config.EngineDefaults.Expression.TimeZone); Assert.AreEqual(2, config.EngineDefaults.ExceptionHandling.HandlerFactories.Count); Assert.AreEqual("my.company.cep.LoggingExceptionHandlerFactory", config.EngineDefaults.ExceptionHandling.HandlerFactories[0]); Assert.AreEqual("my.company.cep.AlertExceptionHandlerFactory", config.EngineDefaults.ExceptionHandling.HandlerFactories[1]); Assert.AreEqual(2, config.EngineDefaults.ConditionHandling.HandlerFactories.Count); Assert.AreEqual("my.company.cep.LoggingConditionHandlerFactory", config.EngineDefaults.ConditionHandling.HandlerFactories[0]); Assert.AreEqual("my.company.cep.AlertConditionHandlerFactory", config.EngineDefaults.ConditionHandling.HandlerFactories[1]); Assert.AreEqual("abc", config.EngineDefaults.Scripts.DefaultDialect); Assert.AreEqual(ConfigurationEngineDefaults.UndeployRethrowPolicy.RETHROW_FIRST, config.EngineDefaults.ExceptionHandling.UndeployRethrowPolicy); // variables Assert.AreEqual(3, config.Variables.Count); var variable = config.Variables.Get("var1"); Assert.AreEqual(typeof(int).FullName, variable.VariableType); Assert.AreEqual("1", variable.InitializationValue); Assert.IsFalse(variable.IsConstant); variable = config.Variables.Get("var2"); Assert.AreEqual(typeof(string).FullName, variable.VariableType); Assert.AreEqual(null, variable.InitializationValue); Assert.IsFalse(variable.IsConstant); variable = config.Variables.Get("var3"); Assert.IsTrue(variable.IsConstant); // method references Assert.AreEqual(2, config.MethodInvocationReferences.Count); var methodRef = config.MethodInvocationReferences.Get("abc"); expCache = (ConfigurationExpiryTimeCache)methodRef.DataCacheDesc; Assert.AreEqual(91.0, expCache.MaxAgeSeconds); Assert.AreEqual(92.2, expCache.PurgeIntervalSeconds); Assert.AreEqual(ConfigurationCacheReferenceType.WEAK, expCache.CacheReferenceType); methodRef = config.MethodInvocationReferences.Get("def"); lruCache = (ConfigurationLRUCache)methodRef.DataCacheDesc; Assert.AreEqual(20, lruCache.Size); // plug-in event representations Assert.AreEqual(2, config.PlugInEventRepresentation.Count); var rep = config.PlugInEventRepresentation.Get(new Uri("type://format/rep/name")); Assert.AreEqual("com.mycompany.MyPlugInEventRepresentation", rep.EventRepresentationTypeName); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><anyxml>test string event rep init</anyxml>", rep.Initializer); rep = config.PlugInEventRepresentation.Get(new Uri("type://format/rep/name2")); Assert.AreEqual("com.mycompany.MyPlugInEventRepresentation2", rep.EventRepresentationTypeName); Assert.AreEqual(null, rep.Initializer); // plug-in event types Assert.AreEqual(2, config.PlugInEventTypes.Count); var type = config.PlugInEventTypes.Get("MyEvent"); Assert.AreEqual(2, type.EventRepresentationResolutionURIs.Count); Assert.AreEqual("type://format/rep", type.EventRepresentationResolutionURIs[0].ToString()); Assert.AreEqual("type://format/rep2", type.EventRepresentationResolutionURIs[1].ToString()); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><anyxml>test string event type init</anyxml>", type.Initializer); type = config.PlugInEventTypes.Get("MyEvent2"); Assert.AreEqual(1, type.EventRepresentationResolutionURIs.Count); Assert.AreEqual("type://format/rep2", type.EventRepresentationResolutionURIs[0].ToString()); Assert.AreEqual(null, type.Initializer); // plug-in event representation resolution URIs when using a new name in a statement Assert.AreEqual(2, config.PlugInEventTypeResolutionURIs.Count); Assert.AreEqual("type://format/rep", config.PlugInEventTypeResolutionURIs[0].ToString()); Assert.AreEqual("type://format/rep2", config.PlugInEventTypeResolutionURIs[1].ToString()); // revision types Assert.AreEqual(1, config.RevisionEventTypes.Count); var configRev = config.RevisionEventTypes.Get("MyRevisionEvent"); Assert.AreEqual(1, configRev.NameBaseEventTypes.Count); Assert.IsTrue(configRev.NameBaseEventTypes.Contains("MyBaseEventName")); Assert.IsTrue(configRev.NameDeltaEventTypes.Contains("MyDeltaEventNameOne")); Assert.IsTrue(configRev.NameDeltaEventTypes.Contains("MyDeltaEventNameTwo")); EPAssertionUtil.AssertEqualsAnyOrder(new String[] { "id", "id2" }, configRev.KeyPropertyNames); Assert.AreEqual(PropertyRevisionEnum.MERGE_NON_NULL, configRev.PropertyRevision); // variance types Assert.AreEqual(1, config.VariantStreams.Count); var configVStream = config.VariantStreams.Get("MyVariantStream"); Assert.AreEqual(2, configVStream.VariantTypeNames.Count); Assert.IsTrue(configVStream.VariantTypeNames.Contains("MyEvenTypetNameOne")); Assert.IsTrue(configVStream.VariantTypeNames.Contains("MyEvenTypetNameTwo")); Assert.AreEqual(TypeVarianceEnum.ANY, configVStream.TypeVariance); }
public void TestClientAppAnnotationSimple() { var configuration = SupportConfigFactory.GetConfiguration(); configuration.AddEventType("Bean", typeof(SupportBean).FullName); _epService = EPServiceProviderManager.GetDefaultProvider(configuration); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } _epService.EPAdministrator.Configuration.AddImport("com.espertech.esper.regression.client"); _epService.EPAdministrator.Configuration.AddImport(typeof(SupportEnum)); var stmtText = "@MyAnnotationSimple " + "@MyAnnotationValue('abc') " + "@MyAnnotationValueDefaulted " + "@MyAnnotationValueEnum(SupportEnum=com.espertech.esper.support.bean.SupportEnum.ENUM_VALUE_3) " + "@MyAnnotationValuePair(StringVal='a',IntVal=-1,LongVal=2,BooleanVal=True,CharVal='x',ByteVal=10,ShortVal=20,DoubleVal=2.5) " + "@Name('STMTONE') " + "select * from Bean"; var stmtTextFormatted = "@MyAnnotationSimple" + NEWLINE + "@MyAnnotationValue('abc')" + NEWLINE + "@MyAnnotationValueDefaulted" + NEWLINE + "@MyAnnotationValueEnum(SupportEnum=com.espertech.esper.support.bean.SupportEnum.ENUM_VALUE_3)" + NEWLINE + "@MyAnnotationValuePair(StringVal='a',IntVal=-1,LongVal=2,BooleanVal=True,CharVal='x',ByteVal=10,ShortVal=20,DoubleVal=2.5)" + NEWLINE + "@Name('STMTONE')" + NEWLINE + "select *" + NEWLINE + "from Bean"; var stmt = _epService.EPAdministrator.CreateEPL(stmtText); var spi = (EPStatementSPI)stmt; Assert.AreEqual("select * from Bean", spi.ExpressionNoAnnotations); Assert.IsTrue(spi.IsNameProvided); var annotations = stmt.Annotations.ToArray(); annotations = SortAlpha(annotations); Assert.AreEqual(6, annotations.Length); Assert.AreEqual(typeof(MyAnnotationSimpleAttribute), annotations[0].GetType()); Assert.AreEqual("abc", ((MyAnnotationValueAttribute)annotations[1]).Value); Assert.AreEqual("XYZ", ((MyAnnotationValueDefaultedAttribute)annotations[2]).Value); Assert.AreEqual("STMTONE", ((NameAttribute)annotations[5]).Value); var enumval = (MyAnnotationValueEnumAttribute)annotations[3]; Assert.AreEqual(SupportEnum.ENUM_VALUE_2, enumval.SupportEnumDef); Assert.AreEqual(SupportEnum.ENUM_VALUE_3, enumval.SupportEnum); var pair = (MyAnnotationValuePairAttribute)annotations[4]; Assert.AreEqual("a", pair.StringVal); Assert.AreEqual(-1, pair.IntVal); Assert.AreEqual(2l, pair.LongVal); Assert.AreEqual(true, pair.BooleanVal); Assert.AreEqual('x', pair.CharVal); Assert.AreEqual(10, pair.ByteVal); Assert.AreEqual(20, pair.ShortVal); Assert.AreEqual(2.5, pair.DoubleVal); Assert.AreEqual("def", pair.StringValDef); Assert.AreEqual(100, pair.IntValDef); Assert.AreEqual(200l, pair.LongValDef); Assert.AreEqual(true, pair.BooleanValDef); Assert.AreEqual('D', pair.CharValDef); Assert.AreEqual(1.1, pair.DoubleValDef); // statement model var model = _epService.EPAdministrator.CompileEPL(stmtText); Assert.AreEqual(stmtText, model.ToEPL()); var textFormatted = model.ToEPL(new EPStatementFormatter(true)); Assert.AreEqual(stmtTextFormatted, textFormatted); var stmtTwo = _epService.EPAdministrator.Create(model); Assert.AreEqual(stmtTwo.Text, model.ToEPL()); Assert.AreEqual(6, stmtTwo.Annotations.Count); // test array stmtText = "@MyAnnotationValueArray(Value={1, 2, 3}, IntArray={4, 5}, DoubleArray={}, \nStringArray={\"X\"})\n" + "/* Test */ select * \nfrom Bean"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); annotations = stmt.Annotations.ToArray(); annotations = SortAlpha(annotations); Assert.AreEqual(1, annotations.Length); var array = (MyAnnotationValueArrayAttribute)annotations[0]; Assert.IsTrue(CompatExtensions.DeepEquals(ToObjectArray(array.Value), new Object[] { 1L, 2L, 3L })); Assert.IsTrue(CompatExtensions.DeepEquals(ToObjectArray(array.IntArray), new Object[] { 4, 5 })); Assert.IsTrue(CompatExtensions.DeepEquals(ToObjectArray(array.DoubleArray), new Object[] { })); Assert.IsTrue(CompatExtensions.DeepEquals(ToObjectArray(array.StringArray), new Object[] { "X" })); Assert.IsTrue(CompatExtensions.DeepEquals(ToObjectArray(array.StringArrayDef), new Object[] { "XYZ" })); // statement model model = _epService.EPAdministrator.CompileEPL(stmtText); Assert.AreEqual("@MyAnnotationValueArray(Value={1,2,3},IntArray={4,5},DoubleArray={},StringArray={'X'}) select * from Bean", model.ToEPL()); stmtTwo = _epService.EPAdministrator.Create(model); Assert.AreEqual(stmtTwo.Text, model.ToEPL()); Assert.AreEqual(1, stmtTwo.Annotations.Count); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public override int GetHashCode() { return CompatExtensions.HashAll(Start, End); }
/// <summary> /// Ctor. /// </summary> /// <param name="viewChain">views</param> /// <param name="matchRecognizeSpec">specification</param> /// <param name="agentInstanceContext">The agent instance context.</param> /// <param name="isUnbound">true for unbound stream</param> /// <param name="annotations">annotations</param> /// <exception cref="ExprValidationException"> /// Variable ' + defineItem.Identifier + ' has already been defined /// or /// An aggregate function may not appear in a DEFINE clause /// or /// Failed to validate condition expression for variable ' + defineItem.Identifier + ': + ex.Message /// or /// Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events /// or /// Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events /// or /// The measures clause requires that each expression utilizes the AS keyword to assign a column name /// </exception> /// <throws>ExprValidationException if validation fails</throws> public EventRowRegexNFAViewFactory( ViewFactoryChain viewChain, MatchRecognizeSpec matchRecognizeSpec, AgentInstanceContext agentInstanceContext, bool isUnbound, Attribute[] annotations, ConfigurationEngineDefaults.MatchRecognize matchRecognizeConfig) { var parentViewType = viewChain.EventType; _matchRecognizeSpec = matchRecognizeSpec; _isUnbound = isUnbound; _isIterateOnly = HintEnum.ITERATE_ONLY.GetHint(annotations) != null; _matchRecognizeConfig = matchRecognizeConfig; var statementContext = agentInstanceContext.StatementContext; // Expand repeats and permutations _expandedPatternNode = RegexPatternExpandUtil.Expand(matchRecognizeSpec.Pattern); // Determine single-row and multiple-row variables _variablesSingle = new LinkedHashSet <string>(); ISet <string> variablesMultiple = new LinkedHashSet <string>(); EventRowRegexHelper.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; _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 _streamVariables = new SortedDictionary <int, string>(); foreach (var entry in _variableStreams) { _streamVariables.Put(entry.Value.First, entry.Key); } // determine visibility rules var visibility = EventRowRegexHelper.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] = parentViewType; streamNum++; } foreach (var variableMultiple in variablesMultiple) { allStreamNames[streamNum] = variableMultiple; allTypes[streamNum] = parentViewType; 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 exprEvaluatorContext = new ExprEvaluatorContextStatement(statementContext, false); _isExprRequiresMultimatchState = new bool[_variableStreams.Count]; for (var defineIndex = 0; defineIndex < matchRecognizeSpec.Defines.Count; defineIndex++) { var 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 = EventRowRegexNFAViewFactoryHelper.BuildDefineStreamTypeServiceDefine(statementContext, _variableStreams, defineItem, visibility, parentViewType); var exprNodeResult = HandlePreviousFunctions(defineItem.Expression); var validationContext = new ExprValidationContext( typeServiceDefines, statementContext.MethodResolutionService, null, statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService, exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService, true, false, true, false, null, false); ExprNode validated; try { // validate validated = ExprNodeUtility.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; } } } _isDefineAsksMultimatches = CollectionUtil.IsAnySet(_isExprRequiresMultimatchState); _defineMultimatchEventBean = _isDefineAsksMultimatches ? EventRowRegexNFAViewFactoryHelper.GetDefineMultimatchBean(statementContext, _variableStreams, parentViewType) : null; // 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 var countPrev = 0; foreach (var entry in _callbacksPerIndex) { foreach (var callback in entry.Value) { callback.AssignedIndex = countPrev; } countPrev++; } // determine type service for use with MEASURE IDictionary <string, object> measureTypeDef = new LinkedHashMap <string, object>(); foreach (var variableSingle in _variablesSingle) { measureTypeDef.Put(variableSingle, parentViewType); } foreach (var variableMultiple in variablesMultiple) { measureTypeDef.Put(variableMultiple, new EventType[] { parentViewType }); } var outputEventTypeName = statementContext.StatementId + "_rowrecog"; _compositeEventType = (ObjectArrayEventType)statementContext.EventAdapterService.CreateAnonymousObjectArrayType(outputEventTypeName, measureTypeDef); StreamTypeService typeServiceMeasure = new StreamTypeServiceImpl(_compositeEventType, "MATCH_RECOGNIZE", true, statementContext.EngineURI); // find MEASURE clause aggregations var measureReferencesMultivar = false; IList <ExprAggregateNode> measureAggregateExprNodes = new List <ExprAggregateNode>(); foreach (var measureItem in matchRecognizeSpec.Measures) { ExprAggregateNodeUtil.GetAggregatesBottomUp(measureItem.Expr, measureAggregateExprNodes); } if (!measureAggregateExprNodes.IsEmpty()) { var isIStreamOnly = new bool[allStreamNames.Length]; CompatExtensions.Fill(isIStreamOnly, true); var typeServiceAggregateMeasure = new StreamTypeServiceImpl(allTypes, allStreamNames, isIStreamOnly, statementContext.EngineURI, false); var measureExprAggNodesPerStream = new Dictionary <int, IList <ExprAggregateNode> >(); foreach (var aggregateNode in measureAggregateExprNodes) { // validate absence of group-by aggregateNode.ValidatePositionals(); if (aggregateNode.OptionalLocalGroupBy != null) { throw new ExprValidationException("Match-recognize does not allow aggregation functions to specify a group-by"); } // validate node and params var count = 0; var visitor = new ExprNodeIdentifierVisitor(true); var validationContext = new ExprValidationContext( typeServiceAggregateMeasure, statementContext.MethodResolutionService, null, statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService, exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService, false, false, true, false, null, false); foreach (var child in aggregateNode.ChildNodes) { var validated = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGMEASURE, child, validationContext); validated.Accept(visitor); aggregateNode.SetChildNode(count++, new ExprNodeValidated(validated)); } validationContext = new ExprValidationContext( typeServiceMeasure, statementContext.MethodResolutionService, null, statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService, exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService, false, false, true, false, null, false); aggregateNode.Validate(validationContext); // verify properties used within the aggregation var aggregatedStreams = new HashSet <int>(); foreach (var pair in visitor.ExprProperties) { aggregatedStreams.Add(pair.First); } int?multipleVarStream = null; foreach (int streamNumAggregated in aggregatedStreams) { var variable = _streamVariables.Get(streamNumAggregated); if (variablesMultiple.Contains(variable)) { measureReferencesMultivar = true; 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); } var factoryDesc = AggregationServiceFactoryFactory.GetServiceMatchRecognize(_streamVariables.Count, measureExprAggNodesPerStream, typeServiceAggregateMeasure.EventTypes); _aggregationService = factoryDesc.AggregationServiceFactory.MakeService(agentInstanceContext); _aggregationExpressions = factoryDesc.Expressions; } else { _aggregationService = null; _aggregationExpressions = Collections.GetEmptyList <AggregationServiceAggExpressionDesc>(); } // 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, typeServiceMeasure, variablesMultiple, _variablesSingle, statementContext); measureItem.Expr = validated; rowTypeDef.Put(measureItem.Name, validated.ExprEvaluator.ReturnType); 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; } } } } _isCollectMultimatches = measureReferencesMultivar || _isDefineAsksMultimatches; // create rowevent type var rowEventTypeName = statementContext.StatementId + "_rowrecogrow"; _rowEventType = statementContext.EventAdapterService.CreateAnonymousMapType(rowEventTypeName, rowTypeDef, true); // validate partition-by expressions, if any if (!matchRecognizeSpec.PartitionByExpressions.IsEmpty()) { var typeServicePartition = new StreamTypeServiceImpl(parentViewType, "MATCH_RECOGNIZE_PARTITION", true, statementContext.EngineURI); var validated = new List <ExprNode>(); var validationContext = new ExprValidationContext( typeServicePartition, statementContext.MethodResolutionService, null, statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService, exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService, false, false, true, false, null, false); foreach (var partitionExpr in matchRecognizeSpec.PartitionByExpressions) { validated.Add(ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.MATCHRECOGPARTITION, partitionExpr, validationContext)); } matchRecognizeSpec.PartitionByExpressions = validated; } // validate interval if present if (matchRecognizeSpec.Interval != null) { var validationContext = new ExprValidationContext( new StreamTypeServiceImpl(statementContext.EngineURI, false), statementContext.MethodResolutionService, null, statementContext.SchedulingService, statementContext.VariableService, statementContext.TableService, exprEvaluatorContext, statementContext.EventAdapterService, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations, statementContext.ContextDescriptor, statementContext.ScriptingService, false, false, true, false, null, false); matchRecognizeSpec.Interval.Validate(validationContext); } }
private static void TrySend( RegressionEnvironment env, RegressionPath path, SupportMTUpdateListener listenerWindow, int numThreads, int numRepeats, int numConsumers) { var listenerConsumers = new SupportMTUpdateListener[numConsumers]; var compiled = env.Compile("select TheString, LongPrimitive from MyWindow", path); for (var i = 0; i < listenerConsumers.Length; i++) { var stmtName = "c" + i; try { env.Deployment.Deploy(compiled, new DeploymentOptions().WithStatementNameRuntime(ctx => stmtName)); } catch (EPDeployException e) { throw new EPException(e); } var stmtConsumer = env.Statement(stmtName); listenerConsumers[i] = new SupportMTUpdateListener(); stmtConsumer.AddListener(listenerConsumers[i]); } var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowConsume)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtNamedWindowConsumeCallable(Convert.ToString(i), env.Runtime, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); // compute list of expected IList<string> expectedIdsList = new List<string>(); for (var i = 0; i < numThreads; i++) { try { expectedIdsList.AddAll((IList<string>) future[i].Get()); } catch (Exception t) { throw new EPException(t); } } var expectedIds = expectedIdsList.ToArray(); Assert.AreEqual(numThreads * numRepeats, listenerWindow.NewDataList.Count); // old and new each // compute list of received for (var i = 0; i < listenerConsumers.Length; i++) { var newEvents = listenerConsumers[i].GetNewDataListFlattened(); var receivedIds = new string[newEvents.Length]; for (var j = 0; j < newEvents.Length; j++) { receivedIds[j] = (string) newEvents[j].Get("TheString"); } Assert.AreEqual(receivedIds.Length, expectedIds.Length); Array.Sort(receivedIds); Array.Sort(expectedIds); CompatExtensions.DeepEqualsWithType(expectedIds, receivedIds); } }
internal static void RunObjectArrInheritanceAssertion(EPServiceProvider epService) { var listeners = new SupportUpdateListener[5]; string[] statements = { "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb? as vb from RootEvent", // 0 "select base as vbase, sub1 as v1, sub2? as v2, suba? as va, subb? as vb from Sub1Event", // 1 "select base as vbase, sub1? as v1, sub2 as v2, suba? as va, subb? as vb from Sub2Event", // 2 "select base as vbase, sub1 as v1, sub2? as v2, suba as va, subb? as vb from SubAEvent", // 3 "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb as vb from SubBEvent" // 4 }; for (int i = 0; i < statements.Length; i++) { EPStatement statement = epService.EPAdministrator.CreateEPL(statements[i]); listeners[i] = new SupportUpdateListener(); statement.Events += listeners[i].Update; } string[] fields = "vbase,v1,v2,va,vb".Split(','); EventType type = epService.EPAdministrator.Configuration.GetEventType("SubAEvent"); Assert.AreEqual("base", type.PropertyDescriptors[0].PropertyName); Assert.AreEqual("sub1", type.PropertyDescriptors[1].PropertyName); Assert.AreEqual("suba", type.PropertyDescriptors[2].PropertyName); Assert.AreEqual(3, type.PropertyDescriptors.Count); type = epService.EPAdministrator.Configuration.GetEventType("SubBEvent"); Assert.AreEqual("[base, sub1, suba, subb]", CompatExtensions.Render(type.PropertyNames)); Assert.AreEqual(4, type.PropertyDescriptors.Count); type = epService.EPAdministrator.Configuration.GetEventType("Sub1Event"); Assert.AreEqual("[base, sub1]", CompatExtensions.Render(type.PropertyNames)); Assert.AreEqual(2, type.PropertyDescriptors.Count); type = epService.EPAdministrator.Configuration.GetEventType("Sub2Event"); Assert.AreEqual("[base, sub2]", CompatExtensions.Render(type.PropertyNames)); Assert.AreEqual(2, type.PropertyDescriptors.Count); epService.EPRuntime.SendEvent(new object[] { "a", "b", "x" }, "SubAEvent"); // base, sub1, suba EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, new object[] { "a", "b", null, "x", null }); Assert.IsFalse(listeners[2].IsInvoked || listeners[4].IsInvoked); EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, new object[] { "a", "b", null, "x", null }); EPAssertionUtil.AssertProps(listeners[3].AssertOneGetNewAndReset(), fields, new object[] { "a", "b", null, "x", null }); epService.EPRuntime.SendEvent(new object[] { "f1", "f2", "f4" }, "SubAEvent"); EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, new object[] { "f1", "f2", null, "f4", null }); Assert.IsFalse(listeners[2].IsInvoked || listeners[4].IsInvoked); EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, new object[] { "f1", "f2", null, "f4", null }); EPAssertionUtil.AssertProps(listeners[3].AssertOneGetNewAndReset(), fields, new object[] { "f1", "f2", null, "f4", null }); epService.EPRuntime.SendEvent(new object[] { "XBASE", "X1", "X2", "XY" }, "SubBEvent"); var values = new object[] { "XBASE", "X1", null, "X2", "XY" }; EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, values); Assert.IsFalse(listeners[2].IsInvoked); EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, values); EPAssertionUtil.AssertProps(listeners[3].AssertOneGetNewAndReset(), fields, values); EPAssertionUtil.AssertProps(listeners[4].AssertOneGetNewAndReset(), fields, values); epService.EPRuntime.SendEvent(new object[] { "YBASE", "Y1" }, "Sub1Event"); values = new object[] { "YBASE", "Y1", null, null, null }; EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, values); Assert.IsFalse(listeners[2].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, values); epService.EPRuntime.SendEvent(new object[] { "YBASE", "Y2" }, "Sub2Event"); values = new object[] { "YBASE", null, "Y2", null, null }; EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, values); Assert.IsFalse(listeners[1].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); EPAssertionUtil.AssertProps(listeners[2].AssertOneGetNewAndReset(), fields, values); epService.EPRuntime.SendEvent(new object[] { "ZBASE" }, "RootEvent"); values = new object[] { "ZBASE", null, null, null, null }; EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, values); Assert.IsFalse(listeners[1].IsInvoked || listeners[2].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); // try property not available try { epService.EPAdministrator.CreateEPL("select suba from Sub1Event"); Assert.Fail(); } catch (EPStatementException ex) { Assert.AreEqual("Error starting statement: Failed to validate select-clause expression 'suba': Property named 'suba' is not valid in any stream (did you mean 'sub1'?) [select suba from Sub1Event]", ex.Message); } // try supertype not Exists try { epService.EPAdministrator.Configuration.AddEventType("Sub1Event", MakeMap(""), new string[] { "doodle" }); Assert.Fail(); } catch (ConfigurationException ex) { Assert.AreEqual("Supertype by name 'doodle' could not be found", ex.Message); } }
public string ToQueryPlan() { return(GetType().Name + " indexProps=" + CompatExtensions.Render(_properties) + " keyStreamNums=" + CompatExtensions.Render(_keyStreamNums)); }