private LinkedHashMap getListViewExamples(){

			LinkedHashMap examples = new LinkedHashMap();

			ArrayList examplesSet = new ArrayList();

			examplesSet.Add (new ListViewGettingStartedFragment());
			examplesSet.Add (new ListViewLayoutsFragment());
			examplesSet.Add (new ListViewDeckOfCardsFragment());
			examplesSet.Add (new ListViewSlideFragment());
			examplesSet.Add (new ListViewWrapFragment());
			examplesSet.Add (new ListViewItemAnimationFragment());
			examplesSet.Add (new ListViewDataOperationsFragment());

			examples.Put("Features", examplesSet);

			examplesSet = new ArrayList();

			examplesSet.Add (new ListViewReorderFragment());
			examplesSet.Add (new ListViewSwipeToExecuteFragment());
			examplesSet.Add (new ListViewSwipeToRefreshFragment());
			examplesSet.Add (new ListViewManualLoadOnDemandFragment());
			examplesSet.Add (new ListViewDataAutomaticLoadOnDemandFragment());
			examplesSet.Add (new ListViewSelectionFragment());
			examplesSet.Add (new ListViewStickyHeadersFragment ());
			examplesSet.Add (new ListViewCollapsibleFragment ());

			examples.Put("Behaviors", examplesSet);

			return examples;
		
		}
		public void AddQuery(HbmQuery querySchema)
		{
			string queryName = querySchema.name;
			string queryText = querySchema.GetText();

			log.DebugFormat("Named query: {0} -> {1}", queryName, queryText);

			bool cacheable = querySchema.cacheable;
			string region = querySchema.cacheregion;
			int timeout = string.IsNullOrEmpty(querySchema.timeout) ? RowSelection.NoValue : int.Parse(querySchema.timeout);
			int fetchSize = querySchema.fetchsizeSpecified ? querySchema.fetchsize : -1;
			bool readOnly = querySchema.readonlySpecified ? querySchema.@readonly : false;
			string comment = querySchema.comment;

			FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema);
			CacheMode? cacheMode = (querySchema.cachemodeSpecified)
										? querySchema.cachemode.ToCacheMode()
										: null;

			IDictionary<string,string> parameterTypes = new LinkedHashMap<string,string>();

			var namedQuery = new NamedQueryDefinition(queryText, cacheable, region, timeout,
				fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes);

			mappings.AddQuery(queryName, namedQuery);
		}
		public void Contains()
		{
			LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);

			Assert.IsTrue(lhm.Contains("12341"));
			Assert.IsFalse(lhm.Contains("55555"));
		}
		public void Add()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			lhm.Add("55555", new Player("55555", "Monde Zondeki"));

			Assert.AreEqual(7, lhm.Count);
		}
Example #5
0
		private LinkedHashMap getChartExamples(){
			LinkedHashMap chartExamples = new LinkedHashMap();

			ArrayList result = new ArrayList();

			result.Add(new AreaSeriesFragment());
			result.Add(new LineSeriesFragment());
			result.Add(new CandleStickSeriesFragment());
			result.Add(new DoughnutSeriesFragment());
			result.Add(new HorizontalBarSeriesFragment());
			result.Add(new IndicatorSeriesFragment());
			result.Add(new OhlcSeriesFragment());
			result.Add(new PieSeriesFragment());
			result.Add(new ScatterBubbleSeriesFragment());
			result.Add(new ScatterPointSeriesFragment());
			result.Add(new SplineAreaSeriesFragment());
			result.Add(new SplineSeriesFragment());
			result.Add(new StackAreaSeriesFragment());
			result.Add(new StackBarSeriesFragment());
			result.Add(new StackSplineAreaSeriesFragment());
			result.Add(new VerticalBarSeriesFragment());

			chartExamples.Put("Series", result);

			result = new ArrayList();

			result.Add(new ChartLegendFragment());
			result.Add(new GridFeatureFragment());
			result.Add(new PalettesFragment());

			chartExamples.Put("Features", result);

			result = new ArrayList();

			result.Add(new PanAndZoomFragment());
			result.Add(new SelectionBehaviorFragment());
			result.Add(new TooltipBehaviorFragment());
			result.Add(new TrackballBehaviorFragment());

			chartExamples.Put("Behaviors", result);

			result = new ArrayList();

			result.Add(new DateTimeContinuousAxisFragment());
			result.Add(new MultipleAxesFragment());

			chartExamples.Put("Axes", result);

			result = new ArrayList();

			result.Add(new GridLineAnnotationFragment());
			result.Add(new PlotBandAnnotationFragment());

			chartExamples.Put("Annotations", result);

			return chartExamples;
		}
Example #6
0
        // function GIBBS-ASK(X, e, bn, N) returns an estimate of <b>P</b>(X|e)
        /**
         * The GIBBS-ASK algorithm in Figure 14.16. For answering queries given
         * evidence in a Bayesian Network.
         * 
         * @param X
         *            the query variables
         * @param e
         *            observed values for variables E
         * @param bn
         *            a Bayesian network specifying joint distribution
         *            <b>P</b>(X<sub>1</sub>,...,X<sub>n</sub>)
         * @param Nsamples
         *            the total number of samples to be generated
         * @return an estimate of <b>P</b>(X|e)
         */

        public CategoricalDistribution gibbsAsk(RandomVariable[] X,
                                                AssignmentProposition[] e, BayesianNetwork bn, int Nsamples)
        {
            // local variables: <b>N</b>, a vector of counts for each value of X,
            // initially zero
            double[] N = new double[ProbUtil
                .expectedSizeOfCategoricalDistribution(X)];
            // Z, the nonevidence variables in bn
            Set<RandomVariable> Z = new Set<RandomVariable>(
                bn.getVariablesInTopologicalOrder());
            foreach (AssignmentProposition ap in e)
            {
                Z.Remove(ap.getTermVariable());
            }
            // <b>x</b>, the current state of the network, initially copied from e
            Map<RandomVariable, Object> x = new LinkedHashMap<RandomVariable, Object>();
            foreach (AssignmentProposition ap in e)
            {
                x.Add(ap.getTermVariable(), ap.getValue());
            }

            // initialize <b>x</b> with random values for the variables in Z
            foreach (RandomVariable Zi in
            Z)
            {
                x.put(Zi, ProbUtil.randomSample(bn.getNode(Zi), x, randomizer));
            }

            // for j = 1 to N do
            for (int j = 0; j < Nsamples; j++)
            {
                // for each Z<sub>i</sub> in Z do
                foreach (RandomVariable Zi in
                Z)
                {
                    // set the value of Z<sub>i</sub> in <b>x</b> by sampling from
                    // <b>P</b>(Z<sub>i</sub>|mb(Z<sub>i</sub>))
                    x.put(Zi,
                          ProbUtil.mbRandomSample(bn.getNode(Zi), x, randomizer));
                }
                // Note: moving this outside the previous for loop,
                // as described in fig 14.6, as will only work
                // correctly in the case of a single query variable X.
                // However, when multiple query variables, rare events
                // will get weighted incorrectly if done above. In case
                // of single variable this does not happen as each possible
                // value gets * |Z| above, ending up with the same ratios
                // when normalized (i.e. its still more efficient to place
                // outside the loop).
                //
                // <b>N</b>[x] <- <b>N</b>[x] + 1
                // where x is the value of X in <b>x</b>
                N[ProbUtil.indexOf(X, x)] += 1.0;
            }
            // return NORMALIZE(<b>N</b>)
            return new ProbabilityTable(N, X).normalize();
        }
		private LinkedHashMap getSideDrawerExamples(){
			LinkedHashMap sideDrawerExamples = new LinkedHashMap();
			ArrayList result = new ArrayList();

			result.Add (new DrawerInitialSetupFragment());

			sideDrawerExamples.Put ("Init", result);

			return sideDrawerExamples;
		}
		public ExamplesAdapter(LinkedHashMap source){
			this.source = source;

			Java.Lang.Object[] k = new Java.Lang.Object[source.Size ()];
			int counter = 0;
			foreach (Java.Lang.Object o in this.source.KeySet()) {
				k [counter++] = o;
			}

			this.keys = k;
		}
		public void Clear()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Player p = new Player("78945", "Someone");
			lhm[p.Id] = p;

			lhm.Clear();
			Assert.AreEqual(0, lhm.Count);

			foreach (KeyValuePair<string, Player> pair in lhm)
				Assert.Fail("Should not be any entries but found Key = " + pair.Key + " and Value = " + pair.Value);
		}
		public void LastKeyLastValue()
		{
			LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			Assert.AreEqual(players[players.Length - 1].Id, lhm.LastKey);
			Assert.AreEqual(players[players.Length-1], lhm.LastValue);

			// override
			Player antWithSameId = new Player("12341", "Another");
			lhm[antWithSameId.Id] = antWithSameId;
			Assert.AreEqual(antWithSameId.Id, lhm.LastKey);
			Assert.AreEqual(antWithSameId, lhm.LastValue);
		}
		public void FirstKeyFirstValue()
		{
			LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			Assert.AreEqual(players[0].Id, lhm.FirstKey);
			Assert.AreEqual(players[0], lhm.FirstValue);

			// override First
			Player antWithSameId = new Player("12341", "Another");
			lhm[antWithSameId.Id] = antWithSameId;
			Assert.AreEqual(players[1].Id, lhm.FirstKey);
			Assert.AreEqual(players[1], lhm.FirstValue);
		}
Example #12
0
        // function PRIOR-SAMPLE(bn) returns an event sampled from the prior
        // specified by bn
        /**
         * The PRIOR-SAMPLE algorithm in Figure 14.13. A sampling algorithm that
         * generates events from a Bayesian network. Each variable is sampled
         * according to the conditional distribution given the values already
         * sampled for the variable's parents.
         * 
         * @param bn
         *            a Bayesian network specifying joint distribution
         *            <b>P</b>(X<sub>1</sub>,...,X<sub>n</sub>)
         * @return an event sampled from the prior specified by bn
         */

        public Map<RandomVariable, Object> priorSample(BayesianNetwork bn)
        {
            // x <- an event with n elements
            Map<RandomVariable, Object> x = new LinkedHashMap<RandomVariable, Object>();
            // foreach variable X<sub>i</sub> in X<sub>1</sub>,...,X<sub>n</sub> do
            foreach (RandomVariable Xi in bn.getVariablesInTopologicalOrder())
            {
                // x[i] <- a random sample from
                // <b>P</b>(X<sub>i</sub> | parents(X<sub>i</sub>))
                x.Add(Xi, ProbUtil.randomSample(bn.getNode(Xi), x, randomizer));
            }
            // return x
            return x;
        }
		public void AddSqlQuery(HbmSqlQuery querySchema)
		{
			mappings.AddSecondPass(delegate
				{
					string queryName = querySchema.name;
					string queryText = querySchema.GetText();
					bool cacheable = querySchema.cacheable;
					string region = querySchema.cacheregion;
					int timeout = string.IsNullOrEmpty(querySchema.timeout) ? RowSelection.NoValue : int.Parse(querySchema.timeout);
					int fetchSize = querySchema.fetchsizeSpecified ? querySchema.fetchsize : -1;
					bool readOnly = querySchema.readonlySpecified ? querySchema.@readonly : false;
					string comment = null;
					bool callable = querySchema.callable;
					string resultSetRef = querySchema.resultsetref;

					FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema);
					CacheMode? cacheMode = (querySchema.cachemodeSpecified)
												? querySchema.cachemode.ToCacheMode()
												: null;

					IDictionary<string,string> parameterTypes = new LinkedHashMap<string,string>();
					IList<string> synchronizedTables = GetSynchronizedTables(querySchema);

					NamedSQLQueryDefinition namedQuery;

					if (string.IsNullOrEmpty(resultSetRef))
					{
						ResultSetMappingDefinition definition =
							new ResultSetMappingBinder(Mappings).Create(querySchema);

						namedQuery = new NamedSQLQueryDefinition(queryText,
							definition.GetQueryReturns(), synchronizedTables, cacheable, region, timeout,
							fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes, callable);
					}
					else
						// TODO: check there is no actual definition elemnents when a ref is defined
						namedQuery = new NamedSQLQueryDefinition(queryText,
							resultSetRef, synchronizedTables, cacheable, region, timeout, fetchSize,
							flushMode, cacheMode, readOnly, comment, parameterTypes, callable);

					log.DebugFormat("Named SQL query: {0} -> {1}", queryName, namedQuery.QueryString);
					mappings.AddSQLQuery(queryName, namedQuery);
				});
		}
		private LinkedHashMap getDataFormExamples(){
			LinkedHashMap dataFormExamples = new LinkedHashMap();
			ArrayList result = new ArrayList();

			result.Add (new DataFormGettingStartedFragment());
			result.Add (new DataFormFeaturesFragment ());
			result.Add (new DataFormEditorsFragment ());
			result.Add (new DataFormValidationFragment ());
			result.Add (new DataFormGroupLayoutFragment ());
			result.Add (new DataFormPlaceholderLayoutFragment ());
			result.Add (new DataFormValidationBehaviorFragment ());
			result.Add (new DataFormValidationModeFragment ());
			result.Add (new DataFormJsonEditFragment ());
			result.Add (new DataFormSchemaSetupFragment ());

			dataFormExamples.Put ("Features", result);

			return dataFormExamples;
		}
		public void CopyTo()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			KeyValuePair<string, Player>[] destArray = new KeyValuePair<string, Player>[lhm.Count + 1];
			destArray[0] = new KeyValuePair<string, Player>("999", new Player("999", "The number nine"));
			lhm.CopyTo(destArray, 1);

			for (int i = 1; i < destArray.Length; i++)
			{
				Assert.AreEqual(players[i-1].Id, destArray[i].Key);
				Assert.AreEqual(players[i-1], destArray[i].Value);
			}
		}
		public void GetEnumeratorEmpty()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Assert.AreEqual(0, lhm.Count);

			int entries = 0;
			foreach (KeyValuePair<string, Player> pair in lhm)
				entries++;
			foreach (string s in lhm.Keys)
				entries++;
			foreach (Player value in lhm.Values)
				entries++;

			Assert.AreEqual(0, entries, "should not have any entries in the enumerators");
		}
		public void Remove()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);

			// remove an item that exists
			bool removed =lhm.Remove("23411");
			Assert.IsTrue(removed);
			Assert.AreEqual(5, lhm.Count);

			// try to remove an item that does not exist
			removed= lhm.Remove("65432");
			Assert.IsFalse(removed);
			Assert.AreEqual(5, lhm.Count);
		}
Example #18
0
 public FunctionSymbol(string name, Type retType, Scope scope, LinkedHashMap <string, BuiltInTypeSymbol> orderedArgs, CMMParser.CodeBlockContext context) : base(name, retType, scope)
 {
     this.orderedArgs = orderedArgs;
     this.context     = context;
 }
Example #19
0
        private void RunAssertionColDefPlain(EventRepresentationEnum eventRepresentationEnum)
        {
            EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, sbean " + typeof(SupportBean).FullName + ", col3.col4 int)");

            AssertTypeColDef(stmtCreate.EventType);
            EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");

            AssertTypeColDef(stmtSelect.EventType);

            stmtSelect.Dispose();
            stmtCreate.Dispose();

            // destroy and create differently
            stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col3 string, col4 int)");
            Assert.AreEqual(typeof(int), stmtCreate.EventType.GetPropertyType("col4"));
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);

            stmtCreate.Stop();

            // destroy and create differently
            stmtCreate = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col5 string, col6 int)");
            Assert.AreEqual(stmtCreate.EventType.UnderlyingType, eventRepresentationEnum.GetOutputClass());
            Assert.AreEqual(typeof(int), stmtCreate.EventType.GetPropertyType("col6"));
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);
            stmtSelect         = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");
            stmtSelect.Events += _listener.Update;
            Assert.AreEqual(stmtSelect.EventType.UnderlyingType, eventRepresentationEnum.GetOutputClass());

            // send event
            IDictionary <String, Object> data = new LinkedHashMap <String, Object>();

            data.Put("col5", "abc");
            data.Put("col6", 1);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(data.Values.ToArray(), "MyEventType");
            }
            else
            {
                _epService.EPRuntime.SendEvent(data, "MyEventType");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "col5,col6".Split(','), new Object[] { "abc", 1 });

            // assert type information
            EventTypeSPI typeSPI = (EventTypeSPI)stmtSelect.EventType;

            Assert.AreEqual(TypeClass.APPLICATION, typeSPI.Metadata.TypeClass);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PublicName);
            Assert.IsTrue(typeSPI.Metadata.IsApplicationConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfiguredStatic);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PrimaryName);

            // test non-enum create-schema
            String      epl           = "create" + eventRepresentationEnum.GetOutputTypeCreateSchemaName() + " schema MyEventTypeTwo as (col1 string, col2 int, sbean " + typeof(SupportBean).FullName + ", col3.col4 int)";
            EPStatement stmtCreateTwo = _epService.EPAdministrator.CreateEPL(epl);

            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreateTwo.EventType.UnderlyingType);
            stmtCreateTwo.Dispose();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyEventTypeTwo", true);

            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(model.ToEPL(), epl);
            stmtCreateTwo = _epService.EPAdministrator.Create(model);
            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtCreateTwo.EventType.UnderlyingType);

            _epService.Initialize();
        }
		public void Performance()
		{
			// Take care with this test because the result is not the same every times

			int numOfRuns = 4;

			int numOfEntries = Int16.MaxValue;

			long[] dictPopulateTicks = new long[numOfRuns];
			long[] dictItemTicks = new long[numOfRuns];

			long[] linkPopulateTicks = new long[numOfRuns];
			long[] linkItemTicks = new long[numOfRuns];

			for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
			{
				string key;
				object value;
				IDictionary<string, object> dictionary = new Dictionary<string, object>();
				IDictionary<string, object> linked = new LinkedHashMap<string, object>();

				long dictStart = DateTime.Now.Ticks;

				for (int i = 0; i < numOfEntries; i++)
				{
					dictionary.Add("test" + i, new object());
				}

				dictPopulateTicks[runIndex] = DateTime.Now.Ticks - dictStart;

				dictStart = DateTime.Now.Ticks;
				for (int i = 0; i < numOfEntries; i++)
				{
					key = "test" + i;
					value = dictionary[key];
				}
				dictItemTicks[runIndex] = DateTime.Now.Ticks - dictStart;

				dictionary.Clear();

				long linkStart = DateTime.Now.Ticks;

				for (int i = 0; i < numOfEntries; i++)
				{
					linked.Add("test" + i, new object());
				}

				linkPopulateTicks[runIndex] = DateTime.Now.Ticks - linkStart;

				linkStart = DateTime.Now.Ticks;
				for (int i = 0; i < numOfEntries; i++)
				{
					key = "test" + i;
					value = linked[key];
				}

				linkItemTicks[runIndex] = DateTime.Now.Ticks - linkStart;

				linked.Clear();
			}

			for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
			{
				decimal linkPopulateOverhead = (linkPopulateTicks[runIndex] / (decimal)dictPopulateTicks[runIndex]);
				decimal linkItemOverhead = (linkItemTicks[runIndex] / (decimal)dictItemTicks[runIndex]);

				string message = string.Format("LinkedHashMap vs Dictionary (Run-{0}) :",runIndex+1);
				message += "\n POPULATE:";
				message += "\n\t linked took " + linkPopulateTicks[runIndex] + " ticks.";
				message += "\n\t dictionary took " + dictPopulateTicks[runIndex] + " ticks.";
				message += "\n\t for an overhead of " + linkPopulateOverhead;
				message += "\n RETRIVE:";
				message += "\n\t linked took " + linkItemTicks[runIndex] + " ticks.";
				message += "\n\t dictionary took " + dictItemTicks[runIndex] + " ticks.";
				message += "\n\t for an overhead of " + linkItemOverhead;

				Console.Out.WriteLine(message);
				Console.Out.WriteLine();
			}
		}
        private static BindingMatchResult MatchBindingsAssignColumnNumbers(
            IntoTableSpec bindings,
            TableMetadata metadata,
            IList<AggregationServiceAggExpressionDesc> aggregations,
            IDictionary<ExprNode, string> selectClauseNamedNodes,
            IList<ExprEvaluator> methodAggEvaluatorsList,
            IList<ExprDeclaredNode> declaredExpressions)
        {
            var methodAggs = new LinkedHashMap<AggregationServiceAggExpressionDesc, TableMetadataColumnAggregation>();
            var accessAggs = new LinkedHashMap<AggregationServiceAggExpressionDesc, TableMetadataColumnAggregation>();
            foreach (AggregationServiceAggExpressionDesc aggDesc in aggregations)
            {
                // determine assigned name
                string columnName = FindColumnNameForAggregation(
                    selectClauseNamedNodes, declaredExpressions, aggDesc.AggregationNode);
                if (columnName == null)
                {
                    throw new ExprValidationException(
                        "Failed to find an expression among the select-clause expressions for expression '" +
                        ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(aggDesc.AggregationNode) + "'");
                }

                // determine binding metadata
                var columnMetadata = (TableMetadataColumnAggregation) metadata.TableColumns.Get(columnName);
                if (columnMetadata == null)
                {
                    throw new ExprValidationException(
                        "Failed to find name '" + columnName + "' among the columns for table '" + bindings.Name + "'");
                }

                // validate compatible
                ValidateIntoTableCompatible(bindings.Name, columnName, columnMetadata, aggDesc);

                if (!columnMetadata.Factory.IsAccessAggregation)
                {
                    methodAggs.Put(aggDesc, columnMetadata);
                }
                else
                {
                    accessAggs.Put(aggDesc, columnMetadata);
                }
            }

            // handle method-aggs
            var methodPairs = new TableColumnMethodPair[methodAggEvaluatorsList.Count];
            int methodIndex = -1;
            foreach (var methodEntry in methodAggs)
            {
                methodIndex++;
                int targetIndex = methodEntry.Value.MethodOffset;
                methodPairs[methodIndex] = new TableColumnMethodPair(
                    methodAggEvaluatorsList[methodIndex], targetIndex, methodEntry.Key.AggregationNode);
                methodEntry.Key.ColumnNum = targetIndex;
            }

            // handle access-aggs
            var accessSlots = new LinkedHashMap<int, ExprNode>();
            var accessReadPairs = new List<AggregationAccessorSlotPair>();
            int accessIndex = -1;
            var agents = new List<AggregationAgent>();
            foreach (var accessEntry in accessAggs)
            {
                accessIndex++;
                int slot = accessEntry.Value.AccessAccessorSlotPair.Slot;
                AggregationMethodFactory aggregationMethodFactory = accessEntry.Key.Factory;
                AggregationAccessor accessor = aggregationMethodFactory.Accessor;
                accessSlots.Put(slot, accessEntry.Key.AggregationNode);
                accessReadPairs.Add(new AggregationAccessorSlotPair(slot, accessor));
                accessEntry.Key.ColumnNum = metadata.NumberMethodAggregations + accessIndex;
                agents.Add(aggregationMethodFactory.AggregationStateAgent);
            }
            AggregationAgent[] agentArr = agents.ToArray();
            AggregationAccessorSlotPair[] accessReads = accessReadPairs.ToArray();

            var targetStates = new int[accessSlots.Count];
            var accessStateExpr = new ExprNode[accessSlots.Count];
            int count = 0;
            foreach (var entry in accessSlots)
            {
                targetStates[count] = entry.Key;
                accessStateExpr[count] = entry.Value;
                count++;
            }

            return new BindingMatchResult(methodPairs, accessReads, targetStates, accessStateExpr, agentArr);
        }
Example #22
0
        private static void RecursiveCompile(
            EvalFactoryNode evalNode,
            StatementContext context,
            ExprEvaluatorContext evaluatorContext,
            ICollection <string> eventTypeReferences,
            bool isInsertInto,
            MatchEventSpec tags,
            Deque <int> subexpressionIdStack,
            Stack <EvalFactoryNode> parentNodeStack,
            ICollection <string> allTagNamesOrdered)
        {
            var counter = 0;

            parentNodeStack.Push(evalNode);
            foreach (var child in evalNode.ChildNodes)
            {
                subexpressionIdStack.AddLast(counter++);
                RecursiveCompile(
                    child, context, evaluatorContext, eventTypeReferences, isInsertInto, tags, subexpressionIdStack,
                    parentNodeStack, allTagNamesOrdered);
                subexpressionIdStack.RemoveLast();
            }
            parentNodeStack.Pop();

            LinkedHashMap <string, Pair <EventType, string> > newTaggedEventTypes = null;
            LinkedHashMap <string, Pair <EventType, string> > newArrayEventTypes  = null;

            if (evalNode is EvalFilterFactoryNode)
            {
                var filterNode = (EvalFilterFactoryNode)evalNode;
                var eventName  = filterNode.RawFilterSpec.EventTypeName;
                if (context.TableService.GetTableMetadata(eventName) != null)
                {
                    throw new ExprValidationException("Tables cannot be used in pattern filter atoms");
                }

                var resolvedEventType = FilterStreamSpecRaw.ResolveType(
                    context.EngineURI, eventName, context.EventAdapterService, context.PlugInTypeResolutionURIs);
                var finalEventType       = resolvedEventType;
                var optionalTag          = filterNode.EventAsName;
                var isPropertyEvaluation = false;
                var isParentMatchUntil   = IsParentMatchUntil(evalNode, parentNodeStack);

                // obtain property event type, if final event type is properties
                if (filterNode.RawFilterSpec.OptionalPropertyEvalSpec != null)
                {
                    var optionalPropertyEvaluator =
                        PropertyEvaluatorFactory.MakeEvaluator(
                            filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                            resolvedEventType,
                            filterNode.EventAsName,
                            context.EventAdapterService,
                            context.MethodResolutionService,
                            context.SchedulingService,
                            context.VariableService,
                            context.ScriptingService,
                            context.TableService,
                            context.EngineURI,
                            context.StatementId,
                            context.StatementName,
                            context.Annotations,
                            subexpressionIdStack,
                            context.ConfigSnapshot,
                            context.NamedWindowService);
                    finalEventType       = optionalPropertyEvaluator.FragmentEventType;
                    isPropertyEvaluation = true;
                }

                if (finalEventType is EventTypeSPI)
                {
                    eventTypeReferences.Add(((EventTypeSPI)finalEventType).Metadata.PrimaryName);
                }

                // If a tag was supplied for the type, the tags must stay with this type, i.e. a=BeanA -> b=BeanA -> a=BeanB is a no
                if (optionalTag != null)
                {
                    var       pair         = tags.TaggedEventTypes.Get(optionalTag);
                    EventType existingType = null;
                    if (pair != null)
                    {
                        existingType = pair.First;
                    }
                    if (existingType == null)
                    {
                        pair = tags.ArrayEventTypes.Get(optionalTag);
                        if (pair != null)
                        {
                            throw new ExprValidationException(
                                      "Tag '" + optionalTag + "' for event '" + eventName +
                                      "' used in the repeat-until operator cannot also appear in other filter expressions");
                        }
                    }
                    if ((existingType != null) && (existingType != finalEventType))
                    {
                        throw new ExprValidationException(
                                  "Tag '" + optionalTag + "' for event '" + eventName +
                                  "' has already been declared for events of type " + existingType.UnderlyingType.GetTypeNameFullyQualPretty());
                    }
                    pair = new Pair <EventType, string>(finalEventType, eventName);

                    // add tagged type
                    if (isPropertyEvaluation || isParentMatchUntil)
                    {
                        newArrayEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                        newArrayEventTypes.Put(optionalTag, pair);
                    }
                    else
                    {
                        newTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                        newTaggedEventTypes.Put(optionalTag, pair);
                    }
                }

                // For this filter, filter types are all known tags at this time,
                // and additionally stream 0 (self) is our event type.
                // Stream type service allows resolution by property name event if that name appears in other tags.
                // by defaulting to stream zero.
                // Stream zero is always the current event type, all others follow the order of the map (stream 1 to Count).
                var selfStreamName = optionalTag;
                if (selfStreamName == null)
                {
                    selfStreamName = "s_" + UuidGenerator.Generate();
                }
                var filterTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                var typePair    = new Pair <EventType, string>(finalEventType, eventName);
                filterTypes.Put(selfStreamName, typePair);
                filterTypes.PutAll(tags.TaggedEventTypes);

                // for the filter, specify all tags used
                var filterTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(tags.TaggedEventTypes);
                filterTaggedEventTypes.Remove(optionalTag);

                // handle array tags (match-until clause)
                LinkedHashMap <string, Pair <EventType, string> > arrayCompositeEventTypes = null;
                if (tags.ArrayEventTypes != null && !tags.ArrayEventTypes.IsEmpty())
                {
                    arrayCompositeEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                    var patternSubexEventType = GetPatternSubexEventType(
                        context.StatementId, "pattern", subexpressionIdStack);

                    foreach (var entry in tags.ArrayEventTypes)
                    {
                        var specificArrayType = new LinkedHashMap <string, Pair <EventType, string> >();
                        specificArrayType.Put(entry.Key, entry.Value);
                        var arrayTagCompositeEventType =
                            context.EventAdapterService.CreateSemiAnonymousMapType(
                                patternSubexEventType, Collections.GetEmptyMap <string, Pair <EventType, string> >(),
                                specificArrayType, isInsertInto);

                        var tag = entry.Key;
                        if (!filterTypes.ContainsKey(tag))
                        {
                            var pair = new Pair <EventType, string>(arrayTagCompositeEventType, tag);
                            filterTypes.Put(tag, pair);
                            arrayCompositeEventTypes.Put(tag, pair);
                        }
                    }
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    filterTypes, context.EngineURI, true, false);
                var exprNodes = filterNode.RawFilterSpec.FilterExpressions;

                var spec = FilterSpecCompiler.MakeFilterSpec(
                    resolvedEventType,
                    eventName,
                    exprNodes,
                    filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                    filterTaggedEventTypes,
                    arrayCompositeEventTypes,
                    streamTypeService,
                    null,
                    context,
                    subexpressionIdStack);
                filterNode.FilterSpec = spec;
            }
            else if (evalNode is EvalObserverFactoryNode)
            {
                var observerNode = (EvalObserverFactoryNode)evalNode;
                try
                {
                    var observerFactory = context.PatternResolutionService.Create(observerNode.PatternObserverSpec);

                    var streamTypeService = GetStreamTypeService(
                        context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes,
                        tags.ArrayEventTypes, subexpressionIdStack, "observer");
                    var validationContext = new ExprValidationContext(
                        streamTypeService, context.MethodResolutionService, null, context.SchedulingService,
                        context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService,
                        context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor,
                        context.ScriptingService,
                        false, false, false, false, null, false);
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNOBSERVER, observerNode.PatternObserverSpec.ObjectParameters,
                        validationContext);

                    MatchedEventConvertor convertor = new MatchedEventConvertorImpl(
                        tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService);

                    observerNode.ObserverFactory = observerFactory;
                    observerFactory.SetObserverParameters(validated, convertor, validationContext);
                }
                catch (ObserverParameterException e)
                {
                    throw new ExprValidationException("Invalid parameter for pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
                catch (PatternObjectException e)
                {
                    throw new ExprValidationException("Failed to resolve pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
            }
            else if (evalNode is EvalGuardFactoryNode)
            {
                var guardNode = (EvalGuardFactoryNode)evalNode;
                try
                {
                    var guardFactory = context.PatternResolutionService.Create(guardNode.PatternGuardSpec);

                    var streamTypeService = GetStreamTypeService(
                        context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes,
                        tags.ArrayEventTypes, subexpressionIdStack, "guard");
                    var validationContext = new ExprValidationContext(
                        streamTypeService, context.MethodResolutionService, null, context.SchedulingService,
                        context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService,
                        context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor,
                        context.ScriptingService,
                        false, false, false, false, null, false);
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNGUARD, guardNode.PatternGuardSpec.ObjectParameters, validationContext);

                    MatchedEventConvertor convertor = new MatchedEventConvertorImpl(
                        tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService);

                    guardNode.GuardFactory = guardFactory;
                    guardFactory.SetGuardParameters(validated, convertor);
                }
                catch (GuardParameterException e)
                {
                    throw new ExprValidationException("Invalid parameter for pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
                catch (PatternObjectException e)
                {
                    throw new ExprValidationException("Failed to resolve pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
            }
            else if (evalNode is EvalEveryDistinctFactoryNode)
            {
                var distinctNode             = (EvalEveryDistinctFactoryNode)evalNode;
                var matchEventFromChildNodes = AnalyzeMatchEvent(distinctNode);
                var streamTypeService        = GetStreamTypeService(
                    context.EngineURI, context.StatementId, context.EventAdapterService,
                    matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes,
                    subexpressionIdStack, "every-distinct");
                var validationContext = new ExprValidationContext(
                    streamTypeService, context.MethodResolutionService, null, context.SchedulingService,
                    context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService,
                    context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);
                IList <ExprNode> validated;
                try
                {
                    validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNEVERYDISTINCT, distinctNode.Expressions, validationContext);
                }
                catch (ExprValidationPropertyException ex)
                {
                    throw new ExprValidationPropertyException(
                              ex.Message +
                              ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct",
                              ex.InnerException);
                }

                MatchedEventConvertor convertor =
                    new MatchedEventConvertorImpl(
                        matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes,
                        allTagNamesOrdered, context.EventAdapterService);

                distinctNode.Convertor = convertor;

                // Determine whether some expressions are constants or time period
                IList <ExprNode>             distinctExpressions  = new List <ExprNode>();
                ExprTimePeriodEvalDeltaConst timeDeltaComputation = null;
                ExprNode expiryTimeExp = null;
                var      count         = -1;
                var      last          = validated.Count - 1;
                foreach (var expr in validated)
                {
                    count++;
                    if (count == last && expr is ExprTimePeriod)
                    {
                        expiryTimeExp = expr;
                        var timePeriodExpr = (ExprTimePeriod)expiryTimeExp;
                        timeDeltaComputation =
                            timePeriodExpr.ConstEvaluator(new ExprEvaluatorContextStatement(context, false));
                    }
                    else if (expr.IsConstantResult)
                    {
                        if (count == last)
                        {
                            var value = expr.ExprEvaluator.Evaluate(new EvaluateParams(null, true, evaluatorContext));
                            if (!(value.IsNumber()))
                            {
                                throw new ExprValidationException(
                                          "Invalid parameter for every-distinct, expected number of seconds constant (constant not considered for distinct)");
                            }
                            var secondsTemp   = expr.ExprEvaluator.Evaluate(new EvaluateParams(null, true, evaluatorContext));
                            var secondsExpire = secondsTemp.AsBoxedDouble();
                            if ((secondsExpire != null) && (secondsExpire > 0))
                            {
                                timeDeltaComputation =
                                    new ExprTimePeriodEvalDeltaConstMsec((long)Math.Round(1000d * secondsExpire.Value));
                                expiryTimeExp = expr;
                            }
                        }
                        else
                        {
                            Log.Warn(
                                "Every-distinct node utilizes an expression returning a constant value, please check expression '" +
                                ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(expr) +
                                "', not adding expression to distinct-value expression list");
                        }
                    }
                    else
                    {
                        distinctExpressions.Add(expr);
                    }
                }
                if (distinctExpressions.IsEmpty())
                {
                    throw new ExprValidationException(
                              "Every-distinct node requires one or more distinct-value expressions that each return non-constant result values");
                }
                distinctNode.SetDistinctExpressions(distinctExpressions, timeDeltaComputation, expiryTimeExp);
            }
            else if (evalNode is EvalMatchUntilFactoryNode)
            {
                var matchUntilNode = (EvalMatchUntilFactoryNode)evalNode;

                // compile bounds expressions, if any
                var untilMatchEventSpec = new MatchEventSpec(tags.TaggedEventTypes, tags.ArrayEventTypes);
                var streamTypeService   = GetStreamTypeService(
                    context.EngineURI, context.StatementId, context.EventAdapterService,
                    untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, subexpressionIdStack,
                    "until");
                var validationContext = new ExprValidationContext(
                    streamTypeService, context.MethodResolutionService, null, context.SchedulingService,
                    context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService,
                    context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);

                var lower = ValidateBounds(matchUntilNode.LowerBounds, validationContext);
                matchUntilNode.LowerBounds = lower;

                var upper = ValidateBounds(matchUntilNode.UpperBounds, validationContext);
                matchUntilNode.UpperBounds = upper;

                var single = ValidateBounds(matchUntilNode.SingleBound, validationContext);
                matchUntilNode.SingleBound = single;

                MatchedEventConvertor convertor = new MatchedEventConvertorImpl(
                    untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, allTagNamesOrdered,
                    context.EventAdapterService);
                matchUntilNode.Convertor = convertor;

                // compile new tag lists
                ISet <string> arrayTags = null;
                var           matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]);
                foreach (var filterNode in matchUntilAnalysisResult.FilterNodes)
                {
                    var optionalTag = filterNode.EventAsName;
                    if (optionalTag != null)
                    {
                        if (arrayTags == null)
                        {
                            arrayTags = new HashSet <string>();
                        }
                        arrayTags.Add(optionalTag);
                    }
                }

                if (arrayTags != null)
                {
                    foreach (var arrayTag in arrayTags)
                    {
                        if (!tags.ArrayEventTypes.ContainsKey(arrayTag))
                        {
                            tags.ArrayEventTypes.Put(arrayTag, tags.TaggedEventTypes.Get(arrayTag));
                            tags.TaggedEventTypes.Remove(arrayTag);
                        }
                    }
                }
                matchUntilNode.TagsArrayed = GetIndexesForTags(allTagNamesOrdered, arrayTags);
            }
            else if (evalNode is EvalFollowedByFactoryNode)
            {
                var followedByNode = (EvalFollowedByFactoryNode)evalNode;
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(context.EngineURI, false);
                var validationContext = new ExprValidationContext(
                    streamTypeService, context.MethodResolutionService, null, context.SchedulingService,
                    context.VariableService, context.TableService, evaluatorContext, context.EventAdapterService,
                    context.StatementName, context.StatementId, context.Annotations, context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);

                if (followedByNode.OptionalMaxExpressions != null)
                {
                    IList <ExprNode> validated = new List <ExprNode>();
                    foreach (var maxExpr in followedByNode.OptionalMaxExpressions)
                    {
                        if (maxExpr == null)
                        {
                            validated.Add(null);
                        }
                        else
                        {
                            var visitor = new ExprNodeSummaryVisitor();
                            maxExpr.Accept(visitor);
                            if (!visitor.IsPlain)
                            {
                                var errorMessage = "Invalid maximum expression in followed-by, " + visitor.Message +
                                                   " are not allowed within the expression";
                                Log.Error(errorMessage);
                                throw new ExprValidationException(errorMessage);
                            }

                            var validatedExpr = ExprNodeUtility.GetValidatedSubtree(
                                ExprNodeOrigin.FOLLOWEDBYMAX, maxExpr, validationContext);
                            validated.Add(validatedExpr);
                            if ((validatedExpr.ExprEvaluator.ReturnType == null) ||
                                (!validatedExpr.ExprEvaluator.ReturnType.IsNumeric()))
                            {
                                var message =
                                    "Invalid maximum expression in followed-by, the expression must return an integer value";
                                throw new ExprValidationException(message);
                            }
                        }
                    }
                    followedByNode.OptionalMaxExpressions = validated;
                }
            }

            if (newTaggedEventTypes != null)
            {
                tags.TaggedEventTypes.PutAll(newTaggedEventTypes);
            }
            if (newArrayEventTypes != null)
            {
                tags.ArrayEventTypes.PutAll(newArrayEventTypes);
            }
        }
Example #23
0
        /// <exception cref="System.IO.IOException"></exception>
        private void ReadAdvertisedRefsImpl()
        {
            LinkedHashMap <string, Ref> avail = new LinkedHashMap <string, Ref>();

            for (; ;)
            {
                string line;
                try
                {
                    line = pckIn.ReadString();
                }
                catch (EOFException eof)
                {
                    if (avail.IsEmpty())
                    {
                        throw NoRepository();
                    }
                    throw;
                }
                if (line == PacketLineIn.END)
                {
                    break;
                }
                if (line.StartsWith("ERR "))
                {
                    // This is a customized remote service error.
                    // Users should be informed about it.
                    throw new RemoteRepositoryException(uri, Sharpen.Runtime.Substring(line, 4));
                }
                if (avail.IsEmpty())
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        // The first line (if any) may contain "hidden"
                        // capability values after a NUL byte.
                        foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" "))
                        {
                            remoteCapablities.AddItem(c);
                        }
                        line = Sharpen.Runtime.Substring(line, 0, nul);
                    }
                }
                string name = Sharpen.Runtime.Substring(line, 41, line.Length);
                if (avail.IsEmpty() && name.Equals("capabilities^{}"))
                {
                    // special line from git-receive-pack to show
                    // capabilities when there are no refs to advertise
                    continue;
                }
                ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, 40));
                if (name.Equals(".have"))
                {
                    additionalHaves.AddItem(id);
                }
                else
                {
                    if (name.EndsWith("^{}"))
                    {
                        name = Sharpen.Runtime.Substring(name, 0, name.Length - 3);
                        Ref prior = avail.Get(name);
                        if (prior == null)
                        {
                            throw new PackProtocolException(uri, MessageFormat.Format(JGitText.Get().advertisementCameBefore
                                                                                      , name, name));
                        }
                        if (prior.GetPeeledObjectId() != null)
                        {
                            throw DuplicateAdvertisement(name + "^{}");
                        }
                        avail.Put(name, new ObjectIdRef.PeeledTag(RefStorage.NETWORK, name, prior.GetObjectId
                                                                      (), id));
                    }
                    else
                    {
                        Ref prior = avail.Put(name, new ObjectIdRef.PeeledNonTag(RefStorage.NETWORK, name
                                                                                 , id));
                        if (prior != null)
                        {
                            throw DuplicateAdvertisement(name);
                        }
                    }
                }
            }
            Available(avail);
        }
Example #24
0
        private void TryAssertionColDefPlain(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, col3_col4 int)");

            AssertTypeColDef(stmtCreate.EventType);
            var stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");

            AssertTypeColDef(stmtSelect.EventType);

            stmtSelect.Dispose();
            stmtCreate.Dispose();

            // destroy and create differently
            stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col3 string, col4 int)");
            Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col4").GetBoxedType());
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);

            stmtCreate.Stop();

            // destroy and create differently
            stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col5 string, col6 int)");
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreate.EventType.UnderlyingType));
            Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col6").GetBoxedType());
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);
            stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");
            var listener = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSelect.EventType.UnderlyingType));

            // send event
            if (eventRepresentationEnum.IsMapEvent())
            {
                var data = new LinkedHashMap <string, object>();
                data.Put("col5", "abc");
                data.Put("col6", 1);
                epService.EPRuntime.SendEvent(data, "MyEventType");
            }
            else if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "abc", 1 }, "MyEventType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema = (RecordSchema)((AvroSchemaEventType)epService.EPAdministrator.Configuration.GetEventType("MyEventType")).Schema;
                var @event = new GenericRecord(schema);
                @event.Put("col5", "abc");
                @event.Put("col6", 1);
                epService.EPRuntime.SendEventAvro(@event, "MyEventType");
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "col5,col6".Split(','), new object[] { "abc", 1 });

            // assert type information
            var typeSPI = (EventTypeSPI)stmtSelect.EventType;

            Assert.AreEqual(TypeClass.APPLICATION, typeSPI.Metadata.TypeClass);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PublicName);
            Assert.IsTrue(typeSPI.Metadata.IsApplicationConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfiguredStatic);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PrimaryName);

            // test non-enum create-schema
            var epl           = "create" + eventRepresentationEnum.GetOutputTypeCreateSchemaName() + " schema MyEventTypeTwo as (col1 string, col2 int, col3_col4 int)";
            var stmtCreateTwo = epService.EPAdministrator.CreateEPL(epl);

            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));
            stmtCreateTwo.Dispose();
            epService.EPAdministrator.Configuration.RemoveEventType("MyEventTypeTwo", true);

            var model = epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(model.ToEPL(), epl);
            stmtCreateTwo = epService.EPAdministrator.Create(model);
            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "MyEventType,MyEventTypeTwo".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Example #25
