Exemplo n.º 1
0
        public static EventPropertyGetter Compile(
            this ICodegenContext codegenContext,
            string engineURI,
            ClassLoaderProvider classLoaderProvider,
            EventPropertyGetterSPI getterSPI,
            string propertyExpression)
        {
            var get      = getterSPI.CodegenEventBeanGet(Ref("bean"), codegenContext);
            var exists   = getterSPI.CodegenEventBeanExists(Ref("bean"), codegenContext);
            var fragment = getterSPI.CodegenEventBeanFragment(Ref("bean"), codegenContext);

            var singleBeanParam = CodegenNamedParam.From(typeof(EventBean), "bean");

            // For: public object Get(EventBean eventBean) ;
            // For: public bool IsExistsProperty(EventBean eventBean);
            // For: public object GetFragment(EventBean eventBean) ;
            var getMethod = new CodegenMethod(typeof(object), "Get", singleBeanParam, null);

            getMethod.Statements.MethodReturn(get);
            var isExistsPropertyMethod = new CodegenMethod(typeof(bool), "IsExistsProperty", singleBeanParam, null);

            isExistsPropertyMethod.Statements.MethodReturn(exists);
            var fragmentMethod = new CodegenMethod(typeof(object), "GetFragment", singleBeanParam, null);

            fragmentMethod.Statements.MethodReturn(fragment);

            var clazz = new CodegenClass(
                "com.espertech.esper.codegen.uri_" + engineURI,
                typeof(EventPropertyGetter).Name + "_" + CodeGenerationIDGenerator.GenerateClass(),
                typeof(EventPropertyGetter),
                codegenContext.Members,
                new [] { getMethod, isExistsPropertyMethod, fragmentMethod },
                codegenContext.Methods
                );

            string debugInfo = null;

            if (codegenContext.IsDebugEnabled)
            {
                debugInfo = getterSPI.GetType().FullName + " for property '" + propertyExpression + "'";
            }

            return(codegenContext.Compiler.Compile(
                       clazz, classLoaderProvider, typeof(EventPropertyGetter), debugInfo));
        }
        protected internal static CodegenMethod GetSelectListEventsAsArrayCodegen(
            ResultSetProcessorRowForAllForge forge,
            CodegenClassScope classScope,
            CodegenInstanceAux instance)
        {
            Consumer<CodegenMethod> code = method => {
                if (forge.OptionalHavingNode != null) {
                    method.Block.IfCondition(
                            Not(
                                LocalMethod(
                                    instance.Methods.GetMethod("EvaluateHavingClause"),
                                    ConstantNull(),
                                    REF_ISNEWDATA,
                                    MEMBER_AGENTINSTANCECONTEXT)))
                        .BlockReturn(ConstantNull());
                }

                method.Block.DeclareVar<EventBean>(
                        "theEvent",
                        ExprDotMethod(
                            MEMBER_SELECTEXPRPROCESSOR,
                            "Process",
                            EnumValue(typeof(CollectionUtil), "EVENTBEANARRAY_EMPTY"),
                            REF_ISNEWDATA,
                            REF_ISSYNTHESIZE,
                            MEMBER_AGENTINSTANCECONTEXT))
                    .DeclareVar<EventBean[]>("result", NewArrayByLength(typeof(EventBean), Constant(1)))
                    .AssignArrayElement("result", Constant(0), Ref("theEvent"))
                    .MethodReturn(Ref("result"));
            };
            return instance.Methods.AddMethod(
                typeof(EventBean[]),
                "GetSelectListEventsAsArray",
                CodegenNamedParam.From(
                    typeof(bool), NAME_ISNEWDATA,
                    typeof(bool), NAME_ISSYNTHESIZE,
                    typeof(bool), "join"),
                typeof(ResultSetProcessorRowForAllImpl),
                classScope,
                code);
        }
Exemplo n.º 3
0
 public static void RowCtorCodegen(
     CodegenNamedMethods namedMethods,
     CodegenClassScope classScope,
     IList<CodegenTypedParam> rowMembers)
 {
     rowMembers.Add(new CodegenTypedParam(typeof(long), "lastUpdateTime"));
     namedMethods.AddMethod(
         typeof(void),
         "SetLastUpdateTime",
         CodegenNamedParam.From(typeof(long), "time"),
         typeof(AggSvcGroupByReclaimAgedImpl),
         classScope,
         method => method.Block.AssignRef("lastUpdateTime", Ref("time")));
     namedMethods.AddMethod(
         typeof(long),
         "GetLastUpdateTime",
         Collections.GetEmptyList<CodegenNamedParam>(),
         typeof(AggSvcGroupByReclaimAgedImpl),
         classScope,
         method => method.Block.MethodReturn(Ref("lastUpdateTime")));
 }
