private void AddReference(String statementName, String eventTypeName) { // add to types var statements = _typeToStmt.Get(eventTypeName); if (statements == null) { statements = new HashSet <String>(); _typeToStmt.Put(eventTypeName, statements); } statements.Add(statementName); // add to statements String[] types = _stmtToType.Get(statementName); if (types == null) { types = new String[] { eventTypeName }; } else { int index = CollectionUtil.FindItem(types, eventTypeName); if (index == -1) { types = (String[])CollectionUtil.ArrayExpandAddSingle(types, eventTypeName); } } _stmtToType.Put(statementName, types); }
public static View[] AddView(View[] children, View view) { if (children.Length == 0) { return(new View[] { view }); } else { return((View[])(CollectionUtil.ArrayExpandAddSingle(children, view))); } }
public void TestGetProcessorAggregatingGrouped() { // with group-by but either // wildcard // or one or more non-aggregated event properties are not in the group by (output per event) var selectList = SupportSelectExprFactory.MakeAggregateMixed(); var identNode = SupportExprNodeFactory.MakeIdentNode("TheString", "s0"); selectList = (SelectClauseElementCompiled[])CollectionUtil.ArrayExpandAddSingle(selectList, new SelectClauseExprCompiledSpec(identNode, null, null, false)); _groupByList.Add(SupportExprNodeFactory.MakeIdentNode("DoubleBoxed", "s0")); var spec = MakeSpec(new SelectClauseSpecCompiled(selectList, false), null, _groupByList, null, null, _orderByList); var processor = ResultSetProcessorFactoryFactory.GetProcessorPrototype(spec, _stmtContext, _typeService1Stream, null, new bool[0], true, ContextPropertyRegistryImpl.EMPTY_REGISTRY, null, new Configuration()); Assert.IsTrue(processor.ResultSetProcessorFactory is ResultSetProcessorAggregateGroupedFactory); }
public void TestVerifyNameUniqueness() { // try valid case var elements = new SelectClauseElementCompiled[4]; elements[0] = new SelectClauseExprCompiledSpec(null, "xx", null, false); elements[1] = new SelectClauseExprCompiledSpec(null, "yy", null, false); elements[2] = new SelectClauseStreamCompiledSpec("win", null); elements[3] = new SelectClauseStreamCompiledSpec("s2", "abc"); SelectExprProcessorFactory.VerifyNameUniqueness(elements); // try invalid case elements = (SelectClauseElementCompiled[])CollectionUtil.ArrayExpandAddSingle(elements, new SelectClauseExprCompiledSpec(null, "yy", null, false)); try { SelectExprProcessorFactory.VerifyNameUniqueness(elements); Assert.Fail(); } catch (ExprValidationException) { // expected } // try invalid case elements = new SelectClauseElementCompiled[2]; elements[0] = new SelectClauseExprCompiledSpec(null, "abc", null, false); elements[1] = new SelectClauseStreamCompiledSpec("s0", "abc"); try { SelectExprProcessorFactory.VerifyNameUniqueness(elements); Assert.Fail(); } catch (ExprValidationException) { // expected } }
public static ExprNodeUtilMethodDesc ResolveMethodAllowWildcardAndStream( string className, Type optionalClass, string methodName, IList<ExprNode> parameters, bool allowWildcard, EventType wildcardType, ExprNodeUtilResolveExceptionHandler exceptionHandler, string functionName, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { var paramTypes = new Type[parameters.Count]; var childForges = new ExprForge[parameters.Count]; var count = 0; var allowEventBeanType = new bool[parameters.Count]; var allowEventBeanCollType = new bool[parameters.Count]; var childEvalsEventBeanReturnTypesForges = new ExprForge[parameters.Count]; var allConstants = true; foreach (var childNode in parameters) { if (!EnumMethodResolver.IsEnumerationMethod(methodName, services.ImportServiceCompileTime) && childNode is ExprLambdaGoesNode) { throw new ExprValidationException( "Unrecognized lambda-expression encountered as parameter to UDF or static method '" + methodName + "'"); } if (childNode is ExprWildcard) { if (wildcardType == null || !allowWildcard) { throw new ExprValidationException("Failed to resolve wildcard parameter to a given event type"); } childForges[count] = new ExprEvalStreamNumUnd(0, wildcardType.UnderlyingType); childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEvent(0); paramTypes[count] = wildcardType.UnderlyingType; allowEventBeanType[count] = true; allConstants = false; count++; continue; } if (childNode is ExprStreamUnderlyingNode) { var und = (ExprStreamUnderlyingNode) childNode; var tableMetadata = services.TableCompileTimeResolver.ResolveTableFromEventType(und.EventType); if (tableMetadata == null) { childForges[count] = childNode.Forge; childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEvent(und.StreamId); } else { childForges[count] = new ExprEvalStreamTable( und.StreamId, und.EventType.UnderlyingType, tableMetadata); childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEventTable(und.StreamId, tableMetadata); } paramTypes[count] = childForges[count].EvaluationType; allowEventBeanType[count] = true; allConstants = false; count++; continue; } if (childNode.Forge is ExprEnumerationForge) { var enumeration = (ExprEnumerationForge) childNode.Forge; var eventType = enumeration.GetEventTypeSingle(statementRawInfo, services); childForges[count] = childNode.Forge; paramTypes[count] = childForges[count].EvaluationType; allConstants = false; if (eventType != null) { childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEnumSingleForge(enumeration); allowEventBeanType[count] = true; count++; continue; } var eventTypeColl = enumeration.GetEventTypeCollection(statementRawInfo, services); if (eventTypeColl != null) { childEvalsEventBeanReturnTypesForges[count] = new ExprEvalStreamNumEnumCollForge(enumeration); allowEventBeanCollType[count] = true; count++; continue; } } paramTypes[count] = childNode.Forge.EvaluationType; childForges[count] = childNode.Forge; count++; if (!childNode.Forge.ForgeConstantType.IsCompileTimeConstant) { allConstants = false; } } // Try to resolve the method MethodInfo method; try { if (optionalClass != null) { method = services.ImportServiceCompileTime.ResolveMethod( optionalClass, methodName, paramTypes, allowEventBeanType); } else { method = services.ImportServiceCompileTime.ResolveMethodOverloadChecked( className, methodName, paramTypes, allowEventBeanType, allowEventBeanCollType, services.ClassProvidedExtension); } } catch (Exception e) { throw exceptionHandler.Handle(e); } var parameterTypes = method.GetParameterTypes(); // rewrite those evaluator that should return the event itself if (CollectionUtil.IsAnySet(allowEventBeanType)) { for (var i = 0; i < parameters.Count; i++) { if (allowEventBeanType[i] && parameterTypes[i] == typeof(EventBean)) { childForges[i] = childEvalsEventBeanReturnTypesForges[i]; } } } // rewrite those evaluators that should return the event collection if (CollectionUtil.IsAnySet(allowEventBeanCollType)) { for (var i = 0; i < parameters.Count; i++) { if (allowEventBeanCollType[i] && (parameterTypes[i] == typeof(ICollection<EventBean>))) { childForges[i] = childEvalsEventBeanReturnTypesForges[i]; } } } // add an evaluator if the method expects a context object if (!method.IsVarArgs() && parameterTypes.Length > 0 && parameterTypes[parameterTypes.Length - 1] == typeof(EPLMethodInvocationContext)) { var node = new ExprEvalMethodContext(functionName); childForges = (ExprForge[]) CollectionUtil.ArrayExpandAddSingle(childForges, node); } // handle varargs if (method.IsVarArgs()) { // handle context parameter var numMethodParams = parameterTypes.Length; if (numMethodParams > 1 && parameterTypes[numMethodParams - 2] == typeof(EPLMethodInvocationContext)) { var rewrittenForges = new ExprForge[childForges.Length + 1]; Array.Copy(childForges, 0, rewrittenForges, 0, numMethodParams - 2); rewrittenForges[numMethodParams - 2] = new ExprEvalMethodContext(functionName); Array.Copy( childForges, numMethodParams - 2, rewrittenForges, numMethodParams - 1, childForges.Length - (numMethodParams - 2)); childForges = rewrittenForges; } childForges = ExprNodeUtilityMake.MakeVarargArrayForges(method, childForges); } var localInlinedClass = services.ClassProvidedExtension.IsLocalInlinedClass(method.DeclaringType); return new ExprNodeUtilMethodDesc(allConstants, childForges, method, localInlinedClass); }
public virtual void AddChildNode(ExprNode childNode) { ChildNodes = (ExprNode[]) CollectionUtil.ArrayExpandAddSingle(ChildNodes, childNode); }