0
        public static IList <StmtClassForgeableFactory> HandleSubselectSelectClauses(
            ExprSubselectNode subselect,
            EventType outerEventType,
            string outerEventTypeName,
            string outerStreamName,
            IDictionary <string, Pair <EventType, string> > taggedEventTypes,
            IDictionary <string, Pair <EventType, string> > arrayEventTypes,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            if (subselect.SubselectNumber == -1)
            {
                throw new IllegalStateException("Subselect is unassigned");
            }

            var statementSpec    = subselect.StatementSpecCompiled;
            var filterStreamSpec = statementSpec.StreamSpecs[0];

            IList <ViewFactoryForge> viewForges;
            string subselecteventTypeName;
            IList <StmtClassForgeableFactory> additionalForgeables;

            // construct view factory chain
            EventType eventType;

            try {
                var args = new ViewFactoryForgeArgs(
                    -1,
                    true,
                    subselect.SubselectNumber,
                    StreamSpecOptions.DEFAULT,
                    null,
                    statementRawInfo,
                    services);
                var streamSpec = statementSpec.StreamSpecs[0];

                if (streamSpec is FilterStreamSpecCompiled)
                {
                    var filterStreamSpecCompiled = (FilterStreamSpecCompiled)statementSpec.StreamSpecs[0];
                    subselecteventTypeName = filterStreamSpecCompiled.FilterSpecCompiled.FilterForEventTypeName;

                    // A child view is required to limit the stream
                    if (filterStreamSpec.ViewSpecs.Length == 0)
                    {
                        throw new ExprValidationException(
                                  "Subqueries require one or more views to limit the stream, consider declaring a length or time window");
                    }

                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(
                        filterStreamSpecCompiled.ViewSpecs,
                        args,
                        filterStreamSpecCompiled.FilterSpecCompiled.ResultEventType);
                    viewForges           = viewForgeDesc.Forges;
                    additionalForgeables = viewForgeDesc.MultikeyForges;
                    // Register filter, create view factories
                    eventType = viewForges.IsEmpty() ? filterStreamSpecCompiled.FilterSpecCompiled.ResultEventType : viewForges[viewForges.Count - 1].EventType;
                    subselect.RawEventType = eventType;
                }
                else if (streamSpec is NamedWindowConsumerStreamSpec)
                {
                    var namedSpec   = (NamedWindowConsumerStreamSpec)statementSpec.StreamSpecs[0];
                    var namedWindow = namedSpec.NamedWindow;
                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(namedSpec.ViewSpecs, args, namedWindow.EventType);
                    viewForges           = viewForgeDesc.Forges;
                    additionalForgeables = viewForgeDesc.MultikeyForges;
                    var namedWindowName = namedWindow.EventType.Name;
                    subselecteventTypeName = namedWindowName;
                    EPLValidationUtil.ValidateContextName(false, namedWindowName, namedWindow.ContextName, statementRawInfo.ContextName, true);
                    subselect.RawEventType = namedWindow.EventType;
                    eventType = namedWindow.EventType;
                }
                else if (streamSpec is TableQueryStreamSpec)
                {
                    var namedSpec = (TableQueryStreamSpec)statementSpec.StreamSpecs[0];
                    var table     = namedSpec.Table;
                    ViewFactoryForgeDesc viewForgeDesc = ViewFactoryForgeUtil.CreateForges(namedSpec.ViewSpecs, args, table.InternalEventType);
                    viewForges           = viewForgeDesc.Forges;
                    additionalForgeables = viewForgeDesc.MultikeyForges;
                    var namedWindowName = table.TableName;
                    subselecteventTypeName = namedWindowName;
                    EPLValidationUtil.ValidateContextName(false, namedWindowName, table.OptionalContextName, statementRawInfo.ContextName, true);
                    subselect.RawEventType = table.InternalEventType;
                    eventType = table.InternalEventType;
                }
                else
                {
                    throw new IllegalStateException("Unexpected stream spec " + streamSpec);
                }
            }
            catch (ViewProcessingException ex) {
                throw new ExprValidationException("Failed to validate subexpression: " + ex.Message, ex);
            }

            // determine a stream name unless one was supplied
            var subexpressionStreamName = SubselectUtil.GetStreamName(filterStreamSpec.OptionalStreamName, subselect.SubselectNumber);

            // Named windows don't allow data views
            if (filterStreamSpec is NamedWindowConsumerStreamSpec | filterStreamSpec is TableQueryStreamSpec)
            {
                EPStatementStartMethodHelperValidate.ValidateNoDataWindowOnNamedWindow(viewForges);
            }

            // Streams event types are the original stream types with the stream zero the subselect stream
            var namesAndTypes = new LinkedHashMap <string, Pair <EventType, string> >();

            namesAndTypes.Put(subexpressionStreamName, new Pair <EventType, string>(eventType, subselecteventTypeName));
            namesAndTypes.Put(outerStreamName, new Pair <EventType, string>(outerEventType, outerEventTypeName));
            if (taggedEventTypes != null)
            {
                foreach (var entry in taggedEventTypes)
                {
                    namesAndTypes.Put(entry.Key, new Pair <EventType, string>(entry.Value.First, entry.Value.Second));
                }
            }

            if (arrayEventTypes != null)
            {
                foreach (var entry in arrayEventTypes)
                {
                    namesAndTypes.Put(entry.Key, new Pair <EventType, string>(entry.Value.First, entry.Value.Second));
                }
            }

            StreamTypeService subselectTypeService = new StreamTypeServiceImpl(namesAndTypes, true, true);
            var viewResourceDelegateSubselect      = new ViewResourceDelegateExpr();

            subselect.FilterSubqueryStreamTypes = subselectTypeService;

            // Validate select expression
            var selectClauseSpec = subselect.StatementSpecCompiled.SelectClauseCompiled;

            if (selectClauseSpec.SelectExprList.Length > 0)
            {
                if (selectClauseSpec.SelectExprList.Length > 1)
                {
                    throw new ExprValidationException("Subquery multi-column select is not allowed in this context.");
                }

                var element = selectClauseSpec.SelectExprList[0];
                if (element is SelectClauseExprCompiledSpec)
                {
                    // validate
                    var compiled          = (SelectClauseExprCompiledSpec)element;
                    var selectExpression  = compiled.SelectExpression;
                    var validationContext = new ExprValidationContextBuilder(subselectTypeService, statementRawInfo, services)
                                            .WithViewResourceDelegate(viewResourceDelegateSubselect)
                                            .WithAllowBindingConsumption(true)
                                            .WithMemberName(new ExprValidationMemberNameQualifiedSubquery(subselect.SubselectNumber))
                                            .Build();
                    selectExpression        = ExprNodeUtilityValidate.GetValidatedSubtree(ExprNodeOrigin.SUBQUERYSELECT, selectExpression, validationContext);
                    subselect.SelectClause  = new ExprNode[] { selectExpression };
                    subselect.SelectAsNames = new string[] { compiled.AssignedName };

                    // handle aggregation
                    var aggExprNodes = new List <ExprAggregateNode>();
                    ExprAggregateNodeUtil.GetAggregatesBottomUp(selectExpression, aggExprNodes);
                    if (aggExprNodes.Count > 0)
                    {
                        // Other stream properties, if there is aggregation, cannot be under aggregation.
                        foreach (var aggNode in aggExprNodes)
                        {
                            var propertiesNodesAggregated = ExprNodeUtilityQuery.GetExpressionProperties(aggNode, true);
                            foreach (var pair in propertiesNodesAggregated)
                            {
                                if (pair.First != 0)
                                {
                                    throw new ExprValidationException("Subselect aggregation function cannot aggregate across correlated properties");
                                }
                            }
                        }

                        // This stream (stream 0) properties must either all be under aggregation, or all not be.
                        var propertiesNotAggregated = ExprNodeUtilityQuery.GetExpressionProperties(selectExpression, false);
                        foreach (var pair in propertiesNotAggregated)
                        {
                            if (pair.First == 0)
                            {
                                throw new ExprValidationException("Subselect properties must all be within aggregation functions");
                            }
                        }
                    }
                }
            }

            return(additionalForgeables);
        }
Example #26
0
        private void TryAssertionSchemaCopyProperties(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseOne (prop1 string, prop2 int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseTwo (prop3 long)");

            // test define and send
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E1 () copyfrom BaseOne");
            var stmtOne  = epService.EPAdministrator.CreateEPL("select * from E1");
            var listener = new SupportUpdateListener();

            stmtOne.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtOne.EventType.UnderlyingType));
            Assert.AreEqual(typeof(string), stmtOne.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int?), stmtOne.EventType.GetPropertyType("prop2").GetBoxedType());

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "v1", 2 }, "E1");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                @event.Put("prop1", "v1");
                @event.Put("prop2", 2);
                epService.EPRuntime.SendEvent(@event, "E1");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var @event = new GenericRecord(SchemaBuilder.Record("name",
                                                                    RequiredString("prop1"), RequiredInt("prop2")));
                @event.Put("prop1", "v1");
                @event.Put("prop2", 2);
                epService.EPRuntime.SendEventAvro(@event, "E1");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "prop1,prop2".Split(','), new object[] { "v1", 2 });

            // test two copy-from types
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E2 () copyfrom BaseOne, BaseTwo");
            var stmtTwo = epService.EPAdministrator.CreateEPL("select * from E2");

            Assert.AreEqual(typeof(string), stmtTwo.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int?), stmtTwo.EventType.GetPropertyType("prop2").GetBoxedType());
            Assert.AreEqual(typeof(long?), stmtTwo.EventType.GetPropertyType("prop3").GetBoxedType());

            // test API-defined type
            if (eventRepresentationEnum.IsMapEvent() ||
                eventRepresentationEnum.IsObjectArrayEvent())
            {
                var def = new Dictionary <string, object>();
                def.Put("a", "string");
                def.Put("b", typeof(string));
                def.Put("c", "BaseOne");
                def.Put("d", "BaseTwo[]");
                epService.EPAdministrator.Configuration.AddEventType("MyType", def);
            }
            else
            {
                epService.EPAdministrator.CreateEPL("create avro schema MyType(a string, b string, c BaseOne, d BaseTwo[])");
            }

            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E3(e long, f BaseOne) copyfrom MyType");
            var stmtThree = epService.EPAdministrator.CreateEPL("select * from E3");

            Assert.AreEqual(typeof(string), stmtThree.EventType.GetPropertyType("a"));
            Assert.AreEqual(typeof(string), stmtThree.EventType.GetPropertyType("b"));
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                Assert.AreEqual(typeof(object[]), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(object[][]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(object[]), stmtThree.EventType.GetPropertyType("f"));
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                Assert.AreEqual(typeof(Map), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(Map[]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(Map), stmtThree.EventType.GetPropertyType("f"));
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                Assert.AreEqual(typeof(GenericRecord), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(GenericRecord[]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(GenericRecord), stmtThree.EventType.GetPropertyType("f"));
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual(typeof(long?), stmtThree.EventType.GetPropertyType("e").GetBoxedType());

            // invalid tests
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(a long) copyFrom MyType",
                       "Error starting statement: Type by name 'MyType' contributes property 'a' defined as 'System.String' which overides the same property of type '" + Name.Clean <long>(false) + "' [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom MyType",
                       "Error starting statement: Property by name 'c' is defined twice by adding type 'MyType' [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Type by name 'XYZ' could not be located [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4 as " + typeof(SupportBean).FullName + " copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with class-provided types [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create variant schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with variant types [");

            // test SODA
            var createEPL = eventRepresentationEnum.GetAnnotationText() + " create schema EX as () copyFrom BaseOne, BaseTwo";
            var model     = epService.EPAdministrator.CompileEPL(createEPL);

            Assert.AreEqual(createEPL.Trim(), model.ToEPL());
            var stmt = epService.EPAdministrator.Create(model);

            Assert.AreEqual(createEPL.Trim(), stmt.Text);

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "BaseOne,BaseTwo,E1,E2,E3,MyType".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
 public ListViewExamples()
 {
     this.listViewExamples = this.getListViewExamples();
 }
Example #28
0
        /// <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);
            }
        }
		public void Values()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			int index = 0;
			foreach (Player p in lhm.Values)
			{
				Assert.AreEqual(players[index], p);
				index++;
			}
		}
Example #30
0
        //	protected abstract int[] prediction(FeatureList featureList) throws MaltChainedException;

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void train() throws org.maltparser.core.exception.MaltChainedException
        public virtual void train()
        {
            if (owner == null)
            {
                throw new LibException("The parent guide model cannot be found. ");
            }
            string pathExternalTrain = null;

            if (!Configuration.getOptionValue("lib", "external").ToString().Equals(""))
            {
                string path = Configuration.getOptionValue("lib", "external").ToString();
                try
                {
                    if (!Directory.Exists(path) || File.Exists(path))
                    {
                        throw new LibException("The path to the external  trainer 'svm-train' is wrong.");
                    }
                    if (Directory.Exists(path))
                    {
                        throw new LibException("The option --lib-external points to a directory, the path should point at the 'train' file or the 'train.exe' file in the libsvm or the liblinear package");
                    }
                    if (!(path.EndsWith("train", StringComparison.Ordinal) || path.EndsWith("train.exe", StringComparison.Ordinal)))
                    {
                        throw new LibException("The option --lib-external does not specify the path to 'train' file or the 'train.exe' file in the libsvm or the liblinear package. ");
                    }
                    pathExternalTrain = path;
                }
                catch (SecurityException e)
                {
                    throw new LibException("Access denied to the file specified by the option --lib-external. ", e);
                }
            }
            LinkedHashMap <string, string> libOptions = DefaultLibOptions;

            parseParameters(Configuration.getOptionValue("lib", "options").ToString(), libOptions, AllowedLibOptionFlags);

            //		long startTime = System.currentTimeMillis();

            //		if (configLogger.isInfoEnabled()) {
            //			configLogger.info("\nStart training\n");
            //		}
            if (!ReferenceEquals(pathExternalTrain, null))
            {
                trainExternal(pathExternalTrain, libOptions);
            }
            else
            {
                trainInternal(libOptions);
            }
            //		long elapsed = System.currentTimeMillis() - startTime;
            //		if (configLogger.isInfoEnabled()) {
            //			configLogger.info("Time 1: " +new Formatter().format("%02d:%02d:%02d", elapsed/3600000, elapsed%3600000/60000, elapsed%60000/1000)+" ("+elapsed+" ms)\n");
            //		}
            try
            {
                //			if (configLogger.isInfoEnabled()) {
                //				configLogger.info("\nSaving feature map "+getFile(".map").getName()+"\n");
                //			}
                saveFeatureMap(new BufferedOutputStream(new FileStream(getFile(".map").AbsolutePath, FileMode.Create, FileAccess.Write)), featureMap);
            }
            catch (FileNotFoundException e)
            {
                throw new LibException("The learner cannot save the feature map file '" + getFile(".map").AbsolutePath + "'. ", e);
            }
            //		elapsed = System.currentTimeMillis() - startTime;
            //		if (configLogger.isInfoEnabled()) {
            //			configLogger.info("Time 2: " +new Formatter().format("%02d:%02d:%02d", elapsed/3600000, elapsed%3600000/60000, elapsed%60000/1000)+" ("+elapsed+" ms)\n");
            //		}
        }
Example #31
0
        private void RunAssertionSchemaCopyProperties(EventRepresentationEnum eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseOne (prop1 String, prop2 int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseTwo (prop3 long)");

            // test define and send
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E1 () copyfrom BaseOne");
            EPStatement stmtOne = _epService.EPAdministrator.CreateEPL("select * from E1");

            stmtOne.Events += _listener.Update;
            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtOne.EventType.UnderlyingType);
            Assert.AreEqual(typeof(string), stmtOne.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int), stmtOne.EventType.GetPropertyType("prop2"));

            IDictionary <String, Object> eventE1 = new LinkedHashMap <String, Object>();

            eventE1.Put("prop1", "v1");
            eventE1.Put("prop2", 2);
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(eventE1.Values.ToArray(), "E1");
            }
            else
            {
                _epService.EPRuntime.SendEvent(eventE1, "E1");
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "prop1,prop2".Split(','), new Object[] { "v1", 2 });

            // test two copy-from types
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E2 () copyfrom BaseOne, BaseTwo");
            EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL("select * from E2");

            Assert.AreEqual(typeof(string), stmtTwo.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int), stmtTwo.EventType.GetPropertyType("prop2"));
            Assert.AreEqual(typeof(long), stmtTwo.EventType.GetPropertyType("prop3"));

            // test API-defined type
            IDictionary <String, Object> def = new Dictionary <String, Object>();

            def.Put("a", "string");
            def.Put("b", typeof(String));
            def.Put("c", "BaseOne");
            def.Put("d", "BaseTwo[]");
            _epService.EPAdministrator.Configuration.AddEventType("MyType", def);

            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E3(e long, f BaseOne) copyfrom MyType");
            EPStatement stmtThree = _epService.EPAdministrator.CreateEPL("select * from E3");

            Assert.AreEqual(typeof(String), stmtThree.EventType.GetPropertyType("a"));
            Assert.AreEqual(typeof(String), stmtThree.EventType.GetPropertyType("b"));
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                Assert.AreEqual(typeof(Object[]), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(Object[][]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(Object[]), stmtThree.EventType.GetPropertyType("f"));
            }
            else
            {
                Assert.AreEqual(typeof(DataMap), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(DataMap[]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(DataMap), stmtThree.EventType.GetPropertyType("f"));
            }
            Assert.AreEqual(typeof(long), stmtThree.EventType.GetPropertyType("e"));

            // invalid tests
            TryInvalid(eventRepresentationEnum.GetAnnotationText() + " create schema E4(a long) copyFrom MyType",
                       "Error starting statement: Type by name 'MyType' contributes property 'a' defined as 'System.String' which overides the same property of type '" + typeof(long).FullName + "' [");
            TryInvalid(eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom MyType",
                       "Error starting statement: Property by name 'c' is defined twice by adding type 'MyType' [");
            TryInvalid(eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Type by name 'XYZ' could not be located [");
            TryInvalid(eventRepresentationEnum.GetAnnotationText() + " create schema E4 as " + typeof(SupportBean).FullName + " copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with class-provided types [");
            TryInvalid(eventRepresentationEnum.GetAnnotationText() + " create variant schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with variant types [");

            // test SODA
            String createEPL             = eventRepresentationEnum.GetAnnotationText() + " create schema EX as () copyFrom BaseOne, BaseTwo";
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(createEPL);

            Assert.AreEqual(createEPL.Trim(), model.ToEPL());
            EPStatement stmt = _epService.EPAdministrator.Create(model);

            Assert.AreEqual(createEPL.Trim(), stmt.Text);

            _epService.Initialize();
        }
Example #32
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected abstract void trainExternal(String pathExternalTrain, java.util.LinkedHashMap<String, String> libOptions) throws org.maltparser.core.exception.MaltChainedException;
        protected internal abstract void trainExternal(string pathExternalTrain, LinkedHashMap <string, string> libOptions);
Example #33
0
        private static IList <LookupInstructionPlan> BuildLookupInstructions(
            int rootStreamNum,
            LinkedHashMap <int, int[]> substreamsPerStream,
            bool[] requiredPerStream,
            string[] streamNames,
            QueryGraph queryGraph,
            QueryPlanIndex[] indexSpecs,
            EventType[] typesPerStream,
            OuterJoinDesc[] outerJoinDescList,
            bool[] isHistorical,
            HistoricalStreamIndexList[] historicalStreamIndexLists,
            ExprEvaluatorContext exprEvaluatorContext,
            TableMetadata[] tablesPerStream)
        {
            IList <LookupInstructionPlan> result = new List <LookupInstructionPlan>();

            foreach (int fromStream in substreamsPerStream.Keys)
            {
                var substreams = substreamsPerStream.Get(fromStream);

                // for streams with no substreams we don't need to look up
                if (substreams.Length == 0)
                {
                    continue;
                }

                var plans           = new TableLookupPlan[substreams.Length];
                var historicalPlans = new HistoricalDataPlanNode[substreams.Length];

                for (var i = 0; i < substreams.Length; i++)
                {
                    var toStream = substreams[i];

                    if (isHistorical[toStream])
                    {
                        // There may not be an outer-join descriptor, use if provided to build the associated expression
                        ExprNode outerJoinExpr = null;
                        if (outerJoinDescList.Length > 0)
                        {
                            OuterJoinDesc outerJoinDesc;
                            if (toStream == 0)
                            {
                                outerJoinDesc = outerJoinDescList[0];
                            }
                            else
                            {
                                outerJoinDesc = outerJoinDescList[toStream - 1];
                            }
                            outerJoinExpr = outerJoinDesc.MakeExprNode(exprEvaluatorContext);
                        }

                        if (historicalStreamIndexLists[toStream] == null)
                        {
                            historicalStreamIndexLists[toStream] = new HistoricalStreamIndexList(toStream, typesPerStream, queryGraph);
                        }
                        historicalStreamIndexLists[toStream].AddIndex(fromStream);
                        historicalPlans[i] = new HistoricalDataPlanNode(toStream, rootStreamNum, fromStream, typesPerStream.Length, outerJoinExpr);
                    }
                    else
                    {
                        plans[i] = NStreamQueryPlanBuilder.CreateLookupPlan(queryGraph, fromStream, toStream, indexSpecs[toStream], typesPerStream, tablesPerStream[toStream]);
                    }
                }

                var fromStreamName = streamNames[fromStream];
                var instruction    = new LookupInstructionPlan(fromStream, fromStreamName, substreams, plans, historicalPlans, requiredPerStream);
                result.Add(instruction);
            }

            return(result);
        }
Example #34
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected abstract void trainInternal(java.util.LinkedHashMap<String, String> libOptions) throws org.maltparser.core.exception.MaltChainedException;
        protected internal abstract void trainInternal(LinkedHashMap <string, string> libOptions);
        /// <summary>
        ///     Produces an aggregation service for use with match-recognice.
        /// </summary>
        /// <param name="numStreams">number of streams</param>
        /// <param name="measureExprNodesPerStream">measure nodes</param>
        /// <param name="typesPerStream">type information</param>
        /// <exception cref="ExprValidationException">for validation errors</exception>
        /// <returns>service</returns>
        public static AggregationServiceMatchRecognizeFactoryDesc GetServiceMatchRecognize(
            int numStreams,
            IDictionary<int, IList<ExprAggregateNode>> measureExprNodesPerStream,
            EventType[] typesPerStream)
        {
            var equivalencyListPerStream = new OrderedDictionary<int, List<AggregationServiceAggExpressionDesc>>();

            foreach (var entry in measureExprNodesPerStream)
            {
                var equivalencyList = new List<AggregationServiceAggExpressionDesc>();
                equivalencyListPerStream.Put(entry.Key, equivalencyList);
                foreach (ExprAggregateNode selectAggNode in entry.Value)
                {
                    AddEquivalent(selectAggNode, equivalencyList);
                }
            }

            var aggregatorsPerStream = new LinkedHashMap<int, AggregationMethodFactory[]>();
            var evaluatorsPerStream = new Dictionary<int, ExprEvaluator[]>();

            foreach (var equivalencyPerStream in equivalencyListPerStream)
            {
                int index = 0;
                int stream = equivalencyPerStream.Key;

                var aggregators = new AggregationMethodFactory[equivalencyPerStream.Value.Count];
                aggregatorsPerStream.Put(stream, aggregators);

                var evaluators = new ExprEvaluator[equivalencyPerStream.Value.Count];
                evaluatorsPerStream.Put(stream, evaluators);

                foreach (AggregationServiceAggExpressionDesc aggregation in equivalencyPerStream.Value)
                {
                    ExprAggregateNode aggregateNode = aggregation.AggregationNode;
                    if (aggregateNode.ChildNodes.Count > 1)
                    {
                        evaluators[index] = ExprMethodAggUtil.GetMultiNodeEvaluator(
                            aggregateNode.ChildNodes, typesPerStream.Length > 1, typesPerStream);
                    }
                    else if (aggregateNode.ChildNodes.Count > 0)
                    {
                        // Use the evaluation node under the aggregation node to obtain the aggregation value
                        evaluators[index] = aggregateNode.ChildNodes[0].ExprEvaluator;
                    }
                    else
                    {
                        // For aggregation that doesn't evaluate any particular sub-expression, return null on evaluation
                        evaluators[index] = new ProxyExprEvaluator
                        {
                            ProcEvaluate = eventParams => null,
                            ProcReturnType = () => null
                        };
                    }

                    aggregators[index] = aggregateNode.Factory;
                    index++;
                }
            }

            // Assign a column number to each aggregation node. The regular aggregation goes first followed by access-aggregation.
            int columnNumber = 0;
            var allExpressions = new List<AggregationServiceAggExpressionDesc>();
            foreach (var equivalencyPerStream in equivalencyListPerStream)
            {
                foreach (AggregationServiceAggExpressionDesc entry in equivalencyPerStream.Value)
                {
                    entry.ColumnNum = columnNumber++;
                }
                allExpressions.AddAll(equivalencyPerStream.Value);
            }

            var factory = new AggregationServiceMatchRecognizeFactoryImpl(
                numStreams, aggregatorsPerStream, evaluatorsPerStream);
            return new AggregationServiceMatchRecognizeFactoryDesc(factory, allExpressions);
        }
        /// <summary>
        /// Returns the processor to use for a given select-clause.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="assignedTypeNumberStack">The assigned type number stack.</param>
        /// <param name="selectionList">the list of select clause elements/items, which are expected to have been validated</param>
        /// <param name="isUsingWildcard">true if the wildcard (*) occurs in the select clause</param>
        /// <param name="insertIntoDesc">contains column names for the optional insert-into clause (if supplied)</param>
        /// <param name="optionalInsertIntoEventType">Type of the optional insert into event.</param>
        /// <param name="forClauseSpec">For clause spec.</param>
        /// <param name="typeService">serves stream type information</param>
        /// <param name="eventAdapterService">for generating wrapper instances for events</param>
        /// <param name="statementResultService">handles listeners/subscriptions awareness to reduce output result generation</param>
        /// <param name="valueAddEventService">service that handles update events and variant events</param>
        /// <param name="selectExprEventTypeRegistry">registry for event type to statements</param>
        /// <param name="engineImportService">The engine import service.</param>
        /// <param name="exprEvaluatorContext">context for expression evalauation</param>
        /// <param name="variableService">The variable service.</param>
        /// <param name="scriptingService">The scripting service.</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="timeProvider">The time provider.</param>
        /// <param name="engineURI">The engine URI.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="contextDescriptor">The context descriptor.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="selectExprProcessorCallback">The select expr processor callback.</param>
        /// <param name="namedWindowMgmtService">The named window service.</param>
        /// <param name="intoTableClause">The into table clause.</param>
        /// <param name="groupByRollupInfo">The group by rollup information.</param>
        /// <param name="statementExtensionSvcContext">The statement extension SVC context.</param>
        /// <returns>
        /// select-clause expression processor
        /// </returns>
        /// <exception cref="ExprValidationException">Expected any of the  + Arrays.ToString(ForClauseKeyword.Values()).ToLowerCase() +  for-clause keywords after reserved keyword 'for'
        /// or
        /// The for-clause with the  + ForClauseKeyword.GROUPED_DELIVERY.Name +  keyword requires one or more grouping expressions
        /// or
        /// The for-clause with the  + ForClauseKeyword.DISCRETE_DELIVERY.Name +  keyword does not allow grouping expressions
        /// or
        /// The for-clause with delivery keywords may only occur once in a statement
        /// or
        /// Expected any of the  + Arrays.ToString(ForClauseKeyword.Values()).ToLowerCase() +  for-clause keywords after reserved keyword 'for'</exception>
        /// <throws>ExprValidationException to indicate the select expression cannot be validated</throws>
        public static SelectExprProcessor GetProcessor(
            IContainer container,
            ICollection <int> assignedTypeNumberStack,
            SelectClauseElementCompiled[] selectionList,
            bool isUsingWildcard,
            InsertIntoDesc insertIntoDesc,
            EventType optionalInsertIntoEventType,
            ForClauseSpec forClauseSpec,
            StreamTypeService typeService,
            EventAdapterService eventAdapterService,
            StatementResultService statementResultService,
            ValueAddEventService valueAddEventService,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            EngineImportService engineImportService,
            ExprEvaluatorContext exprEvaluatorContext,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            TimeProvider timeProvider,
            string engineURI,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ContextDescriptor contextDescriptor,
            ConfigurationInformation configuration,
            SelectExprProcessorDeliveryCallback selectExprProcessorCallback,
            NamedWindowMgmtService namedWindowMgmtService,
            IntoTableSpec intoTableClause,
            GroupByRollupInfo groupByRollupInfo,
            StatementExtensionSvcContext statementExtensionSvcContext)
        {
            if (selectExprProcessorCallback != null)
            {
                var bindProcessor = new BindProcessor(selectionList, typeService.EventTypes, typeService.StreamNames, tableService);
                IDictionary <string, object> properties = new LinkedHashMap <string, object>();
                for (var i = 0; i < bindProcessor.ColumnNamesAssigned.Length; i++)
                {
                    properties.Put(bindProcessor.ColumnNamesAssigned[i], bindProcessor.ExpressionTypes[i]);
                }
                var eventType = eventAdapterService.CreateAnonymousObjectArrayType("Output_" + statementName, properties);
                return(new SelectExprProcessorWDeliveryCallback(eventType, bindProcessor, selectExprProcessorCallback));
            }

            var synthetic = GetProcessorInternal(
                assignedTypeNumberStack, selectionList, isUsingWildcard, insertIntoDesc, optionalInsertIntoEventType,
                typeService, eventAdapterService, valueAddEventService, selectExprEventTypeRegistry,
                engineImportService, statementId, statementName, annotations, configuration, namedWindowMgmtService, tableService,
                groupByRollupInfo);

            // Handle table as an optional service
            if (statementResultService != null)
            {
                // Handle for-clause delivery contract checking
                ExprNode[] groupedDeliveryExpr = null;
                var        forDelivery         = false;
                if (forClauseSpec != null)
                {
                    foreach (var item in forClauseSpec.Clauses)
                    {
                        if (item.Keyword == null)
                        {
                            throw new ExprValidationException("Expected any of the " + EnumHelper.GetValues <ForClauseKeyword>().Render().ToLower() + " for-clause keywords after reserved keyword 'for'");
                        }
                        try
                        {
                            ForClauseKeyword keyword = EnumHelper.Parse <ForClauseKeyword>(item.Keyword);
                            if ((keyword == ForClauseKeyword.GROUPED_DELIVERY) && (item.Expressions.IsEmpty()))
                            {
                                throw new ExprValidationException(
                                          "The for-clause with the " + ForClauseKeyword.GROUPED_DELIVERY.GetName() +
                                          " keyword requires one or more grouping expressions");
                            }
                            if ((keyword == ForClauseKeyword.DISCRETE_DELIVERY) && (!item.Expressions.IsEmpty()))
                            {
                                throw new ExprValidationException(
                                          "The for-clause with the " + ForClauseKeyword.DISCRETE_DELIVERY.GetName() +
                                          " keyword does not allow grouping expressions");
                            }
                            if (forDelivery)
                            {
                                throw new ExprValidationException(
                                          "The for-clause with delivery keywords may only occur once in a statement");
                            }
                        }
                        catch (ExprValidationException)
                        {
                            throw;
                        }
                        catch (EPException)
                        {
                            throw;
                        }
                        catch (Exception ex)
                        {
                            throw new ExprValidationException("Expected any of the " + EnumHelper.GetValues <ForClauseKeyword>().Render().ToLower() + " for-clause keywords after reserved keyword 'for'", ex);
                        }

                        StreamTypeService type = new StreamTypeServiceImpl(synthetic.ResultEventType, null, false, engineURI);
                        groupedDeliveryExpr = new ExprNode[item.Expressions.Count];
                        var validationContext = new ExprValidationContext(
                            container,
                            type,
                            engineImportService,
                            statementExtensionSvcContext,
                            null,
                            timeProvider,
                            variableService,
                            tableService,
                            exprEvaluatorContext,
                            eventAdapterService,
                            statementName,
                            statementId, annotations, null,
                            scriptingService,
                            false, false, true, false,
                            intoTableClause == null ? null : intoTableClause.Name,
                            false);  // no context descriptor available
                        for (var i = 0; i < item.Expressions.Count; i++)
                        {
                            groupedDeliveryExpr[i] = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.FORCLAUSE, item.Expressions[i], validationContext);
                        }
                        forDelivery = true;
                    }
                }

                var bindProcessor = new BindProcessor(selectionList, typeService.EventTypes, typeService.StreamNames, tableService);
                statementResultService.SetSelectClause(bindProcessor.ExpressionTypes, bindProcessor.ColumnNamesAssigned, forDelivery, ExprNodeUtility.GetEvaluators(groupedDeliveryExpr), exprEvaluatorContext);
                return(new SelectExprResultProcessor(statementResultService, synthetic, bindProcessor));
            }

            return(synthetic);
        }
		public SideDrawerExamples(){
			this.sideDrawerExamples = this.getSideDrawerExamples();
		}
Example #38
0
        /**
         * Iterate over all possible values assignments for the Random Variables
         * comprising this ProbabilityTable that are not in the fixed set of values.
         * This allows you to iterate over a subset of possible combinations.
         *
         * @param pti
         *            the ProbabilityTable Iterator to iterate
         * @param fixedValues
         *            Fixed values for a subset of the Random Variables comprising
         *            this Probability Table.
         */

        public void iterateOverTable(Factor.Iterator pti,
                                     params AssignmentProposition[] fixedValues)
        {
            Map <RandomVariable, Object> possibleWorld = new LinkedHashMap <RandomVariable, Object>();
            MixedRadixNumber             tableMRN      = new MixedRadixNumber(0, radices);

            int[] tableRadixValues = new int[radices.Length];

            // Assert that the Random Variables for the fixed values
            // are part of this probability table and assign
            // all the fixed values to the possible world.
            foreach (AssignmentProposition ap in fixedValues)
            {
                if (!randomVarInfo.ContainsKey(ap.getTermVariable()))
                {
                    throw new ArgumentException("Assignment proposition ["
                                                + ap + "] does not belong to this probability table.");
                }
                possibleWorld.Add(ap.getTermVariable(), ap.getValue());
                RVInfo fixedRVI = randomVarInfo.get(ap.getTermVariable());
                tableRadixValues[fixedRVI.getRadixIdx()] = fixedRVI
                                                           .getIdxForDomain(ap.getValue());
            }
            // If have assignments for all the random variables
            // in this probability table
            if (fixedValues.Length == randomVarInfo.Count)
            {
                // Then only 1 iteration call is required.
                pti.iterate(possibleWorld, getValue(fixedValues));
            }
            else
            {
                // Else iterate over the non-fixed values
                List <RandomVariable> freeVariables = SetOps.difference(
                    new List <RandomVariable>(randomVarInfo.Keys), new List <RandomVariable>(possibleWorld.Keys));
                Map <RandomVariable, RVInfo> freeVarInfo = new LinkedHashMap <RandomVariable, RVInfo>();
                // Remove the fixed Variables
                foreach (RandomVariable fv in freeVariables)
                {
                    freeVarInfo.put(fv, new RVInfo(fv));
                }
                int[]            freeRadixValues = createRadixs(freeVarInfo);
                MixedRadixNumber freeMRN         = new MixedRadixNumber(0, freeRadixValues);
                Object           fval            = null;
                // Iterate through all combinations of the free variables
                do
                {
                    // Put the current assignments for the free variables
                    // into the possible world and update
                    // the current index in the table MRN
                    foreach (RVInfo freeRVI in freeVarInfo.values())
                    {
                        fval = freeRVI.getDomainValueAt(freeMRN
                                                        .getCurrentNumeralValue(freeRVI.getRadixIdx()));
                        possibleWorld.put(freeRVI.getVariable(), fval);

                        tableRadixValues[randomVarInfo.get(freeRVI.getVariable())
                                         .getRadixIdx()] = freeRVI.getIdxForDomain(fval);
                    }
                    pti.iterate(possibleWorld, values[(int)tableMRN
                                                      .getCurrentValueFor(tableRadixValues)]);
                } while (freeMRN.increment());
            }
        }
Example #39
0
        /** Load a vocab file {@code &lt;vocabName&gt;.tokens} and return mapping. */
        public virtual IDictionary<string, int> Load() {
            IDictionary<string, int> tokens = new LinkedHashMap<string, int>();
            int maxTokenType = -1;
            string fullFile = GetImportedVocabFile();
            AntlrTool tool = g.tool;
            string vocabName = g.GetOptionString("tokenVocab");
            try {
                Regex tokenDefPattern = new Regex("([^\n]+?)[ \\t]*?=[ \\t]*?([0-9]+)");
                string[] lines;
                if (tool.grammarEncoding != null) {
                    lines = File.ReadAllLines(fullFile, Encoding.GetEncoding(tool.grammarEncoding));
                }
                else {
                    lines = File.ReadAllLines(fullFile);
                }

                for (int i = 0; i < lines.Length; i++)
                {
                    string tokenDef = lines[i];
                    int lineNum = i + 1;
                    Match matcher = tokenDefPattern.Match(tokenDef);
                    if (matcher.Success) {
                        string tokenID = matcher.Groups[1].Value;
                        string tokenTypeS = matcher.Groups[2].Value;
                        int tokenType;
                        if (!int.TryParse(tokenTypeS, out tokenType))
                        {
                            tool.errMgr.ToolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR,
                                                  vocabName + CodeGenerator.VOCAB_FILE_EXTENSION,
                                                  " bad token type: " + tokenTypeS,
                                                  lineNum);
                            tokenType = TokenTypes.Invalid;
                        }

                        tool.Log("grammar", "import " + tokenID + "=" + tokenType);
                        tokens[tokenID] = tokenType;
                        maxTokenType = Math.Max(maxTokenType, tokenType);
                        lineNum++;
                    }
                    else {
                        if (tokenDef.Length > 0) { // ignore blank lines
                            tool.errMgr.ToolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR,
                                                  vocabName + CodeGenerator.VOCAB_FILE_EXTENSION,
                                                  " bad token def: " + tokenDef,
                                                  lineNum);
                        }
                    }
                }
            }
            catch (FileNotFoundException) {
                GrammarAST inTree = g.ast.GetOptionAST("tokenVocab");
                string inTreeValue = inTree.Token.Text;
                if (vocabName.Equals(inTreeValue)) {
                    tool.errMgr.GrammarError(ErrorType.CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR,
                                             g.fileName,
                                             inTree.Token,
                                             fullFile);
                }
                else { // must be from -D option on cmd-line not token in tree
                    tool.errMgr.ToolError(ErrorType.CANNOT_FIND_TOKENS_FILE_GIVEN_ON_CMDLINE,
                                          fullFile,
                                          g.name);
                }
            }
            catch (Exception e) {
                tool.errMgr.ToolError(ErrorType.ERROR_READING_TOKENS_FILE,
                                      e,
                                      fullFile,
                                      e.Message);
            }

            return tokens;
        }
Example #40
0
        public ProbabilityTable divideBy(ProbabilityTable divisor)
        {
            if (!randomVarInfo.keySet().containsAll(divisor.randomVarInfo.keySet()))
            {
                throw new IllegalArgumentException(
                          "Divisor must be a subset of the dividend.");
            }

            ProbabilityTable quotient = new ProbabilityTable(new List <RandomVariable>(randomVarInfo.Keys));

            if (1 == divisor.getValues().Length)
            {
                double d = divisor.getValues()[0];
                for (int i = 0; i < quotient.getValues().Length; i++)
                {
                    if (0 == d)
                    {
                        quotient.getValues()[i] = 0;
                    }
                    else
                    {
                        quotient.getValues()[i] = getValues()[i] / d;
                    }
                }
            }
            else
            {
                Set <RandomVariable> dividendDivisorDiff = SetOps
                                                           .difference(new List <RVInfo>(randomVarInfo.keySet()),
                                                                       new List <RVInfo>(randomVarInfo.keySet()));
                Map <RandomVariable, RVInfo> tdiff = null;
                MixedRadixNumber             tdMRN = null;
                if (dividendDivisorDiff.size() > 0)
                {
                    tdiff = new LinkedHashMap <RandomVariable, RVInfo>();
                    foreach (RandomVariable rv in dividendDivisorDiff)
                    {
                        tdiff.put(rv, new RVInfo(rv));
                    }
                    tdMRN = new MixedRadixNumber(0, createRadixs(tdiff));
                }
                Map <RandomVariable, RVInfo> diff = tdiff;
                MixedRadixNumber             dMRN = tdMRN;
                int[]            qRVs             = new int[quotient.radices.Length];
                MixedRadixNumber qMRN             = new MixedRadixNumber(0,
                                                                         quotient.radices);
                //ProbabilityTable.Iterator divisorIterator = new ProbabilityTable.Iterator() {
                //    public void iterate(Map<RandomVariable, Object> possibleWorld,
                //            double probability) {
                //        foreach (RandomVariable rv in possibleWorld.keySet()) {
                //            RVInfo rvInfo = quotient.randomVarInfo.get(rv);
                //            qRVs[rvInfo.getRadixIdx()] = rvInfo
                //                    .getIdxForDomain(possibleWorld.get(rv));
                //        }
                //        if (null != diff) {
                //            // Start from 0 off the diff
                //            dMRN.setCurrentValueFor(new int[diff.size()]);
                //            do {
                //                for (RandomVariable rv : diff.keySet()) {
                //                    RVInfo drvInfo = diff.get(rv);
                //                    RVInfo qrvInfo = quotient.randomVarInfo.get(rv);
                //                    qRVs[qrvInfo.getRadixIdx()] = dMRN
                //                            .getCurrentNumeralValue(drvInfo
                //                                    .getRadixIdx());
                //                }
                //                updateQuotient(probability);
                //            } while (dMRN.increment());
                //        } else {
                //            updateQuotient(probability);
                //        }
                //    }

                //    //
                //
                //private void updateQuotient(double probability) {
                //    int offset = (int) qMRN.getCurrentValueFor(qRVs);
                //    if (0 == probability) {
                //        quotient.getValues()[offset] = 0;
                //    } else {
                //        quotient.getValues()[offset] += getValues()[offset]
                //                / probability;
                //    }
                //}
                //////  };

                //	divisor.iterateOverTable(divisorIterator);
                // TODO
            }

            return(quotient);
        }
		public void GetEnumeratorModifyExceptionFromUpdate()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			lhm["123"] = new Player("123", "yyyyyyy");
			Assert.Throws<InvalidOperationException>(() =>
			                                         	{
			                                         		foreach (KeyValuePair<string, Player> pair in lhm)
			                                         		{
			                                         			lhm["123"] = new Player("123", "aaaaaaa");
			                                         		}
			                                         	});
		}
Example #42
0
        public IDictionary<Object, Object> ReadMap(FastInputStream dis)
        {
            int sz = ReadVInt(dis);
            IDictionary<Object, Object> m = new LinkedHashMap<Object, Object>();
            for (int i = 0; i < sz; i++)
            {
                Object key = ReadVal(dis);
                Object val = ReadVal(dis);
                m[key] = val;

            }
            return m;
        }
		public void ContainsValue()
		{
			LinkedHashMap<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			Assert.IsTrue(lhm.ContainsValue(new Player("55221", "Jonty Rhodes")));
			Assert.IsFalse(lhm.ContainsValue(new Player("55221", "SameKeyDiffName")));
		}
Example #44
0
        /// <exception cref="System.IO.IOException"></exception>
        private IDictionary <string, OpenSshConfig.Host> Parse(InputStream @in)
        {
            IDictionary <string, OpenSshConfig.Host> m = new LinkedHashMap <string, OpenSshConfig.Host
                                                                            >();
            BufferedReader             br      = new BufferedReader(new InputStreamReader(@in));
            IList <OpenSshConfig.Host> current = new AList <OpenSshConfig.Host>(4);
            string line;

            while ((line = br.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.Length == 0 || line.StartsWith("#"))
                {
                    continue;
                }
                string[] parts    = line.Split("[ \t]*[= \t]", 2);
                string   keyword  = parts[0].Trim();
                string   argValue = parts[1].Trim();
                if (StringUtils.EqualsIgnoreCase("Host", keyword))
                {
                    current.Clear();
                    foreach (string pattern in argValue.Split("[ \t]"))
                    {
                        string             name = Dequote(pattern);
                        OpenSshConfig.Host c    = m.Get(name);
                        if (c == null)
                        {
                            c = new OpenSshConfig.Host();
                            m.Put(name, c);
                        }
                        current.AddItem(c);
                    }
                    continue;
                }
                if (current.IsEmpty())
                {
                    // We received an option outside of a Host block. We
                    // don't know who this should match against, so skip.
                    //
                    continue;
                }
                if (StringUtils.EqualsIgnoreCase("HostName", keyword))
                {
                    foreach (OpenSshConfig.Host c in current)
                    {
                        if (c.hostName == null)
                        {
                            c.hostName = Dequote(argValue);
                        }
                    }
                }
                else
                {
                    if (StringUtils.EqualsIgnoreCase("User", keyword))
                    {
                        foreach (OpenSshConfig.Host c in current)
                        {
                            if (c.user == null)
                            {
                                c.user = Dequote(argValue);
                            }
                        }
                    }
                    else
                    {
                        if (StringUtils.EqualsIgnoreCase("Port", keyword))
                        {
                            try
                            {
                                int port = System.Convert.ToInt32(Dequote(argValue));
                                foreach (OpenSshConfig.Host c in current)
                                {
                                    if (c.port == 0)
                                    {
                                        c.port = port;
                                    }
                                }
                            }
                            catch (FormatException)
                            {
                            }
                        }
                        else
                        {
                            // Bad port number. Don't set it.
                            if (StringUtils.EqualsIgnoreCase("IdentityFile", keyword))
                            {
                                foreach (OpenSshConfig.Host c in current)
                                {
                                    if (c.identityFile == null)
                                    {
                                        c.identityFile = ToFile(Dequote(argValue));
                                    }
                                }
                            }
                            else
                            {
                                if (StringUtils.EqualsIgnoreCase("PreferredAuthentications", keyword))
                                {
                                    foreach (OpenSshConfig.Host c in current)
                                    {
                                        if (c.preferredAuthentications == null)
                                        {
                                            c.preferredAuthentications = Nows(Dequote(argValue));
                                        }
                                    }
                                }
                                else
                                {
                                    if (StringUtils.EqualsIgnoreCase("BatchMode", keyword))
                                    {
                                        foreach (OpenSshConfig.Host c in current)
                                        {
                                            if (c.batchMode == null)
                                            {
                                                c.batchMode = Yesno(Dequote(argValue));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (StringUtils.EqualsIgnoreCase("StrictHostKeyChecking", keyword))
                                        {
                                            string value = Dequote(argValue);
                                            foreach (OpenSshConfig.Host c in current)
                                            {
                                                if (c.strictHostKeyChecking == null)
                                                {
                                                    c.strictHostKeyChecking = value;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(m);
        }
		public void Keys()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			int index = 0;
			foreach (string s in lhm.Keys)
			{
				Assert.AreEqual(players[index].Id, s);
				index++;
			}
		}
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QPatternEveryDistinctEvaluateTrue(EveryNode, matchEvent);
            }

            // determine if this evaluation has been seen before from the same node
            var matchEventKey = PatternExpressionUtil.GetKeys(matchEvent, EveryNode.FactoryNode.Convertor, EveryNode.FactoryNode.DistinctExpressionsArray, EveryNode.Context.AgentInstanceContext);
            var haveSeenThis  = false;
            var keysFromNode  = SpawnedNodes.Get(fromNode);

            if (keysFromNode != null)
            {
                // Clean out old keys
                var currentTime = EveryNode.Context.PatternContext.TimeProvider.Time;
                var entries     = new List <object>();

                foreach (var entry in keysFromNode)
                {
                    if (currentTime >= entry.Value)
                    {
                        entries.Add(entry.Key);
                    }
                    else
                    {
                        break;
                    }
                }

                entries.ForEach(k => keysFromNode.Remove(k));

                if (keysFromNode.ContainsKey(matchEventKey))
                {
                    haveSeenThis = true;
                }
                else
                {
                    long expiryTime = EveryNode.FactoryNode.AbsMillisecondExpiry(EveryNode.Context);
                    keysFromNode.Put(matchEventKey, expiryTime);
                }
            }

            if (isQuitted)
            {
                SpawnedNodes.Remove(fromNode);
            }

            // See explanation in EvalFilterStateNode for the type check
            if (fromNode.IsFilterStateNode)
            {
                // We do not need to newState new listeners here, since the filter state node below this node did not quit
            }
            else
            {
                // Spawn all nodes below this EVERY node
                // During the start of a child we need to use the temporary evaluator to catch any event created during a start
                // Such events can be raised when the "not" operator is used.
                var spawnEvaluator = new EvalEveryStateSpawnEvaluator(EveryNode.Context.PatternContext.StatementName);
                var spawned        = EveryNode.ChildNode.NewState(spawnEvaluator, null, 0L);
                spawned.Start(BeginState);

                // If the whole spawned expression already turned true, quit it again
                if (spawnEvaluator.IsEvaluatedTrue)
                {
                    spawned.Quit();
                }
                else
                {
                    var keyset = new LinkedHashMap <Object, long>();
                    if (keysFromNode != null)
                    {
                        keyset.PutAll(keysFromNode);
                    }
                    SpawnedNodes.Put(spawned, keyset);
                    spawned.ParentEvaluator = this;
                }
            }

            if (!haveSeenThis)
            {
                ParentEvaluator.EvaluateTrue(matchEvent, this, false);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().APatternEveryDistinctEvaluateTrue(null, keysFromNode, matchEventKey, haveSeenThis);
            }
        }
		public void Serialization()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);

			MemoryStream stream = new MemoryStream();
			BinaryFormatter f = new BinaryFormatter();
			f.Serialize(stream, lhm);
			stream.Position = 0;

			LinkedHashMap<string, Player> dlhm = (LinkedHashMap<string, Player>)f.Deserialize(stream);
			stream.Close();

			Assert.AreEqual(6, dlhm.Count);
			int index = 0;
			foreach (KeyValuePair<string, Player> pair in dlhm)
			{
				Assert.AreEqual(players[index].Id, pair.Key);
				Assert.AreEqual(players[index], pair.Value);
				index++;
			}

			Assert.AreEqual(6, index);
		}
Example #48
0
        public static IDictionary <String, Object> GetNestedTypeBase()
        {
            IDictionary <String, Object> props = new LinkedHashMap <String, Object>();

            return(MakeEventType(LIST_NESTED_PROPS, props));
        }
		public void ShowDiff()
		{
			IDictionary<string, Player> dict = new Dictionary<string, Player>();
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(dict);
			Fill(lhm);
			// Override the first element
			Player o = new Player("12341", "Ovirride");
			dict[o.Id] = o;
			lhm[o.Id] = o;
			Console.Out.WriteLine("Dictionary order:");
			foreach (KeyValuePair<string, Player> pair in dict)
			{
				Console.Out.WriteLine("Key->{0}", pair.Key);
			}
			Console.Out.WriteLine("LinkedHashMap order:");
			foreach (KeyValuePair<string, Player> pair in lhm)
			{
				Console.Out.WriteLine("Key->{0}", pair.Key);
			}
		}
Example #50
0
        public void SetUp()
        {
            _container = SupportContainer.Reset();

            IDictionary <String, Object> propertyTypes = new LinkedHashMap <String, Object>();

            propertyTypes.Put("myInt", typeof(int));
            propertyTypes.Put("myDouble", typeof(double?));
            propertyTypes.Put("myString", typeof(String));

            _eventTypeName = "mapEvent";
            Configuration configuration = new Configuration(_container);

            configuration.AddEventType(_eventTypeName, propertyTypes);

            _epService = EPServiceProviderManager.GetProvider(_container, "Adapter", configuration);
            _epService.Initialize();
            EPAdministrator administrator = _epService.EPAdministrator;
            String          statementText = "select * from mapEvent#length(5)";
            EPStatement     statement     = administrator.CreateEPL(statementText);

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            // Turn off external clocking
            _epService.EPRuntime.SendEvent(new TimerControlEvent(TimerControlEvent.ClockTypeEnum.CLOCK_EXTERNAL));

            // Set the clock to 0
            _currentTime = 0;
            SendTimeEvent(0);

            _coordinator = new AdapterCoordinatorImpl(_epService, true);

            _propertyOrderNoTimestamp = new String[] { "myInt", "myDouble", "myString" };
            String[] propertyOrderTimestamp = new String[] { "timestamp", "myInt", "myDouble", "myString" };

            // A CSVPlayer for a file with timestamps, not looping
            _timestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource("regression/timestampOne.csv"), _eventTypeName);
            _timestampsNotLooping.IsUsingEngineThread = true;
            _timestampsNotLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsNotLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter for a file with timestamps, looping
            _timestampsLooping                     = new CSVInputAdapterSpec(new AdapterInputSource("regression/timestampTwo.csv"), _eventTypeName);
            _timestampsLooping.IsLooping           = true;
            _timestampsLooping.IsUsingEngineThread = true;
            _timestampsLooping.PropertyOrder       = propertyOrderTimestamp;
            _timestampsLooping.TimestampColumn     = "timestamp";

            // A CSVAdapter that sends 10 events per sec, not looping
            _noTimestampsNotLooping = new CSVInputAdapterSpec(new AdapterInputSource("regression/noTimestampOne.csv"), _eventTypeName);
            _noTimestampsNotLooping.EventsPerSec        = 10;
            _noTimestampsNotLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsNotLooping.IsUsingEngineThread = true;

            // A CSVAdapter that sends 5 events per sec, looping
            _noTimestampsLooping = new CSVInputAdapterSpec(new AdapterInputSource("regression/noTimestampTwo.csv"), _eventTypeName);
            _noTimestampsLooping.EventsPerSec        = 5;
            _noTimestampsLooping.IsLooping           = true;
            _noTimestampsLooping.PropertyOrder       = _propertyOrderNoTimestamp;
            _noTimestampsLooping.IsUsingEngineThread = true;
        }
Example #51
0
 /** Empty contructor */
 protected SentenceHMMState()
 {
     StateNumber = _globalStateNumber--;
     arcs        = new LinkedHashMap <String, SentenceHMMStateArc>();
 }
Example #52
0
 public ChartElement()
 {
     attributes = new LinkedHashMap <string, ChartAttribute>();
 }
Example #53
0
        /// <summary>
        /// Set the preconfigured event properties resolved by XPath expression.
        /// </summary>
        /// <param name="explicitXPathProperties">are preconfigured event properties</param>
        /// <param name="additionalSchemaProperties">the explicit properties</param>
        protected void Initialize(ICollection <ConfigurationEventTypeXMLDOM.XPathPropertyDesc> explicitXPathProperties,
                                  IList <ExplicitPropertyDescriptor> additionalSchemaProperties)
        {
            // make sure we override those explicitly provided with those derived from a metadataz
            var namedProperties = new LinkedHashMap <String, ExplicitPropertyDescriptor>();

            foreach (ExplicitPropertyDescriptor desc in additionalSchemaProperties)
            {
                namedProperties[desc.Descriptor.PropertyName] = desc;
            }

            String xPathExpression = null;

            try
            {
                foreach (ConfigurationEventTypeXMLDOM.XPathPropertyDesc property in explicitXPathProperties)
                {
                    xPathExpression = property.XPath;
                    if (Log.IsInfoEnabled)
                    {
                        Log.Info("Compiling XPath expression for property '" + property.Name + "' as '" +
                                 xPathExpression + "'");
                    }

                    var expressionContext = NamespaceContext ?? GetExtendedContext();
                    var expression        = XPathExpression.Compile(xPathExpression, expressionContext);

                    FragmentFactoryXPathPredefinedGetter fragmentFactory = null;

                    var isFragment = false;
                    if (property.OptionalEventTypeName != null)
                    {
                        fragmentFactory = new FragmentFactoryXPathPredefinedGetter(
                            EventAdapterService,
                            property.OptionalEventTypeName,
                            property.Name);
                        isFragment = true;
                    }

                    var getter = new XPathPropertyGetter(
                        property.Name,
                        xPathExpression,
                        expression,
                        property.ResultType,
                        property.OptionalCastToType,
                        fragmentFactory);
                    var returnType = SchemaUtil.ToReturnType(
                        property.ResultType,
                        property.OptionalCastToType.GetBoxedType());
                    var indexType = returnType.GetIndexType();
                    var isIndexed = indexType != null;

                    if (property.ResultType == XPathResultType.NodeSet)
                    {
                        isIndexed = true;
                    }

                    var desc = new EventPropertyDescriptor(
                        property.Name, returnType, indexType, false, false,
                        isIndexed, false, isFragment);
                    var @explicit = new ExplicitPropertyDescriptor(
                        desc, getter, isIndexed,
                        property.OptionalEventTypeName);

                    namedProperties[desc.PropertyName] = @explicit;
                }
            }
            catch (XPathException ex)
            {
                throw new EPException(
                          "XPath expression could not be compiled for expression '" + xPathExpression + '\'', ex);
            }

            Initialize(namedProperties.Values);

            // evaluate start and end timestamp properties if any
            _startTimestampPropertyName = ConfigurationEventTypeXMLDOM.StartTimestampPropertyName;
            _endTimestampPropertyName   = ConfigurationEventTypeXMLDOM.EndTimestampPropertyName;
            EventTypeUtility.ValidateTimestampProperties(this, _startTimestampPropertyName, _endTimestampPropertyName);
        }
        /// <summary>
        /// Parses one or more CSV format curve files for all available dates.
        /// <para>
        /// A predicate is specified that is used to filter the dates that are returned.
        /// This could match a single date, a set of dates or all dates.
        /// </para>
        /// <para>
        /// If the files contain a duplicate entry an exception will be thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="datePredicate">  the predicate used to select the dates </param>
        /// <param name="groupsCharSource">  the curve groups CSV character source </param>
        /// <param name="settingsCharSource">  the curve settings CSV character source </param>
        /// <param name="curveValueCharSources">  the CSV character sources for curves </param>
        /// <returns> the loaded curves, mapped by date and identifier </returns>
        /// <exception cref="IllegalArgumentException"> if the files contain a duplicate entry </exception>
        public static ImmutableListMultimap <LocalDate, LegalEntityCurveGroup> parse(System.Predicate <LocalDate> datePredicate, CharSource groupsCharSource, CharSource settingsCharSource, ICollection <CharSource> curveValueCharSources)
        {
            IDictionary <CurveGroupName, IDictionary <Pair <RepoGroup, Currency>, CurveName> >        repoGroups        = new LinkedHashMap <CurveGroupName, IDictionary <Pair <RepoGroup, Currency>, CurveName> >();
            IDictionary <CurveGroupName, IDictionary <Pair <LegalEntityGroup, Currency>, CurveName> > legalEntityGroups = new LinkedHashMap <CurveGroupName, IDictionary <Pair <LegalEntityGroup, Currency>, CurveName> >();

            parseCurveMaps(groupsCharSource, repoGroups, legalEntityGroups);
            IDictionary <LocalDate, IDictionary <CurveName, Curve> > allCurves = parseCurves(datePredicate, settingsCharSource, curveValueCharSources);

            ImmutableListMultimap.Builder <LocalDate, LegalEntityCurveGroup> builder = ImmutableListMultimap.builder();

            foreach (KeyValuePair <LocalDate, IDictionary <CurveName, Curve> > curveEntry in allCurves.SetOfKeyValuePairs())
            {
                LocalDate date = curveEntry.Key;
                IDictionary <CurveName, Curve> curves = curveEntry.Value;
                foreach (KeyValuePair <CurveGroupName, IDictionary <Pair <RepoGroup, Currency>, CurveName> > repoEntry in repoGroups.SetOfKeyValuePairs())
                {
                    CurveGroupName groupName = repoEntry.Key;
                    IDictionary <Pair <RepoGroup, Currency>, Curve>        repoCurves   = MapStream.of(repoEntry.Value).mapValues(name => queryCurve(name, curves, date, groupName, "Repo")).toMap();
                    IDictionary <Pair <LegalEntityGroup, Currency>, Curve> issuerCurves = MapStream.of(legalEntityGroups[groupName]).mapValues(name => queryCurve(name, curves, date, groupName, "Issuer")).toMap();
                    builder.put(date, LegalEntityCurveGroup.of(groupName, repoCurves, issuerCurves));
                }
            }
            return(builder.build());
        }
		public void GetEnumerator()
		{
			IDictionary<string, Player> lhm = new LinkedHashMap<string, Player>();
			Fill(lhm);
			int index = 0;
			foreach (KeyValuePair<string, Player> pair in lhm)
			{
				Assert.AreEqual(players[index].Id, pair.Key);
				Assert.AreEqual(players[index], pair.Value);
				index++;
			}

			Assert.AreEqual(6, index);
		}
Example #56
0
        /**
         * Get {@code #} labels. The keys of the map are the labels applied to outer
         * alternatives of a lexer rule, and the values are collections of pairs
         * (alternative number and {@link AltAST}) identifying the alternatives with
         * this label. Unlabeled alternatives are not included in the result.
         */
        public virtual IDictionary<string, IList<System.Tuple<int, AltAST>>> GetAltLabels()
        {
            IDictionary<string, IList<System.Tuple<int, AltAST>>> labels = new LinkedHashMap<string, IList<System.Tuple<int, AltAST>>>();
            for (int i = 1; i <= numberOfAlts; i++)
            {
                GrammarAST altLabel = alt[i].ast.altLabel;
                if (altLabel != null)
                {
                    IList<System.Tuple<int, AltAST>> list;
                    if (!labels.TryGetValue(altLabel.Text, out list) || list == null)
                    {
                        list = new List<System.Tuple<int, AltAST>>();
                        labels[altLabel.Text] = list;
                    }

                    list.Add(Tuple.Create(i, alt[i].ast));
                }
            }
            if (labels.Count == 0)
                return null;
            return labels;
        }
Example #57
0
        public static DeployerModuleEPLObjects InitializeEPLObjects(
            ModuleProviderCLPair provider,
            string deploymentId,
            EPServicesContext services)
        {
            // keep protected types
            var beanEventTypeFactory = new BeanEventTypeFactoryPrivate(
                new EventBeanTypedEventFactoryRuntime(services.EventTypeAvroHandler),
                services.EventTypeFactory,
                services.BeanEventTypeStemService);

            // initialize module event types
            IDictionary <string, EventType> moduleEventTypes = new LinkedHashMap <string, EventType>();
            var eventTypeResolver = new EventTypeResolverImpl(
                moduleEventTypes,
                services.EventTypePathRegistry,
                services.EventTypeRepositoryBus,
                services.BeanEventTypeFactoryPrivate,
                services.EventSerdeFactory);
            var eventTypeCollector = new EventTypeCollectorImpl(
                services.Container,
                moduleEventTypes,
                beanEventTypeFactory,
                provider.ClassLoader,
                services.EventTypeFactory,
                services.BeanEventTypeStemService,
                eventTypeResolver,
                services.XmlFragmentEventTypeFactory,
                services.EventTypeAvroHandler,
                services.EventBeanTypedEventFactory,
                services.ImportServiceRuntime);

            try {
                provider.ModuleProvider.InitializeEventTypes(new EPModuleEventTypeInitServicesImpl(eventTypeCollector, eventTypeResolver));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            JsonEventTypeUtility.AddJsonUnderlyingClass(moduleEventTypes, services.ClassLoaderParent, deploymentId);

            // initialize module named windows
            IDictionary <string, NamedWindowMetaData> moduleNamedWindows = new Dictionary <string, NamedWindowMetaData>();
            NamedWindowCollector namedWindowCollector = new NamedWindowCollectorImpl(moduleNamedWindows);

            try {
                provider.ModuleProvider.InitializeNamedWindows(new EPModuleNamedWindowInitServicesImpl(namedWindowCollector, eventTypeResolver));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module tables
            IDictionary <string, TableMetaData> moduleTables = new Dictionary <string, TableMetaData>();
            var tableCollector = new TableCollectorImpl(moduleTables);

            try {
                provider.ModuleProvider.InitializeTables(new EPModuleTableInitServicesImpl(tableCollector, eventTypeResolver));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize create-index indexes
            ISet <ModuleIndexMeta> moduleIndexes = new HashSet <ModuleIndexMeta>();
            var indexCollector = new IndexCollectorRuntime(moduleIndexes);

            try {
                provider.ModuleProvider.InitializeIndexes(new EPModuleIndexInitServicesImpl(indexCollector));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module contexts
            IDictionary <string, ContextMetaData> moduleContexts = new Dictionary <string, ContextMetaData>();
            ContextCollector contextCollector = new ContextCollectorImpl(moduleContexts);

            try {
                provider.ModuleProvider.InitializeContexts(new EPModuleContextInitServicesImpl(contextCollector, eventTypeResolver));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module variables
            IDictionary <string, VariableMetaData> moduleVariables = new Dictionary <string, VariableMetaData>();
            VariableCollector variableCollector = new VariableCollectorImpl(moduleVariables);

            try {
                provider.ModuleProvider.InitializeVariables(new EPModuleVariableInitServicesImpl(variableCollector, eventTypeResolver));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module expressions
            IDictionary <string, ExpressionDeclItem> moduleExpressions = new Dictionary <string, ExpressionDeclItem>();
            var exprDeclaredCollector = new ExprDeclaredCollectorRuntime(moduleExpressions);

            try {
                provider.ModuleProvider.InitializeExprDeclareds(new EPModuleExprDeclaredInitServicesImpl(exprDeclaredCollector));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module scripts
            IDictionary <NameAndParamNum, ExpressionScriptProvided> moduleScripts = new Dictionary <NameAndParamNum, ExpressionScriptProvided>();
            var scriptCollectorRuntime = new ScriptCollectorRuntime(moduleScripts);

            try {
                provider.ModuleProvider.InitializeScripts(new EPModuleScriptInitServicesImpl(scriptCollectorRuntime));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            // initialize module class-provided create-class
            IDictionary <string, ClassProvided> moduleClasses = new Dictionary <string, ClassProvided>();
            var classProvidedCollectorRuntime = new ClassProvidedCollectorRuntime(moduleClasses);

            try {
                provider.ModuleProvider.InitializeClassProvided(new EPModuleClassProvidedInitServicesImpl(classProvidedCollectorRuntime));
            }
            catch (Exception e) {
                throw new EPException(e);
            }

            foreach (var moduleClass in moduleClasses)
            {
                moduleClass.Value.LoadClasses(provider.ClassLoader);
            }

            return(new DeployerModuleEPLObjects(
                       beanEventTypeFactory,
                       moduleEventTypes,
                       moduleNamedWindows,
                       moduleTables,
                       moduleIndexes,
                       moduleContexts,
                       moduleVariables,
                       moduleExpressions,
                       moduleScripts,
                       moduleClasses,
                       eventTypeCollector.Serdes,
                       eventTypeResolver));
        }
Example #58
0
        public JoinSetComposerDesc Create(Viewable[] streamViews, bool isFireAndForget, AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            // Build indexes
            var indexesPerStream         = new IDictionary <TableLookupIndexReqKey, EventTable> [_indexSpecs.Length];
            var tableSecondaryIndexLocks = new ILockable[_indexSpecs.Length];
            var hasTable = false;

            for (var streamNo = 0; streamNo < _indexSpecs.Length; streamNo++)
            {
                if (_indexSpecs[streamNo] == null)
                {
                    continue;
                }

                var items = _indexSpecs[streamNo].Items;
                indexesPerStream[streamNo] = new LinkedHashMap <TableLookupIndexReqKey, EventTable>();

                if (_streamJoinAnalysisResult.TablesPerStream[streamNo] != null)
                {
                    // build for tables
                    var metadata = _streamJoinAnalysisResult.TablesPerStream[streamNo];
                    var state    = _tableService.GetState(metadata.TableName, agentInstanceContext.AgentInstanceId);
                    foreach (var indexName in state.SecondaryIndexes)
                    { // add secondary indexes
                        indexesPerStream[streamNo].Put(new TableLookupIndexReqKey(indexName, metadata.TableName), state.GetIndex(indexName));
                    }
                    var index = state.GetIndex(metadata.TableName); // add primary index
                    indexesPerStream[streamNo].Put(new TableLookupIndexReqKey(metadata.TableName, metadata.TableName), index);
                    hasTable = true;
                    tableSecondaryIndexLocks[streamNo] = agentInstanceContext.StatementContext.IsWritesToTables ?
                                                         state.TableLevelRWLock.WriteLock : state.TableLevelRWLock.ReadLock;
                }
                else
                {
                    // build tables for implicit indexes
                    foreach (var entry in items)
                    {
                        EventTable index;
                        if (_streamJoinAnalysisResult.ViewExternal[streamNo] != null)
                        {
                            VirtualDWView view = _streamJoinAnalysisResult.ViewExternal[streamNo].Invoke(agentInstanceContext);
                            index = view.GetJoinIndexTable(items.Get(entry.Key));
                        }
                        else
                        {
                            index = EventTableUtil.BuildIndex(
                                agentInstanceContext, streamNo, items.Get(entry.Key), _streamTypes[streamNo], false,
                                entry.Value.IsUnique, null, null, isFireAndForget);
                        }
                        indexesPerStream[streamNo].Put(entry.Key, index);
                    }
                }
            }

            // obtain any external views
            var externalViewProviders = _streamJoinAnalysisResult.ViewExternal;
            var externalViews         = new VirtualDWView[externalViewProviders.Length];

            for (var i = 0; i < externalViews.Length; i++)
            {
                if (externalViewProviders[i] != null)
                {
                    externalViews[i] = _streamJoinAnalysisResult.ViewExternal[i].Invoke(agentInstanceContext);
                }
            }

            // Build strategies
            var queryExecSpecs  = _queryPlan.ExecNodeSpecs;
            var queryStrategies = new QueryStrategy[queryExecSpecs.Length];

            for (var i = 0; i < queryExecSpecs.Length; i++)
            {
                var planNode = queryExecSpecs[i];
                if (planNode == null)
                {
                    Log.Debug(".MakeComposer No execution node for stream " + i + " '" + _streamNames[i] + "'");
                    continue;
                }

                var executionNode = planNode.MakeExec(
                    _statementName, _statementId, _annotations, indexesPerStream, _streamTypes, streamViews,
                    _historicalStreamIndexLists, externalViews, tableSecondaryIndexLocks);

                if (Log.IsDebugEnabled)
                {
                    Log.Debug(".MakeComposer Execution nodes for stream " + i + " '" + _streamNames[i] +
                              "' : \n" + ExecNode.Print(executionNode));
                }

                queryStrategies[i] = new ExecNodeQueryStrategy(i, _streamTypes.Length, executionNode);
            }

            // Remove indexes that are from tables as these are only available to query strategies
            if (hasTable)
            {
                indexesPerStream = RemoveTableIndexes(indexesPerStream, _streamJoinAnalysisResult.TablesPerStream);
            }

            // If this is not unidirectional and not a self-join (excluding self-outer-join)
            JoinSetComposerDesc joinSetComposerDesc;

            if ((!_streamJoinAnalysisResult.IsUnidirectional) &&
                (!_streamJoinAnalysisResult.IsPureSelfJoin || _outerJoinDescList.Length > 0))
            {
                JoinSetComposer composer;
                if (_historicalViewableDesc.HasHistorical)
                {
                    composer = new JoinSetComposerHistoricalImpl(_eventTableIndexService.AllowInitIndex(isRecoveringResilient), indexesPerStream, queryStrategies, streamViews, _exprEvaluatorContext);
                }
                else
                {
                    if (isFireAndForget)
                    {
                        composer = new JoinSetComposerFAFImpl(indexesPerStream, queryStrategies, _streamJoinAnalysisResult.IsPureSelfJoin, _exprEvaluatorContext, _joinRemoveStream, _isOuterJoins);
                    }
                    else
                    {
                        composer = new JoinSetComposerImpl(_eventTableIndexService.AllowInitIndex(isRecoveringResilient), indexesPerStream, queryStrategies, _streamJoinAnalysisResult.IsPureSelfJoin, _exprEvaluatorContext, _joinRemoveStream);
                    }
                }

                // rewrite the filter expression for all-inner joins in case "on"-clause outer join syntax was used to include those expressions
                var filterExpression = GetFilterExpressionInclOnClause(_optionalFilterNode, _outerJoinDescList);

                var postJoinEval = filterExpression == null ? null : filterExpression.ExprEvaluator;
                joinSetComposerDesc = new JoinSetComposerDesc(composer, postJoinEval);
            }
            else
            {
                ExprEvaluator postJoinEval = _optionalFilterNode == null ? null : _optionalFilterNode.ExprEvaluator;

                if (_streamJoinAnalysisResult.IsUnidirectionalAll)
                {
                    JoinSetComposer composer = new JoinSetComposerAllUnidirectionalOuter(queryStrategies);
                    joinSetComposerDesc = new JoinSetComposerDesc(composer, postJoinEval);
                }
                else
                {
                    QueryStrategy driver;
                    int           unidirectionalStream;
                    if (_streamJoinAnalysisResult.IsUnidirectional)
                    {
                        unidirectionalStream = _streamJoinAnalysisResult.UnidirectionalStreamNumberFirst;
                        driver = queryStrategies[unidirectionalStream];
                    }
                    else
                    {
                        unidirectionalStream = 0;
                        driver = queryStrategies[0];
                    }

                    JoinSetComposer composer = new JoinSetComposerStreamToWinImpl(
                        _eventTableIndexService.AllowInitIndex(isRecoveringResilient), indexesPerStream,
                        _streamJoinAnalysisResult.IsPureSelfJoin,
                        unidirectionalStream, driver,
                        _streamJoinAnalysisResult.UnidirectionalNonDriving);
                    joinSetComposerDesc = new JoinSetComposerDesc(composer, postJoinEval);
                }
            }

            // init if the join-set-composer allows it
            if (joinSetComposerDesc.JoinSetComposer.AllowsInit)
            {
                // compile prior events per stream to preload any indexes
                var eventsPerStream = new EventBean[_streamNames.Length][];
                var events          = new List <EventBean>();
                for (var i = 0; i < eventsPerStream.Length; i++)
                {
                    // For named windows and tables, we don't need to preload indexes from the iterators as this is always done already
                    if (_streamJoinAnalysisResult.NamedWindow[i] || _streamJoinAnalysisResult.TablesPerStream[i] != null)
                    {
                        continue;
                    }

                    IEnumerator <EventBean> it = null;
                    if (!(streamViews[i] is HistoricalEventViewable) && !(streamViews[i] is DerivedValueView))
                    {
                        try
                        {
                            it = streamViews[i].GetEnumerator();
                        }
                        catch (UnsupportedOperationException)
                        {
                            // Joins do not support the iterator
                        }
                    }

                    if (it != null)
                    {
                        while (it.MoveNext())
                        {
                            events.Add(it.Current);
                        }
                        eventsPerStream[i] = events.ToArray();
                        events.Clear();
                    }
                    else
                    {
                        eventsPerStream[i] = new EventBean[0];
                    }
                }

                // init
                joinSetComposerDesc.JoinSetComposer.Init(eventsPerStream, _exprEvaluatorContext);
            }

            return(joinSetComposerDesc);
        }
		/// <exception cref="System.IO.IOException"></exception>
		private void ReadAdvertisedRefsImpl()
		{
			LinkedHashMap<string, Ref> avail = new LinkedHashMap<string, Ref>();
			for (; ; )
			{
				string line;
				try
				{
					line = pckIn.ReadString();
				}
				catch (EOFException eof)
				{
					if (avail.IsEmpty())
					{
						throw NoRepository();
					}
					throw;
				}
				if (line == PacketLineIn.END)
				{
					break;
				}
				if (line.StartsWith("ERR "))
				{
					// This is a customized remote service error.
					// Users should be informed about it.
					throw new RemoteRepositoryException(uri, Sharpen.Runtime.Substring(line, 4));
				}
				if (avail.IsEmpty())
				{
					int nul = line.IndexOf('\0');
					if (nul >= 0)
					{
						// The first line (if any) may contain "hidden"
						// capability values after a NUL byte.
						foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" "))
						{
							remoteCapablities.AddItem(c);
						}
						line = Sharpen.Runtime.Substring(line, 0, nul);
					}
				}
				string name = Sharpen.Runtime.Substring(line, 41, line.Length);
				if (avail.IsEmpty() && name.Equals("capabilities^{}"))
				{
					// special line from git-receive-pack to show
					// capabilities when there are no refs to advertise
					continue;
				}
				ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, 40));
				if (name.Equals(".have"))
				{
					additionalHaves.AddItem(id);
				}
				else
				{
					if (name.EndsWith("^{}"))
					{
						name = Sharpen.Runtime.Substring(name, 0, name.Length - 3);
						Ref prior = avail.Get(name);
						if (prior == null)
						{
							throw new PackProtocolException(uri, MessageFormat.Format(JGitText.Get().advertisementCameBefore
								, name, name));
						}
						if (prior.GetPeeledObjectId() != null)
						{
							throw DuplicateAdvertisement(name + "^{}");
						}
						avail.Put(name, new ObjectIdRef.PeeledTag(RefStorage.NETWORK, name, prior.GetObjectId
							(), id));
					}
					else
					{
						Ref prior = avail.Put(name, new ObjectIdRef.PeeledNonTag(RefStorage.NETWORK, name
							, id));
						if (prior != null)
						{
							throw DuplicateAdvertisement(name);
						}
					}
				}
			}
			Available(avail);
		}
Example #60
0
        public void Performance()
        {
            // Take care with this test because the result is not the same every times

            int numOfRuns = 4;

            int numOfEntries = Int16.MaxValue;

            long[] dictPopulateTicks = new long[numOfRuns];
            long[] dictItemTicks     = new long[numOfRuns];

            long[] linkPopulateTicks = new long[numOfRuns];
            long[] linkItemTicks     = new long[numOfRuns];

            for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
            {
                string key;
                object value;
                IDictionary <string, object> dictionary = new Dictionary <string, object>();
                IDictionary <string, object> linked     = new LinkedHashMap <string, object>();

                long dictStart = DateTime.Now.Ticks;

                for (int i = 0; i < numOfEntries; i++)
                {
                    dictionary.Add("test" + i, new object());
                }

                dictPopulateTicks[runIndex] = DateTime.Now.Ticks - dictStart;

                dictStart = DateTime.Now.Ticks;
                for (int i = 0; i < numOfEntries; i++)
                {
                    key   = "test" + i;
                    value = dictionary[key];
                }
                dictItemTicks[runIndex] = DateTime.Now.Ticks - dictStart;

                dictionary.Clear();

                long linkStart = DateTime.Now.Ticks;

                for (int i = 0; i < numOfEntries; i++)
                {
                    linked.Add("test" + i, new object());
                }

                linkPopulateTicks[runIndex] = DateTime.Now.Ticks - linkStart;

                linkStart = DateTime.Now.Ticks;
                for (int i = 0; i < numOfEntries; i++)
                {
                    key   = "test" + i;
                    value = linked[key];
                }

                linkItemTicks[runIndex] = DateTime.Now.Ticks - linkStart;

                linked.Clear();
            }

            for (int runIndex = 0; runIndex < numOfRuns; runIndex++)
            {
                decimal linkPopulateOverhead = (linkPopulateTicks[runIndex] / (decimal)dictPopulateTicks[runIndex]);
                decimal linkItemOverhead     = (linkItemTicks[runIndex] / (decimal)dictItemTicks[runIndex]);

                string message = string.Format("LinkedHashMap vs Dictionary (Run-{0}) :", runIndex + 1);
                message += "\n POPULATE:";
                message += "\n\t linked took " + linkPopulateTicks[runIndex] + " ticks.";
                message += "\n\t dictionary took " + dictPopulateTicks[runIndex] + " ticks.";
                message += "\n\t for an overhead of " + linkPopulateOverhead;
                message += "\n RETRIVE:";
                message += "\n\t linked took " + linkItemTicks[runIndex] + " ticks.";
                message += "\n\t dictionary took " + dictItemTicks[runIndex] + " ticks.";
                message += "\n\t for an overhead of " + linkItemOverhead;

                Console.Out.WriteLine(message);
                Console.Out.WriteLine();
            }
        }