Example #1
0
 public CodegenExpression MakeCodegen(
     CodegenClassScope classScope,
     CodegenMethodScope parent)
 {
     var method = parent.MakeChild(typeof(double), GetType(), classScope);
     var result = CodegenLegoMethodExpression.CodegenExpression(_runtimeConstant.Forge, method, classScope, true);
     method.Block.MethodReturn(
         ExprDotMethod(
             LocalMethod(result, ConstantNull(), ConstantTrue(), ConstantNull()),
             "AsDouble"));
     return LocalMethod(method);
 }
Example #2
0
 private static CodegenExpression FormatFieldExpr(
     Type type,
     ExprForge formatExpr,
     CodegenClassScope codegenClassScope)
 {
     var formatEval = CodegenLegoMethodExpression.CodegenExpression(
         formatExpr,
         codegenClassScope.NamespaceScope.InitMethod,
         codegenClassScope,
         true);
     CodegenExpression formatInit = LocalMethod(formatEval, ConstantNull(), ConstantTrue(), ConstantNull());
     return codegenClassScope.AddDefaultFieldUnshared(true, type, formatInit);
 }
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), this.GetType(), classScope);
            var eps = symbols.GetAddEPS(method);
            var evalCtx = symbols.GetAddExprEvalCtx(method);
            var left = symbols.GetAddLeftResult(method);

            method.Block.IfNullReturnNull(symbols.GetAddLeftResult(method));
            if (havingEval != null) {
                CodegenExpression having = LocalMethod(
                    CodegenLegoMethodExpression.CodegenExpression(havingEval, method, classScope, true),
                    eps,
                    ConstantTrue(),
                    evalCtx);
                CodegenLegoBooleanExpression.CodegenReturnValueIfNullOrNotPass(
                    method.Block,
                    havingEval.EvaluationType,
                    having,
                    ConstantNull());
            }

            CodegenExpression select = LocalMethod(
                CodegenLegoMethodExpression.CodegenExpression(selectEval, method, classScope, true),
                eps,
                ConstantTrue(),
                evalCtx);
            var rightEvalType = Boxing.GetBoxedType(selectEval.EvaluationType);
            method.Block
                .DeclareVar(rightEvalType, "rhs", select)
                .IfRefNullReturnNull("rhs");

            if (coercer == null) {
                method.Block.IfCondition(ExprDotMethod(left, "Equals", Ref("rhs"))).BlockReturn(Constant(!isNotIn));
            }
            else {
                method.Block.DeclareVar<object>("left", coercer.CoerceCodegen(left, symbols.LeftResultType))
                    .DeclareVar<object>("right", coercer.CoerceCodegen(Ref("valueRight"), rightEvalType))
                    .DeclareVar<bool>("eq", StaticMethod<object>("Equals", Ref("left"), Ref("right")))
                    .IfCondition(Ref("eq"))
                    .BlockReturn(Constant(!isNotIn));
            }

            method.Block.MethodReturn(Constant(isNotIn));
            return LocalMethod(method);
        }
Example #4
0
 public CodegenExpression EventBeanWithCtxGet(
     CodegenExpression beanExpression,
     CodegenExpression ctxExpression,
     CodegenMethodScope parent,
     CodegenClassScope classScope)
 {
     var method = parent
         .MakeChild(typeof(object), GetType(), classScope)
         .AddParam(typeof(EventBean), "eventBean")
         .AddParam(typeof(ExprEvaluatorContext), "ctx");
     var getImpl = CodegenLegoMethodExpression.CodegenExpression(_lookupable.Forge, method, classScope);
     method.Block
         .DeclareVar<EventBean[]>("events", NewArrayWithInit(typeof(EventBean), Ref("eventBean")))
         .MethodReturn(LocalMethod(getImpl, NewArrayWithInit(typeof(EventBean), Ref("eventBean")), ConstantTrue(), Ref("ctx")));
     return LocalMethod(method, beanExpression, ctxExpression);
 }
Example #5
0
            public CodegenExpression EventBeanGetCodegen(
                CodegenExpression beanExpression,
                CodegenMethodScope parent,
                CodegenClassScope codegenClassScope)
            {
                var method = parent.MakeChild(exprForge.EvaluationType, GetType(), codegenClassScope)
                    .AddParam(typeof(EventBean), "bean");
                var exprMethod =
                    CodegenLegoMethodExpression.CodegenExpression(exprForge, method, codegenClassScope, true);

                method.Block
                    .DeclareVar<EventBean[]>("events", NewArrayByLength(typeof(EventBean), Constant(1)))
                    .AssignArrayElement(Ref("events"), Constant(0), Ref("bean"))
                    .MethodReturn(LocalMethod(exprMethod, Ref("events"), ConstantTrue(), ConstantNull()));

                return LocalMethod(method, beanExpression);
            }
Example #6
0
        public override CodegenExpression EvaluateCodegenUninstrumented(
            Type requiredType,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            if (EvaluationType == typeof(void)) {
                return Noop();
            }

            var initMethod = codegenClassScope.NamespaceScope.InitMethod;
            var evaluate = CodegenLegoMethodExpression.CodegenExpression(_inner, initMethod, codegenClassScope, true);
            return codegenClassScope.AddDefaultFieldUnshared(
                true,
                EvaluationType,
                LocalMethod(evaluate, ConstantNull(), ConstantTrue(), ConstantNull()));
        }
        private static CodegenMethod GetComparableWObjectArrayKeyCodegen(
            ExprNode[] criteria,
            CodegenExpressionMember member,
            CodegenNamedMethods namedMethods,
            CodegenClassScope classScope)
        {
            var methodName = "GetComparable_" + member.Ref;
            Consumer <CodegenMethod> code = method => {
                if (criteria.Length == 1)
                {
                    method.Block.MethodReturn(
                        LocalMethod(
                            CodegenLegoMethodExpression.CodegenExpression(criteria[0].Forge, method, classScope),
                            REF_EPS,
                            REF_ISNEWDATA,
                            REF_EXPREVALCONTEXT));
                }
                else
                {
                    var exprSymbol  = new ExprForgeCodegenSymbol(true, null);
                    var expressions = new CodegenExpression[criteria.Length];
                    for (var i = 0; i < criteria.Length; i++)
                    {
                        expressions[i] = criteria[i].Forge.EvaluateCodegen(typeof(object), method, exprSymbol, classScope);
                    }

                    exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope);

                    method.Block.DeclareVar <object[]>("result", NewArrayByLength(typeof(object), Constant(criteria.Length)));
                    for (var i = 0; i < criteria.Length; i++)
                    {
                        method.Block.AssignArrayElement(Ref("result"), Constant(i), expressions[i]);
                    }

                    method.Block.MethodReturn(Ref("result"));
                }
            };

            return(namedMethods.AddMethod(
                       typeof(object),
                       methodName,
                       CodegenNamedParam.From(typeof(EventBean[]), NAME_EPS, typeof(bool), NAME_ISNEWDATA, typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT),
                       typeof(AggregatorAccessSortedImpl),
                       classScope,
                       code));
        }
Example #8
0
        private CodegenExpression GetSelectClauseExpr(
            CodegenMethod method,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause.Length == 1) {
                var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[0].Forge, method, classScope, true);
                return LocalMethod(eval, REF_EVENTS_SHIFTED, ConstantTrue(), symbols.GetAddExprEvalCtx(method));
            }

            var methodSelect = ExprNodeUtilityCodegen.CodegenMapSelect(
                subselect.SelectClause,
                subselect.SelectAsNames,
                this.GetType(),
                method,
                classScope);
            return LocalMethod(methodSelect, REF_EVENTS_SHIFTED, ConstantTrue(), symbols.GetAddExprEvalCtx(method));
        }
Example #9
0
        private static CodegenMethod GetBeanFirstLastIndexCodegen(
            AggregationAccessorFirstLastIndexWEvalForge forge,
            int column,
            CodegenClassScope classScope,
            AggregationStateLinearForge stateForge,
            CodegenMethod parent,
            CodegenNamedMethods namedMethods)
        {
            CodegenMethod method = parent.MakeChild(
                typeof(EventBean),
                typeof(AggregationAccessorFirstLastIndexWEval),
                classScope);
            if (forge.Constant == -1) {
                Type evalType = forge.IndexNode.EvaluationType;
                method.Block.DeclareVar(
                    evalType,
                    "indexResult",
                    LocalMethod(
                        CodegenLegoMethodExpression.CodegenExpression(
                            forge.IndexNode,
                            method, 
                            classScope,
                            true),
                        ConstantNull(),
                        ConstantTrue(),
                        ConstantNull()));
                if (evalType.CanBeNull()) {
                    method.Block.IfRefNullReturnNull("indexResult");
                }

                method.Block.DeclareVar<int>(
                    "index",
                    SimpleNumberCoercerFactory.CoercerInt.CodegenInt(Ref("indexResult"), evalType));
            }
            else {
                method.Block.DeclareVar<int>("index", Constant(forge.Constant));
            }

            CodegenExpression value = forge.IsFirst
                ? stateForge.AggregatorLinear.GetFirstNthValueCodegen(Ref("index"), method, classScope, namedMethods)
                : stateForge.AggregatorLinear.GetLastNthValueCodegen(Ref("index"), method, classScope, namedMethods);
            method.Block.MethodReturn(value);
            return method;
        }
        public CodegenExpression MakeCodegen(
            CodegenClassScope classScope,
            CodegenMethodScope parent)
        {
            var method = parent.MakeChild(typeof(object), GetType(), classScope).AddParam(GET_FILTER_VALUE_FP);
            var rhsExpression = CodegenLegoMethodExpression.CodegenExpression(value.Forge, method, classScope);
            var matchEventConvertor = convertor.Make(method, classScope);

            CodegenExpression valueExpr = LocalMethod(rhsExpression, Ref("eps"), ConstantTrue(), REF_EXPREVALCONTEXT);
            if (numberCoercer != null) {
                valueExpr = numberCoercer.CoerceCodegenMayNullBoxed(valueExpr, value.Forge.EvaluationType, method, classScope);
            }

            method.Block
                .DeclareVar<EventBean[]>("eps", LocalMethod(matchEventConvertor, REF_MATCHEDEVENTMAP))
                .MethodReturn(valueExpr);

            return LocalMethod(method, GET_FILTER_VALUE_REFS);
        }
Example #11
0
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpressionInstanceField eventToPublic =
                TableDeployTimeResolver.MakeTableEventToPublicField(table, classScope, this.GetType());
            CodegenMethod method = parent.MakeChild(subselect.EvaluationType, this.GetType(), classScope);

            method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

            method.Block.DeclareVar<EventBean>("filtered", ConstantNull());
            CodegenBlock @foreach = method.Block.ForEach(
                typeof(EventBean),
                "@event",
                symbols.GetAddMatchingEvents(method));
            {
                @foreach.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                CodegenMethod filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                    @foreach,
                    typeof(bool?),
                    LocalMethod(
                        filter,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
                @foreach.IfCondition(NotEqualsNull(Ref("filtered")))
                    .BlockReturn(ConstantNull())
                    .AssignRef("filtered", Ref("@event"));
            }

            method.Block.IfRefNullReturnNull("filtered")
                .MethodReturn(
                    ExprDotMethod(
                        eventToPublic,
                        "ConvertToUnd",
                        Ref("filtered"),
                        symbols.GetAddEPS(method),
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
            return LocalMethod(method);
        }
Example #12
0
        public CodegenExpression EventBeanGetCodegen(
            CodegenExpression beanExpression,
            CodegenMethodScope parent,
            CodegenClassScope classScope)
        {
            CodegenMethod method = parent.MakeChild(typeof(object), this.GetType(), classScope)
                .AddParam(typeof(EventBean), "eventBean");
            CodegenMethod methodExpr = CodegenLegoMethodExpression.CodegenExpression(eval.Forge, method, classScope, true);
            method.Block
                .DeclareVar<EventBean[]>("events", NewArrayWithInit(typeof(EventBean), Ref("eventBean")))
                .DeclareVar<object>("code", LocalMethod(methodExpr, Ref("events"), ConstantTrue(), ConstantNull()))
                .MethodReturn(
                    StaticMethod(
                        typeof(ContextControllerHashedGetterHashSingleForge),
                        "ObjectToNativeHash",
                        Ref("code"),
                        Constant(granularity)));

            return LocalMethod(method, beanExpression);
        }
Example #13
0
 public static void GetValueCodegen(
     AggregationAccessorFirstWEvalForge forge,
     AggregationStateLinearForge accessStateFactory,
     AggregationAccessorForgeGetCodegenContext context)
 {
     CodegenMethod childExpr = CodegenLegoMethodExpression.CodegenExpression(
         forge.ChildNode,
         context.Method,
         context.ClassScope,
         true);
     context.Method.Block.DeclareVar<EventBean>(
             "bean",
             accessStateFactory.AggregatorLinear.GetFirstValueCodegen(context.ClassScope, context.Method))
         .DebugStack()
         .IfRefNullReturnNull("bean")
         .DeclareVar<EventBean[]>(
             "eventsPerStreamBuf",
             NewArrayByLength(typeof(EventBean), Constant(forge.StreamNum + 1)))
         .AssignArrayElement("eventsPerStreamBuf", Constant(forge.StreamNum), Ref("bean"))
         .MethodReturn(LocalMethod(childExpr, Ref("eventsPerStreamBuf"), Constant(true), ConstantNull()));
 }
Example #14
0
        public CodegenExpression EvaluateCodegenUninstrumented(
            Type requiredType,
            CodegenMethodScope parent,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var method = parent.MakeChild(EvaluationType, GetType(), codegenClassScope);
            var innerEval = CodegenLegoMethodExpression.CodegenExpression(InnerForge, method, codegenClassScope, true);
            var eps = exprSymbol.GetAddEPS(method);

            // see ExprPriorEvalStrategyBase
            CodegenExpression future = codegenClassScope.NamespaceScope.AddOrGetDefaultFieldWellKnown(
                priorStrategyFieldName,
                typeof(PriorEvalStrategy));

            var innerMethod = LocalMethod(
                innerEval,
                eps,
                exprSymbol.GetAddIsNewData(method),
                exprSymbol.GetAddExprEvalCtx(method));
            method.Block
                .DeclareVar<EventBean>("originalEvent", ArrayAtIndex(eps, Constant(StreamNumber)))
                .DeclareVar<EventBean>(
                    "substituteEvent",
                    ExprDotMethod(
                        future,
                        "GetSubstituteEvent",
                        Ref("originalEvent"),
                        exprSymbol.GetAddIsNewData(method),
                        Constant(ConstantIndexNumber),
                        Constant(RelativeIndex),
                        exprSymbol.GetAddExprEvalCtx(method),
                        Constant(StreamNumber)))
                .AssignArrayElement(eps, Constant(StreamNumber), Ref("substituteEvent"))
                .DeclareVar(EvaluationType, "evalResult", innerMethod)
                .AssignArrayElement(eps, Constant(StreamNumber), Ref("originalEvent"))
                .MethodReturn(Ref("evalResult"));

            return LocalMethod(method);
        }
Example #15
0
        public CodegenExpression EvaluateMatchesCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool), GetType(), classScope);
            var havingMethod = CodegenLegoMethodExpression.CodegenExpression(havingEval, method, classScope, true);
            CodegenExpression having = LocalMethod(
                havingMethod,
                REF_EVENTS_SHIFTED,
                symbols.GetAddIsNewData(method),
                symbols.GetAddExprEvalCtx(method));

            method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);
            CodegenLegoBooleanExpression.CodegenReturnValueIfNullOrNotPass(
                method.Block,
                typeof(bool?),
                having,
                ConstantFalse());
            method.Block.MethodReturn(ConstantTrue());
            return LocalMethod(method);
        }
Example #16
0
        private CodegenExpression EvaluateCodegenPrevAndTail(
            CodegenMethodScope parent,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var method = parent.MakeChild(ResultType, GetType(), codegenClassScope);

            var eps = exprSymbol.GetAddEPS(method);
            var innerEval = CodegenLegoMethodExpression.CodegenExpression(
                ChildNodes[1].Forge,
                method,
                codegenClassScope,
                true);

            method.Block
                .IfCondition(Not(exprSymbol.GetAddIsNewData(method)))
                .BlockReturn(ConstantNull())
                .DeclareVar<EventBean>(
                    "substituteEvent",
                    LocalMethod(
                        GetSubstituteCodegen(method, exprSymbol, codegenClassScope),
                        eps,
                        exprSymbol.GetAddExprEvalCtx(method)))
                .IfRefNullReturnNull("substituteEvent")
                .DeclareVar<EventBean>("originalEvent", ArrayAtIndex(eps, Constant(StreamNumber)))
                .AssignArrayElement(eps, Constant(StreamNumber), Ref("substituteEvent"))
                .DeclareVar(
                    ResultType,
                    "evalResult",
                    LocalMethod(
                        innerEval,
                        eps,
                        exprSymbol.GetAddIsNewData(method),
                        exprSymbol.GetAddExprEvalCtx(method)))
                .AssignArrayElement(eps, Constant(StreamNumber), Ref("originalEvent"))
                .MethodReturn(Ref("evalResult"));

            return LocalMethod(method);
        }
 public static void GetEnumerableScalarCodegen(
     AggregationAccessorWindowWEvalForge forge,
     AggregationStateLinearForge stateForge,
     AggregationAccessorForgeGetCodegenContext context)
 {
     context.Method.Block
         .DeclareVar<int>("size", stateForge.AggregatorLinear.SizeCodegen())
         .IfCondition(EqualsIdentity(Ref("size"), Constant(0)))
         .BlockReturn(ConstantNull())
         .DeclareVar<IList<object>>("values", NewInstance<List<object>>(Ref("size")))
         .DeclareVar<IEnumerator<EventBean>>(
             "enumerator",
             stateForge.AggregatorLinear.EnumeratorCodegen(
                 context.ClassScope,
                 context.Method,
                 context.NamedMethods))
         .DebugStack()
         .DeclareVar<EventBean[]>(
             "eventsPerStreamBuf",
             NewArrayByLength(typeof(EventBean), Constant(forge.StreamNum + 1)))
         .WhileLoop(ExprDotMethod(Ref("enumerator"), "MoveNext"))
         .DeclareVar<EventBean>("bean", Cast(typeof(EventBean), ExprDotName(Ref("enumerator"), "Current")))
         .AssignArrayElement("eventsPerStreamBuf", Constant(forge.StreamNum), Ref("bean"))
         .DeclareVar(
             forge.ChildNode.EvaluationType.GetBoxedType(),
             "value",
             LocalMethod(
                 CodegenLegoMethodExpression.CodegenExpression(
                     forge.ChildNode,
                     context.Method,
                     context.ClassScope,
                     true),
                 Ref("eventsPerStreamBuf"),
                 ConstantTrue(),
                 ConstantNull()))
         .ExprDotMethod(Ref("values"), "Add", Ref("value"))
         .BlockEnd()
         .MethodReturn(Ref("values"));
 }
        public static void GetValueCodegen(
            AggregationAccessorWindowWEvalForge forge,
            AggregationStateLinearForge accessStateFactory,
            AggregationAccessorForgeGetCodegenContext context)
        {
            var size = accessStateFactory.AggregatorLinear.SizeCodegen();
            var enumerator = accessStateFactory.AggregatorLinear.EnumeratorCodegen(
                context.ClassScope,
                context.Method,
                context.NamedMethods);
            var childExpr = CodegenLegoMethodExpression.CodegenExpression(
                forge.ChildNode,
                context.Method,
                context.ClassScope,
                false);
            var childExprType = forge.ChildNode.EvaluationType;

            CodegenExpression invokeChild = LocalMethod(childExpr, Ref("eventsPerStreamBuf"), Constant(true), ConstantNull());
            if (forge.ComponentType != childExprType) {
                invokeChild = Unbox(invokeChild);
            }

            context.Method.Block
                .IfCondition(EqualsIdentity(size, Constant(0)))
                .BlockReturn(ConstantNull())
                .DeclareVar(TypeHelper.GetArrayType(forge.ComponentType), "array", NewArrayByLength(forge.ComponentType, size))
                .DeclareVar<int>("count", Constant(0))
                .DeclareVar<IEnumerator<EventBean>>("enumerator", enumerator)
                .DebugStack()
                .DeclareVar<EventBean[]>("eventsPerStreamBuf", NewArrayByLength(typeof(EventBean), Constant(forge.StreamNum + 1)))
                .WhileLoop(ExprDotMethod(Ref("enumerator"), "MoveNext"))
                .DeclareVar<EventBean>("bean", Cast(typeof(EventBean), ExprDotName(Ref("enumerator"), "Current")))
                .AssignArrayElement("eventsPerStreamBuf", Constant(forge.StreamNum), Ref("bean"))
                .AssignArrayElement(Ref("array"), Ref("count"), invokeChild)
                .IncrementRef("count")
                .BlockEnd()
                .MethodReturn(Ref("array"));
        }
Example #19
0
        private CodegenExpression EvaluateCodegenPrevWindow(
            Type requiredType,
            CodegenMethodScope parent,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            var method = parent.MakeChild(ResultType, GetType(), codegenClassScope);

            method.Block
                .DeclareVar<PreviousGetterStrategy>(
                    "strategy",
                    ExprDotMethod(GetterField(codegenClassScope), "GetStrategy", exprSymbol.GetAddExprEvalCtx(method)))
                .Apply(new PreviousBlockGetSizeAndIterator(method, exprSymbol, StreamNumber, Ref("strategy")).Accept);

            var eps = exprSymbol.GetAddEPS(method);
            var innerEval = CodegenLegoMethodExpression.CodegenExpression(
                ChildNodes[1].Forge,
                method,
                codegenClassScope,
                true);

            method.Block.DeclareVar<EventBean>("originalEvent", ArrayAtIndex(eps, Constant(StreamNumber)))
                .DeclareVar(ResultType, "result", NewArrayByLength(ResultType.GetElementType(), Ref("size")))
                .ForLoopIntSimple("i", Ref("size"))
                .ExprDotMethod(Ref("events"), "MoveNext")
                .AssignArrayElement(
                    eps,
                    Constant(StreamNumber),
                    Cast(typeof(EventBean), ExprDotName(Ref("events"), "Current")))
                .AssignArrayElement(
                    "result",
                    Ref("i"),
                    LocalMethod(innerEval, eps, ConstantTrue(), exprSymbol.GetAddExprEvalCtx(method)))
                .BlockEnd()
                .AssignArrayElement(eps, Constant(StreamNumber), Ref("originalEvent"))
                .MethodReturn(Ref("result"));
            return LocalMethod(method);
        }
Example #20
0
        public override CodegenMethod MakeCodegen(
            CodegenClassScope classScope,
            CodegenMethodScope parent,
            SAIFFInitializeSymbolWEventType symbols)
        {
            var method = parent
                         .MakeChild(typeof(FilterSpecParam), GetType(), classScope);

            method.Block
            .DeclareVar <ExprFilterSpecLookupable>(
                "lookupable",
                LocalMethod(lookupable.MakeCodegen(method, symbols, classScope)))
            .DeclareVar <FilterOperator>("filterOperator", EnumValue(typeof(FilterOperator), filterOperator.GetName()));

            var getFilterValue = new CodegenExpressionLambda(method.Block)
                                 .WithParams(FilterSpecParam.GET_FILTER_VALUE_FP);
            var inner = NewInstance <ProxyFilterSpecParam>(
                Ref("lookupable"),
                Ref("filterOperator"),
                getFilterValue);

            var rhsExpression       = CodegenLegoMethodExpression.CodegenExpression(_value.Forge, method, classScope);
            var matchEventConvertor = _convertor.Make(method, classScope);

            CodegenExpression valueExpr = LocalMethod(rhsExpression, Ref("eps"), ConstantTrue(), REF_EXPREVALCONTEXT);

            if (_numberCoercer != null)
            {
                valueExpr = _numberCoercer.CoerceCodegenMayNullBoxed(valueExpr, _value.Forge.EvaluationType, method, classScope);
            }

            getFilterValue.Block
            .DeclareVar <EventBean[]>("eps", LocalMethod(matchEventConvertor, FilterSpecParam.REF_MATCHEDEVENTMAP))
            .BlockReturn(FilterValueSetParamImpl.CodegenNew(valueExpr));

            method.Block.MethodReturn(inner);
            return(method);
        }
        protected override CodegenExpression CodegenEvaluateInternal(
            CodegenMethodScope parent,
            SubselectForgeNRSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(bool?), GetType(), classScope);
            CodegenExpression eps = symbols.GetAddEPS(method);
            CodegenExpression evalCtx = symbols.GetAddExprEvalCtx(method);
            var left = symbols.GetAddLeftResult(method);

            if (havingEval != null) {
                CodegenExpression having = LocalMethod(
                    CodegenLegoMethodExpression.CodegenExpression(havingEval, method, classScope, true),
                    eps,
                    ConstantTrue(),
                    evalCtx);
                CodegenLegoBooleanExpression.CodegenReturnValueIfNullOrNotPass(
                    method.Block,
                    havingEval.EvaluationType,
                    having,
                    ConstantNull());
            }

            CodegenExpression rhsSide = LocalMethod(
                CodegenLegoMethodExpression.CodegenExpression(selectEval, method, classScope, true),
                eps,
                ConstantTrue(),
                evalCtx);
            var rhsType = selectEval.EvaluationType.GetBoxedType();
            method.Block
                .DeclareVar(rhsType, "rhs", rhsSide)
                .IfRefNullReturnNull("rhs")
                .MethodReturn(computer.Codegen(left, symbols.LeftResultType, Ref("rhs"), rhsType));

            return LocalMethod(method);
        }
Example #22
0
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(subselect.EvaluationType, this.GetType(), classScope);

            if (subselect.FilterExpr == null) {
                method.Block
                    .IfCondition(
                        Relational(
                            ExprDotName(symbols.GetAddMatchingEvents(method), "Count"),
                            CodegenExpressionRelational.CodegenRelational.GT,
                            Constant(1)))
                    .BlockReturn(ConstantNull());
                if (subselect.SelectClause == null) {
                    method.Block.MethodReturn(
                        Cast(
                            subselect.EvaluationType,
                            StaticMethod(
                                typeof(EventBeanUtility),
                                "GetNonemptyFirstEventUnderlying",
                                symbols.GetAddMatchingEvents(method))));
                    return LocalMethod(method);
                }
                else {
                    method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                        .AssignArrayElement(
                            REF_EVENTS_SHIFTED,
                            Constant(0),
                            StaticMethod(
                                typeof(EventBeanUtility),
                                "GetNonemptyFirstEvent",
                                symbols.GetAddMatchingEvents(method)));
                }
            }
            else {
                method.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols);

                method.Block.DeclareVar<EventBean>("filtered", ConstantNull());
                var @foreach = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    @foreach.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                    var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                    CodegenLegoBooleanExpression.CodegenContinueIfNotNullAndNotPass(
                        @foreach,
                        typeof(bool?),
                        LocalMethod(
                            filter,
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddExprEvalCtx(method)));
                    @foreach.IfCondition(NotEqualsNull(Ref("filtered")))
                        .BlockReturn(ConstantNull())
                        .AssignRef("filtered", Ref("@event"));
                }

                if (subselect.SelectClause == null) {
                    method.Block.IfRefNullReturnNull("filtered")
                        .MethodReturn(Cast(subselect.EvaluationType, ExprDotUnderlying(Ref("filtered"))));
                    return LocalMethod(method);
                }

                method.Block.IfRefNullReturnNull("filtered")
                    .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("filtered"));
            }

            var selectClause = GetSelectClauseExpr(method, symbols, classScope);
            method.Block.MethodReturn(selectClause);
            return LocalMethod(method);
        }
Example #23
0
        public static CodegenMethod DetermineLocalMinMaxCodegen(
            OrderByProcessorForgeImpl forge,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            var elements = forge.OrderBy;
            CodegenExpression comparator = classScope.AddOrGetDefaultFieldSharable(forge.IComparer);

            Consumer<CodegenMethod> code = method => {
                method.Block.DeclareVar<object>("localMinMax", ConstantNull())
                    .DeclareVar<EventBean>("outgoingMinMaxBean", ConstantNull())
                    .DeclareVar<int>("count", Constant(0));

                if (elements.Length == 1) {
                    var forEach = method.Block.ForEach(typeof(EventBean[]), "eventsPerStream", REF_GENERATINGEVENTS);

                    forEach.DeclareVar<object>(
                            "sortKey",
                            LocalMethod(
                                CodegenLegoMethodExpression.CodegenExpression(
                                    elements[0].ExprNode.Forge,
                                    method,
                                    classScope,
                                    true),
                                Ref("eventsPerStream"),
                                REF_ISNEWDATA,
                                REF_EXPREVALCONTEXT))
                        .IfCondition(
                            Or(
                                EqualsNull(Ref("localMinMax")),
                                Relational(
                                    ExprDotMethod(comparator, "Compare", Ref("localMinMax"), Ref("sortKey")),
                                    GT,
                                    Constant(0))))
                        .AssignRef("localMinMax", Ref("sortKey"))
                        .AssignRef("outgoingMinMaxBean", ArrayAtIndex(REF_OUTGOINGEVENTS, Ref("count")))
                        .BlockEnd()
                        .IncrementRef("count");
                }
                else {
                    method.Block.DeclareVar<object[]>(
                            "values",
                            NewArrayByLength(typeof(object), Constant(elements.Length)))
                        .DeclareVar<HashableMultiKey>(
                            "valuesMk",
                            NewInstance<HashableMultiKey>(Ref("values")));

                    var forEach = method.Block.ForEach(typeof(EventBean[]), "eventsPerStream", REF_GENERATINGEVENTS);

                    if (forge.IsNeedsGroupByKeys) {
                        forEach.ExprDotMethod(
                            MEMBER_AGGREGATIONSVC,
                            "SetCurrentAccess",
                            ArrayAtIndex(Ref("groupByKeys"), Ref("count")),
                            ExprDotMethod(REF_EXPREVALCONTEXT, "GetAgentInstanceId", ConstantNull()));
                    }

                    for (var i = 0; i < elements.Length; i++) {
                        forEach.AssignArrayElement(
                            "values",
                            Constant(i),
                            LocalMethod(
                                CodegenLegoMethodExpression.CodegenExpression(
                                    elements[i].ExprNode.Forge,
                                    method,
                                    classScope,
                                    true),
                                Ref("eventsPerStream"),
                                REF_ISNEWDATA,
                                REF_EXPREVALCONTEXT));
                    }

                    forEach.IfCondition(
                            Or(
                                EqualsNull(Ref("localMinMax")),
                                Relational(
                                    ExprDotMethod(comparator, "Compare", Ref("localMinMax"), Ref("valuesMk")),
                                    GT,
                                    Constant(0))))
                        .AssignRef("localMinMax", Ref("valuesMk"))
                        .AssignRef("values", NewArrayByLength(typeof(object), Constant(elements.Length)))
                        .AssignRef("valuesMk", NewInstance<HashableMultiKey>(Ref("values")))
                        .AssignRef("outgoingMinMaxBean", ArrayAtIndex(REF_OUTGOINGEVENTS, Ref("count")))
                        .BlockEnd()
                        .IncrementRef("count");
                }

                method.Block.MethodReturn(Ref("outgoingMinMaxBean"));
            };

            return namedMethods.AddMethod(
                typeof(EventBean),
                "DetermineLocalMinMax",
                CodegenNamedParam.From(
                    typeof(EventBean[]), REF_OUTGOINGEVENTS.Ref,
                    typeof(EventBean[][]), REF_GENERATINGEVENTS.Ref,
                    typeof(bool), NAME_ISNEWDATA,
                    typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT,
                    typeof(AggregationService), MEMBER_AGGREGATIONSVC.Ref),
                typeof(OrderByProcessorImpl),
                classScope,
                code);
        }
        public CodegenExpression EvaluateTypableMultirowCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause == null) {
                return ConstantNull();
            }

            if (subselect.FilterExpr == null) {
                var method = parent.MakeChild(typeof(object[][]), GetType(), classScope);
                method.Block
                    .DeclareVar<object[][]>(
                        "rows",
                        NewArrayByLength(typeof(object[]), ExprDotName(symbols.GetAddMatchingEvents(method), "Count")))
                    .DeclareVar<int>("index", Constant(-1))
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols);
                var foreachEvent = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    foreachEvent
                        .IncrementRef("index")
                        .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"))
                        .DeclareVar<object[]>(
                            "results",
                            NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)))
                        .AssignArrayElement("rows", Ref("index"), Ref("results"));
                    for (var i = 0; i < subselect.SelectClause.Length; i++) {
                        var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                        foreachEvent.AssignArrayElement(
                            "results",
                            Constant(i),
                            LocalMethod(
                                eval,
                                REF_EVENTS_SHIFTED,
                                symbols.GetAddIsNewData(method),
                                symbols.GetAddExprEvalCtx(method)));
                    }
                }
                method.Block.MethodReturn(Ref("rows"));
                return LocalMethod(method);
            }
            else {
                var method = parent.MakeChild(typeof(object[][]), GetType(), classScope);
                method.Block
                    .DeclareVar<ArrayDeque<object[]>>("rows", NewInstance(typeof(ArrayDeque<object[]>)))
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols);
                var foreachEvent = method.Block.ForEach(
                    typeof(EventBean),
                    "@event",
                    symbols.GetAddMatchingEvents(method));
                {
                    foreachEvent.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));

                    var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, method, classScope, true);
                    CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                        foreachEvent,
                        typeof(bool?),
                        LocalMethod(
                            filter,
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddExprEvalCtx(method)));

                    foreachEvent
                        .DeclareVar<object[]>(
                            "results",
                            NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)))
                        .ExprDotMethod(Ref("rows"), "Add", Ref("results"));
                    for (var i = 0; i < subselect.SelectClause.Length; i++) {
                        var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                        foreachEvent.AssignArrayElement(
                            "results",
                            Constant(i),
                            LocalMethod(
                                eval,
                                REF_EVENTS_SHIFTED,
                                symbols.GetAddIsNewData(method),
                                symbols.GetAddExprEvalCtx(method)));
                    }
                }
                method.Block
                    .IfCondition(ExprDotMethod(Ref("rows"), "IsEmpty"))
                    .BlockReturn(EnumValue(typeof(CollectionUtil), "OBJECTARRAYARRAY_EMPTY"))
                    .MethodReturn(ExprDotMethod(Ref("rows"), "ToArray"));
                return LocalMethod(method);
            }
        }
        public CodegenExpression EvaluateTypableSinglerowCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.SelectClause == null) {
                return ConstantNull(); // no select-clause
            }

            var method = parent.MakeChild(typeof(object[]), GetType(), classScope);
            if (subselect.FilterExpr == null) {
                method.Block
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols)
                    .AssignArrayElement(
                        REF_EVENTS_SHIFTED,
                        Constant(0),
                        StaticMethod(
                            typeof(EventBeanUtility),
                            "GetNonemptyFirstEvent",
                            symbols.GetAddMatchingEvents(method)));
            }
            else {
                var filter = ExprNodeUtilityCodegen.CodegenEvaluator(
                    subselect.FilterExpr,
                    method,
                    GetType(),
                    classScope);
                method.Block
                    .ApplyTri(SubselectForgeCodegenUtil.DECLARE_EVENTS_SHIFTED, method, symbols)
                    .DeclareVar<EventBean>(
                        "subselectResult",
                        StaticMethod(
                            typeof(EventBeanUtility),
                            "EvaluateFilterExpectSingleMatch",
                            REF_EVENTS_SHIFTED,
                            symbols.GetAddIsNewData(method),
                            symbols.GetAddMatchingEvents(method),
                            symbols.GetAddExprEvalCtx(method),
                            filter))
                    .IfRefNullReturnNull("subselectResult")
                    .AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("subselectResult"));
            }

            method.Block.DeclareVar<object[]>(
                "results",
                NewArrayByLength(typeof(object), Constant(subselect.SelectClause.Length)));
            for (var i = 0; i < subselect.SelectClause.Length; i++) {
                var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[i].Forge, method, classScope, true);
                method.Block.AssignArrayElement(
                    "results",
                    Constant(i),
                    LocalMethod(
                        eval,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(method),
                        symbols.GetAddExprEvalCtx(method)));
            }

            method.Block.MethodReturn(Ref("results"));

            return LocalMethod(method);
        }
Example #26
0
        public static CodegenExpression MakePatternDeltaLambda(
            ExprNode parameter,
            MatchedEventConvertorForge convertor,
            TimeAbacus timeAbacus,
            CodegenMethod method,
            CodegenClassScope classScope)
        {
            var computeDelta = new CodegenExpressionLambda(method.Block)
                .WithParam<MatchedEventMap>("beginState")
                .WithParam<PatternAgentInstanceContext>("context");
            var compute = NewInstance<PatternDeltaCompute>(computeDelta);

            //var compute = NewAnonymousClass(method.Block, typeof(PatternDeltaCompute));
            //var computeDelta = CodegenMethod.MakeMethod(typeof(long), typeof(PatternDeltaComputeUtil), classScope)
            //    .AddParam(
            //        CodegenNamedParam.From(
            //            typeof(MatchedEventMap),
            //            "beginState",
            //            typeof(PatternAgentInstanceContext),
            //            "context"));
            //compute.AddMethod("ComputeDelta", computeDelta);

            if (parameter is ExprTimePeriod) {
                var timePeriod = (ExprTimePeriod) parameter;
                var time = ExprDotName(Ref("context"), "Time");
                if (timePeriod.IsConstantResult) {
                    var delta = classScope.AddDefaultFieldUnshared<TimePeriodCompute>(
                        true,
                        timePeriod.TimePeriodComputeForge.MakeEvaluator(
                            classScope.NamespaceScope.InitMethod,
                            classScope));
                    computeDelta.Block
                        .ReturnMethodOrBlock(
                            ExprDotMethod(
                                delta,
                                "DeltaAdd",
                                time,
                                ConstantNull(),
                                ConstantTrue(),
                                ExprDotMethod(Ref("context"), "GetAgentInstanceContext")));
                }
                else {
                    var delta = classScope.AddDefaultFieldUnshared<TimePeriodCompute>(
                        true,
                        timePeriod.TimePeriodComputeForge.MakeEvaluator(
                            classScope.NamespaceScope.InitMethod,
                            classScope));
                    computeDelta.Block
                        .DeclareVar<EventBean[]>(
                            "events",
                            LocalMethod(
                                convertor.Make(method, classScope),
                                //convertor.Make(computeDelta, classScope),
                                Ref("beginState")))
                        .ReturnMethodOrBlock(
                            ExprDotMethod(
                                delta,
                                "DeltaAdd",
                                time,
                                Ref("events"),
                                ConstantTrue(),
                                ExprDotMethod(Ref("context"), "GetAgentInstanceContext")));
                }
            }
            else {
                var eval = CodegenLegoMethodExpression.CodegenExpression(parameter.Forge, method, classScope, true);
                CodegenExpression events;
                if (parameter.Forge.ForgeConstantType.IsConstant) {
                    events = ConstantNull();
                }
                else {
                    events = LocalMethod(
                        convertor.Make(method, classScope),
                        //convertor.Make(computeDelta, classScope),
                        Ref("beginState"));
                }

                computeDelta.Block
                    .DeclareVar<EventBean[]>("events", events)
                    .DeclareVar(
                        parameter.Forge.EvaluationType.GetBoxedType(),
                        "result",
                        LocalMethod(
                            eval,
                            Ref("events"),
                            ConstantTrue(),
                            ExprDotMethod(Ref("context"), "GetAgentInstanceContext")));
                if (parameter.Forge.EvaluationType.CanBeNull()) {
                    computeDelta.Block
                        .IfRefNull("result")
                        .BlockThrow(
                            NewInstance<EPException>(Constant("Null value returned for guard expression")));
                }

                computeDelta.Block.ReturnMethodOrBlock(
                    timeAbacus.DeltaForSecondsDoubleCodegen(Ref("result"), classScope));
            }

            return compute;
        }
        public override CodegenExpression EvaluateGetCollEventsCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpression aggService = classScope.NamespaceScope.AddOrGetDefaultFieldWellKnown(
                new CodegenFieldNameSubqueryAgg(subselect.SubselectNumber),
                typeof(AggregationResultFuture));
            var factory = classScope.AddOrGetDefaultFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE);
            var subselectMultirowType = classScope.AddDefaultFieldUnshared(
                false,
                typeof(EventType),
                EventTypeUtility.ResolveTypeCodegen(
                    subselect.subselectMultirowType,
                    EPStatementInitServicesConstants.REF));

            var method = parent.MakeChild(typeof(FlexCollection), GetType(), classScope);
            var evalCtx = symbols.GetAddExprEvalCtx(method);

            method.Block
                .DeclareVar<int>("cpid", ExprDotName(evalCtx, "AgentInstanceId"))
                .DeclareVar<AggregationService>(
                    "aggregationService",
                    ExprDotMethod(aggService, "GetContextPartitionAggregationService", Ref("cpid")))
                .DeclareVar<ICollection<object>>(
                    "groupKeys",
                    ExprDotMethod(Ref("aggregationService"), "GetGroupKeys", evalCtx))
                .IfCondition(ExprDotMethod(Ref("groupKeys"), "IsEmpty"))
                .BlockReturn(ConstantNull())
                .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                .DeclareVar<ICollection<EventBean>>(
                    "result",
                    NewInstance<ArrayDeque<EventBean>>(ExprDotName(Ref("groupKeys"), "Count")));

            var forEach = method.Block.ForEach(typeof(object), "groupKey", Ref("groupKeys"));
            {
                var havingExpr = CodegenLegoMethodExpression.CodegenExpression(subselect.HavingExpr, method, classScope, true);
                CodegenExpression havingCall = LocalMethod(
                    havingExpr,
                    REF_EVENTS_SHIFTED,
                    symbols.GetAddIsNewData(method),
                    evalCtx);

                forEach
                    .ExprDotMethod(
                        Ref("aggregationService"),
                        "SetCurrentAccess",
                        Ref("groupKey"),
                        Ref("cpid"),
                        ConstantNull())
                    .DeclareVar<bool?>("pass", Cast(typeof(bool?), havingCall))
                    .IfCondition(And(NotEqualsNull(Ref("pass")), Unbox(Ref("pass"))))
                    .DeclareVar<IDictionary<string, object>>(
                        "row",
                        LocalMethod(
                            subselect.EvaluateRowCodegen(method, classScope),
                            REF_EVENTS_SHIFTED,
                            ConstantTrue(),
                            symbols.GetAddExprEvalCtx(method)))
                    .DeclareVar<EventBean>(
                        "@event",
                        ExprDotMethod(factory, "AdapterForTypedMap", Ref("row"), subselectMultirowType))
                    .ExprDotMethod(Ref("result"), "Add", Ref("@event"));
            }
            method.Block.MethodReturn(FlexWrap(Ref("result")));
            return LocalMethod(method);
        }
        public override CodegenExpression EvaluateCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            CodegenExpression aggService = classScope.NamespaceScope.AddOrGetDefaultFieldWellKnown(
                new CodegenFieldNameSubqueryAgg(subselect.SubselectNumber),
                typeof(AggregationResultFuture));

            var method = parent.MakeChild(subselect.EvaluationType, GetType(), classScope);
            var evalCtx = symbols.GetAddExprEvalCtx(method);

            method.Block
                .DeclareVar<int>("cpid", ExprDotName(evalCtx, "AgentInstanceId"))
                .DeclareVar<AggregationService>(
                    "aggregationService",
                    ExprDotMethod(aggService, "GetContextPartitionAggregationService", Ref("cpid")))
                .DeclareVar<ICollection<object>>(
                    "groupKeys",
                    ExprDotMethod(Ref("aggregationService"), "GetGroupKeys", evalCtx))
                .IfCondition(ExprDotMethod(Ref("groupKeys"), "IsEmpty"))
                .BlockReturn(ConstantNull())
                .ApplyTri(DECLARE_EVENTS_SHIFTED, method, symbols)
                .DeclareVar<bool>("haveResult", ConstantFalse())
                .DeclareVar<object>("groupKeyMatch", ConstantNull());

            var forEach = method.Block.ForEach(typeof(object), "groupKey", Ref("groupKeys"));
            {
                var havingExpr = CodegenLegoMethodExpression.CodegenExpression(subselect.HavingExpr, method, classScope, true);
                CodegenExpression havingCall = LocalMethod(
                    havingExpr,
                    REF_EVENTS_SHIFTED,
                    symbols.GetAddIsNewData(method),
                    evalCtx);

                forEach.ExprDotMethod(
                        Ref("aggregationService"),
                        "SetCurrentAccess",
                        Ref("groupKey"),
                        Ref("cpid"),
                        ConstantNull())
                    .DeclareVar<bool?>("pass", Cast(typeof(bool?), havingCall))
                    .IfCondition(And(NotEqualsNull(Ref("pass")), Unbox(Ref("pass"))))
                    .IfCondition(Ref("haveResult"))
                    .BlockReturn(ConstantNull())
                    .AssignRef("groupKeyMatch", Ref("groupKey"))
                    .AssignRef("haveResult", ConstantTrue());
            }

            method.Block.IfCondition(EqualsNull(Ref("groupKeyMatch")))
                .BlockReturn(ConstantNull())
                .ExprDotMethod(
                    Ref("aggregationService"),
                    "SetCurrentAccess",
                    Ref("groupKeyMatch"),
                    Ref("cpid"),
                    ConstantNull());

            if (subselect.SelectClause.Length == 1) {
                var eval = CodegenLegoMethodExpression.CodegenExpression(subselect.SelectClause[0].Forge, method, classScope, true);
                method.Block.MethodReturn(
                    LocalMethod(eval, REF_EVENTS_SHIFTED, ConstantTrue(), symbols.GetAddExprEvalCtx(method)));
            }
            else {
                var methodSelect = ExprNodeUtilityCodegen.CodegenMapSelect(
                    subselect.SelectClause,
                    subselect.SelectAsNames,
                    GetType(),
                    method,
                    classScope);
                CodegenExpression select = LocalMethod(
                    methodSelect,
                    REF_EVENTS_SHIFTED,
                    ConstantTrue(),
                    symbols.GetAddExprEvalCtx(method));
                method.Block.MethodReturn(select);
            }

            return LocalMethod(method);
        }
Example #29
0
        public override CodegenExpression EvaluateGetCollEventsCodegen(
            CodegenMethodScope parent,
            ExprSubselectEvalMatchSymbol symbols,
            CodegenClassScope classScope)
        {
            if (subselect.FilterExpr == null) {
                if (subselect.SelectClause == null) {
                    return symbols.GetAddMatchingEvents(parent);
                }
                else {
                    if (subselect.subselectMultirowType == null) {
                        var eval = ((ExprIdentNode) subselect.SelectClause[0]).ExprEvaluatorIdent;
                        var method = parent.MakeChild(
                            typeof(FlexCollection),
                            this.GetType(),
                            classScope);
                        method.Block.DeclareVar<ICollection<EventBean>>(
                            "events",
                            NewInstance<ArrayDeque<EventBean>>(
                                ExprDotName(symbols.GetAddMatchingEvents(method), "Count")));
                        var @foreach = method.Block.ForEach(
                            typeof(EventBean),
                            "@event",
                            symbols.GetAddMatchingEvents(method));
                        {
                            @foreach.DeclareVar<EventBean>(
                                    "fragment",
                                    CodegenLegoCast.CastSafeFromObjectType(
                                        typeof(EventBean),
                                        eval.Getter.EventBeanFragmentCodegen(Ref("@event"), method, classScope)))
                                .IfRefNull("fragment")
                                .BlockContinue()
                                .ExprDotMethod(Ref("events"), "Add", Ref("fragment"));
                        }
                        method.Block.MethodReturn(FlexWrap(Ref("events")));
                        return LocalMethod(method);
                    }

                    // when selecting a combined output row that contains multiple fields
                    var methodX = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);
                    var fieldEventType = classScope.AddDefaultFieldUnshared(
                        true,
                        typeof(EventType),
                        EventTypeUtility.ResolveTypeCodegen(
                            subselect.subselectMultirowType,
                            EPStatementInitServicesConstants.REF));
                    var eventBeanSvc =
                        classScope.AddOrGetDefaultFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE);

                    methodX.Block
                        .DeclareVar<ICollection<EventBean>>(
                            "result",
                            NewInstance<ArrayDeque<EventBean>>(
                                ExprDotName(symbols.GetAddMatchingEvents(methodX), "Count")))
                        .ApplyTri(DECLARE_EVENTS_SHIFTED, methodX, symbols);
                    var foreachX = methodX.Block.ForEach(
                        typeof(EventBean),
                        "@event",
                        symbols.GetAddMatchingEvents(methodX));
                    {
                        foreachX.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"))
                            .DeclareVar<IDictionary<string, object>>(
                                "row",
                                LocalMethod(
                                    subselect.EvaluateRowCodegen(methodX, classScope),
                                    REF_EVENTS_SHIFTED,
                                    ConstantTrue(),
                                    symbols.GetAddExprEvalCtx(methodX)))
                            .DeclareVar<EventBean>(
                                "rowEvent",
                                ExprDotMethod(eventBeanSvc, "AdapterForTypedMap", Ref("row"), fieldEventType))
                            .ExprDotMethod(Ref("result"), "Add", Ref("rowEvent"));
                    }
                    methodX.Block.MethodReturn(FlexWrap(Ref("result")));
                    return LocalMethod(methodX);
                }
            }

            if (subselect.SelectClause != null) {
                return ConstantNull();
            }

            // handle filtered
            var methodY = parent.MakeChild(typeof(FlexCollection), this.GetType(), classScope);

            methodY.Block.ApplyTri(DECLARE_EVENTS_SHIFTED, methodY, symbols);

            methodY.Block.DeclareVar<ArrayDeque<EventBean>>("filtered", ConstantNull());
            var foreachY = methodY.Block.ForEach(
                typeof(EventBean),
                "@event",
                symbols.GetAddMatchingEvents(methodY));
            {
                foreachY.AssignArrayElement(REF_EVENTS_SHIFTED, Constant(0), Ref("@event"));
                var filter = CodegenLegoMethodExpression.CodegenExpression(subselect.FilterExpr, methodY, classScope, true);
                CodegenLegoBooleanExpression.CodegenContinueIfNullOrNotPass(
                    foreachY,
                    typeof(bool?),
                    LocalMethod(
                        filter,
                        REF_EVENTS_SHIFTED,
                        symbols.GetAddIsNewData(methodY),
                        symbols.GetAddExprEvalCtx(methodY)));
                foreachY.IfCondition(EqualsNull(Ref("filtered")))
                    .AssignRef("filtered", NewInstance(typeof(ArrayDeque<EventBean>)))
                    .BlockEnd()
                    .ExprDotMethod(Ref("filtered"), "Add", Ref("@event"));
            }

            methodY.Block.MethodReturn(FlexWrap(Ref("filtered")));
            return LocalMethod(methodY);
        }
Example #30
0
        protected internal static CodegenMethod CreateSortPropertiesCodegen(
            OrderByProcessorForgeImpl forge,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            Consumer<CodegenMethod> code = method => {
                string[] expressions = null;
                bool[] descending = null;
                if (classScope.IsInstrumented) {
                    expressions = forge.ExpressionTexts;
                    descending = forge.DescendingFlags;
                }

                method.Block.DeclareVar<object[]>(
                    "sortProperties",
                    NewArrayByLength(typeof(object), ArrayLength(REF_GENERATINGEVENTS)));

                var elements = forge.OrderBy;
                var forEach = method.Block.DeclareVar<int>("count", Constant(0))
                    .ForEach(typeof(EventBean[]), "eventsPerStream", REF_GENERATINGEVENTS);

                if (forge.IsNeedsGroupByKeys) {
                    forEach.ExprDotMethod(
                        MEMBER_AGGREGATIONSVC,
                        "SetCurrentAccess",
                        ArrayAtIndex(Ref("groupByKeys"), Ref("count")),
                        ExprDotName(REF_EXPREVALCONTEXT, "AgentInstanceId"),
                        ConstantNull());
                }

                forEach.Apply(
                    Instblock(
                        classScope,
                        "qOrderBy",
                        Ref("eventsPerStream"),
                        Constant(expressions),
                        Constant(descending)));
                if (elements.Length == 1) {
                    forEach.AssignArrayElement(
                        "sortProperties",
                        Ref("count"),
                        LocalMethod(
                            CodegenLegoMethodExpression.CodegenExpression(
                                elements[0].ExprNode.Forge,
                                method,
                                classScope,
                                true),
                            Ref("eventsPerStream"),
                            REF_ISNEWDATA,
                            REF_EXPREVALCONTEXT));
                }
                else {
                    forEach.DeclareVar<object[]>(
                        "values",
                        NewArrayByLength(typeof(object), Constant(forge.OrderBy.Length)));
                    for (var i = 0; i < forge.OrderBy.Length; i++) {
                        forEach.AssignArrayElement(
                            "values",
                            Constant(i),
                            LocalMethod(
                                CodegenLegoMethodExpression.CodegenExpression(
                                    elements[i].ExprNode.Forge,
                                    method,
                                    classScope,
                                    true),
                                Ref("eventsPerStream"),
                                REF_ISNEWDATA,
                                REF_EXPREVALCONTEXT));
                    }

                    forEach.AssignArrayElement(
                        "sortProperties",
                        Ref("count"),
                        NewInstance<HashableMultiKey>(Ref("values")));
                }

                forEach.Apply(Instblock(classScope, "aOrderBy", Ref("sortProperties")))
                    .IncrementRef("count");
                method.Block.MethodReturn(StaticMethod(typeof(CompatExtensions), "AsList", Ref("sortProperties")));
            };
            return namedMethods.AddMethod(
                typeof(IList<object>),
                "CreateSortProperties",
                CodegenNamedParam.From(
                    typeof(EventBean[][]), REF_GENERATINGEVENTS.Ref,
                    typeof(object[]), "groupByKeys",
                    typeof(bool), REF_ISNEWDATA.Ref,
                    typeof(ExprEvaluatorContext), REF_EXPREVALCONTEXT.Ref,
                    typeof(AggregationService), MEMBER_AGGREGATIONSVC.Ref),
                typeof(OrderByProcessorImpl),
                classScope,
                code);
        }