Ejemplo n.º 1
0
        public static IList <ExprNode> GetExprNodesLibFunc(EsperEPL2GrammarParser.LibFunctionArgsContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap)
        {
            if (ctx == null)
            {
                return(Collections.GetEmptyList <ExprNode>());
            }
            IList <EsperEPL2GrammarParser.LibFunctionArgItemContext> args = ctx.libFunctionArgItem();

            if (args == null || args.IsEmpty())
            {
                return(Collections.GetEmptyList <ExprNode>());
            }
            IList <ExprNode> parameters = new List <ExprNode>(args.Count);

            foreach (var arg in args)
            {
                if (arg.expressionLambdaDecl() != null)
                {
                    var lambdaparams = GetLambdaGoesParams(arg.expressionLambdaDecl());
                    var goes         = new ExprLambdaGoesNode(lambdaparams);
                    var lambdaExpr   = ASTExprHelper.ExprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap)[0];
                    goes.AddChildNode(lambdaExpr);
                    parameters.Add(goes);
                }
                else
                {
                    var parameter = ASTExprHelper.ExprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap)[0];
                    parameters.Add(parameter);
                }
            }
            return(parameters);
        }
Ejemplo n.º 2
0
        public override EnumForgeDescFactory GetForgeFactory(
            DotMethodFP footprint,
            IList <ExprNode> parameters,
            EnumMethodEnum enumMethod,
            string enumMethodUsedName,
            EventType inputEventType,
            Type collectionComponentType,
            ExprValidationContext validationContext)
        {
            if (parameters.Count < 2)
            {
                throw new IllegalStateException();
            }

            EPType             returnType   = ReturnType(inputEventType, collectionComponentType);
            ExprLambdaGoesNode lambdaFirst  = (ExprLambdaGoesNode)parameters[0];
            ExprLambdaGoesNode lambdaSecond = (ExprLambdaGoesNode)parameters[1];

            if (lambdaFirst.GoesToNames.Count != lambdaSecond.GoesToNames.Count)
            {
                throw new ExprValidationException(
                          "Enumeration method '" + enumMethodUsedName + "' expected the same number of parameters for both the key and the value expression");
            }

            int numParameters = lambdaFirst.GoesToNames.Count;

            if (inputEventType != null)
            {
                string streamNameFirst  = lambdaFirst.GoesToNames[0];
                string streamNameSecond = lambdaSecond.GoesToNames[0];
                if (numParameters == 1)
                {
                    return(new TwoLambdaThreeFormEventPlainFactory(inputEventType, streamNameFirst, streamNameSecond, returnType, TwoParamEventPlain()));
                }

                IDictionary <string, object> fieldsFirst  = new Dictionary <string, object>();
                IDictionary <string, object> fieldsSecond = new Dictionary <string, object>();
                fieldsFirst.Put(lambdaFirst.GoesToNames[1], typeof(int?));
                fieldsSecond.Put(lambdaSecond.GoesToNames[1], typeof(int?));
                if (numParameters > 2)
                {
                    fieldsFirst.Put(lambdaFirst.GoesToNames[2], typeof(int?));
                    fieldsSecond.Put(lambdaSecond.GoesToNames[2], typeof(int?));
                }

                ObjectArrayEventType typeFirst = ExprDotNodeUtility.MakeTransientOAType(
                    enumMethodUsedName,
                    fieldsFirst,
                    validationContext.StatementRawInfo,
                    validationContext.StatementCompileTimeService);
                ObjectArrayEventType typeSecond = ExprDotNodeUtility.MakeTransientOAType(
                    enumMethodUsedName,
                    fieldsSecond,
                    validationContext.StatementRawInfo,
                    validationContext.StatementCompileTimeService);
                return(new TwoLambdaThreeFormEventPlusFactory(
                           inputEventType,
                           streamNameFirst,
                           streamNameSecond,
                           typeFirst,
                           typeSecond,
                           lambdaFirst.GoesToNames.Count,
                           returnType,
                           TwoParamEventPlus()));
            }
            else
            {
                IDictionary <string, object> fieldsFirst  = new Dictionary <string, object>();
                IDictionary <string, object> fieldsSecond = new Dictionary <string, object>();
                fieldsFirst.Put(lambdaFirst.GoesToNames[0], collectionComponentType);
                fieldsSecond.Put(lambdaSecond.GoesToNames[0], collectionComponentType);
                if (numParameters > 1)
                {
                    fieldsFirst.Put(lambdaFirst.GoesToNames[1], typeof(int?));
                    fieldsSecond.Put(lambdaSecond.GoesToNames[1], typeof(int?));
                }

                if (numParameters > 2)
                {
                    fieldsFirst.Put(lambdaFirst.GoesToNames[2], typeof(int?));
                    fieldsSecond.Put(lambdaSecond.GoesToNames[2], typeof(int?));
                }

                ObjectArrayEventType typeFirst = ExprDotNodeUtility.MakeTransientOAType(
                    enumMethodUsedName,
                    fieldsFirst,
                    validationContext.StatementRawInfo,
                    validationContext.StatementCompileTimeService);
                ObjectArrayEventType typeSecond = ExprDotNodeUtility.MakeTransientOAType(
                    enumMethodUsedName,
                    fieldsSecond,
                    validationContext.StatementRawInfo,
                    validationContext.StatementCompileTimeService);

                return(new TwoLambdaThreeFormScalarFactory(
                           typeFirst,
                           typeSecond,
                           lambdaFirst.GoesToNames.Count,
                           returnType,
                           TwoParamScalar()));
            }
        }