Exemplo n.º 4
0
 protected internal static CodegenMethod SortWGroupKeysInternalCodegen(
     OrderByProcessorForgeImpl forge,
     CodegenClassScope classScope,
     CodegenNamedMethods namedMethods)
 {
     var createSortProperties = CreateSortPropertiesCodegen(forge, classScope, namedMethods);
     CodegenExpression comparator = classScope.AddOrGetDefaultFieldSharable(forge.IComparer);
     Consumer<CodegenMethod> code = method => {
         method.Block.DeclareVar<IList<object>>(
                 "sortValuesMultiKeys",
                 LocalMethod(
                     createSortProperties,
                     REF_GENERATINGEVENTS,
                     Ref("groupByKeys"),
                     REF_ISNEWDATA,
                     REF_EXPREVALCONTEXT,
                     MEMBER_AGGREGATIONSVC))
             .MethodReturn(
                 StaticMethod(
                     typeof(OrderByProcessorUtil),
                     "SortGivenOutgoingAndSortKeys",
                     REF_OUTGOINGEVENTS,
                     Ref("sortValuesMultiKeys"),
                     comparator));
     };
     return namedMethods.AddMethod(
         typeof(EventBean[]),
         "SortWGroupKeysInternal",
         CodegenNamedParam.From(
             typeof(EventBean[]), REF_OUTGOINGEVENTS.Ref,
             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);
 }
 public static CodegenMethod GenerateGroupKeyArrayViewCodegen(
     CodegenMethod generateGroupKeySingle,
     CodegenClassScope classScope,
     CodegenInstanceAux instance)
 {
     Consumer<CodegenMethod> code = method => {
         method.Block.IfRefNullReturnNull("events")
             .DeclareVar<EventBean[]>(
                 "eventsPerStream",
                 NewArrayByLength(typeof(EventBean), Constant(1)))
             .DeclareVar<object[]>("keys", NewArrayByLength(typeof(object), ArrayLength(Ref("events"))));
         {
             var forLoop = method.Block.ForLoopIntSimple("i", ArrayLength(Ref("events")));
             forLoop.AssignArrayElement("eventsPerStream", Constant(0), ArrayAtIndex(Ref("events"), Ref("i")))
                 .AssignArrayElement(
                     "keys",
                     Ref("i"),
                     LocalMethod(
                         generateGroupKeySingle,
                         Ref("eventsPerStream"),
                         ExprForgeCodegenNames.REF_ISNEWDATA));
         }
         method.Block.MethodReturn(Ref("keys"));
     };
     return instance.Methods.AddMethod(
         typeof(object[]),
         "GenerateGroupKeyArrayView",
         CodegenNamedParam.From(
             typeof(EventBean[]),
             "events",
             typeof(bool),
             ResultSetProcessorCodegenNames.NAME_ISNEWDATA),
         typeof(ResultSetProcessorRowPerGroup),
         classScope,
         code);
 }
        public static void GenerateIncidentals(
            bool hasRefcount,
            bool hasLastUpdTime,
            AggregationRowCtorDesc rowCtorDesc)
        {
            var namedMethods = rowCtorDesc.NamedMethods;
            var classScope = rowCtorDesc.ClassScope;
            IList<CodegenTypedParam> rowMembers = rowCtorDesc.RowMembers;

            if (hasRefcount) {
                rowMembers.Add(new CodegenTypedParam(typeof(int), "refcount").WithFinal(false));
            }

            namedMethods.AddMethod(
                typeof(void),
                "IncreaseRefcount",
                NIL_NAMED_PARAM,
                typeof(AggregationServiceCodegenUtil),
                classScope,
                hasRefcount ? method => method.Block.Increment(Ref("refcount")) : NIL_METHOD_CONSUMER);
            namedMethods.AddMethod(
                typeof(void),
                "DecreaseRefcount",
                NIL_NAMED_PARAM,
                typeof(AggregationServiceCodegenUtil),
                classScope,
                hasRefcount ? method => method.Block.Decrement(Ref("refcount")) : NIL_METHOD_CONSUMER);
            namedMethods.AddMethod(
                typeof(long),
                "GetRefcount",
                NIL_NAMED_PARAM,
                typeof(AggregationServiceCodegenUtil),
                classScope,
                hasRefcount
                    ? new Consumer<CodegenMethod>(method => method.Block.MethodReturn(Ref("refcount")))
                    : new Consumer<CodegenMethod>(method => method.Block.MethodReturn(Constant(1))));

            if (hasLastUpdTime) {
                rowMembers.Add(new CodegenTypedParam(typeof(long), "lastUpd").WithFinal(false));
            }

            namedMethods.AddMethod(
                typeof(void),
                "SetLastUpdateTime",
                CodegenNamedParam.From(typeof(long), "time"),
                typeof(AggregationServiceCodegenUtil),
                classScope,
                hasLastUpdTime
                    ? new Consumer<CodegenMethod>(method => method.Block.AssignRef("lastUpd", Ref("time")))
                    : new Consumer<CodegenMethod>(method => method.Block.MethodThrowUnsupported()));

            namedMethods.AddMethod(
                typeof(long),
                "GetLastUpdateTime",
                NIL_NAMED_PARAM,
                typeof(AggregationServiceCodegenUtil),
                classScope,
                hasLastUpdTime
                    ? new Consumer<CodegenMethod>(method => method.Block.MethodReturn(Ref("lastUpd")))
                    : new Consumer<CodegenMethod>(method => method.Block.MethodThrowUnsupported()));
        }
        protected internal static CodegenMethod ProcessViewResultNewDepthOneUnboundCodegen(
            ResultSetProcessorRowPerGroupForge forge,
            CodegenClassScope classScope,
            CodegenInstanceAux instance)
        {
            CodegenMethod shortcutEvalGivenKey =
                ResultSetProcessorRowPerGroupImpl.ShortcutEvalGivenKeyCodegen(
                    forge.OptionalHavingNode,
                    classScope,
                    instance);

            Consumer<CodegenMethod> code = methodNode => {
                methodNode.Block.DeclareVar<object>(
                    "groupKey",
                    LocalMethod(forge.GenerateGroupKeySingle, REF_NEWDATA, ConstantTrue()));
                if (forge.IsSelectRStream) {
                    methodNode.Block.DeclareVar<EventBean>(
                        "rstream",
                        LocalMethod(
                            shortcutEvalGivenKey,
                            REF_NEWDATA,
                            Ref("groupKey"),
                            ConstantFalse(),
                            REF_ISSYNTHESIZE));
                }

                methodNode.Block.ExprDotMethod(
                        MEMBER_AGGREGATIONSVC,
                        "ApplyEnter",
                        REF_NEWDATA,
                        Ref("groupKey"),
                        MEMBER_AGENTINSTANCECONTEXT)
                    .ExprDotMethod(Ref("groupReps"), "Put", Ref("groupKey"), ArrayAtIndex(REF_NEWDATA, Constant(0)))
                    .DeclareVar<EventBean>(
                        "istream",
                        LocalMethod(
                            shortcutEvalGivenKey,
                            REF_NEWDATA,
                            Ref("groupKey"),
                            ConstantTrue(),
                            REF_ISSYNTHESIZE));
                if (forge.IsSelectRStream) {
                    methodNode.Block.MethodReturn(
                        StaticMethod(
                            typeof(ResultSetProcessorUtil),
                            "ToPairNullIfAllNullSingle",
                            Ref("istream"),
                            Ref("rstream")));
                }
                else {
                    methodNode.Block.MethodReturn(
                        StaticMethod(typeof(ResultSetProcessorUtil), "ToPairNullIfNullIStream", Ref("istream")));
                }
            };

            return instance.Methods.AddMethod(
                typeof(UniformPair<EventBean[]>),
                "ProcessViewResultNewDepthOneUnboundCodegen",
                CodegenNamedParam.From(typeof(EventBean[]), NAME_NEWDATA, typeof(bool), NAME_ISSYNTHESIZE),
                typeof(ResultSetProcessorRowPerGroupImpl),
                classScope,
                code);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }