Esempio n. 1
0
        private static CodegenMethod GetComparableWMultiKeyCodegen(
            ExprNode[] criteria,
            CodegenExpressionRef @ref,
            CodegenNamedMethods namedMethods,
            CodegenClassScope classScope)
        {
            var methodName = "GetComparable_" + @ref.Ref;
            Consumer<CodegenMethod> code = method => {
                if (criteria.Length == 1) {
                    method.Block.MethodReturn(
                        LocalMethod(
                            CodegenLegoMethodExpression.CodegenExpression(
                                criteria[0].Forge,
                                method,
                                classScope,
                                true),
                            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(NewInstance<HashableMultiKey>(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);
        }
Esempio n. 2
0
        protected internal static CodegenMethod CreateSortPropertiesWRollupCodegen(
            OrderByProcessorForgeImpl forge,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            Consumer<CodegenMethod> code = method => {
                method.Block.DeclareVar<object[]>(
                        "sortProperties",
                        NewArrayByLength(typeof(object), ExprDotName(REF_ORDERCURRENTGENERATORS, "Count")))
                    .DeclareVar<int>("count", Constant(0));

                var forEach = method.Block.ForEach(typeof(GroupByRollupKey), "rollup", REF_ORDERCURRENTGENERATORS);

                if (forge.IsNeedsGroupByKeys) {
                    forEach.ExprDotMethod(
                        MEMBER_AGGREGATIONSVC,
                        "SetCurrentAccess",
                        ExprDotName(Ref("rollup"), "GroupKey"),
                        ExprDotName(REF_EXPREVALCONTEXT, "AgentInstanceId"),
                        ExprDotName(Ref("rollup"), "Level"));
                }

                forEach.DeclareVar<int>(
                    "num",
                    ExprDotMethodChain(Ref("rollup")).Get("Level").Get("LevelNumber"));
                var blocks = forEach.SwitchBlockOfLength(Ref("num"), forge.OrderByRollup.Length, false);
                for (var i = 0; i < blocks.Length; i++) {
                    var getSortKey = GenerateOrderKeyCodegen(
                        "GetSortKeyInternal_" + i,
                        forge.OrderByRollup[i],
                        classScope,
                        namedMethods);
                    blocks[i]
                        .AssignArrayElement(
                            "sortProperties",
                            Ref("count"),
                            LocalMethod(
                                getSortKey,
                                ExprDotName(Ref("rollup"), "Generator"),
                                REF_ISNEWDATA,
                                REF_EXPREVALCONTEXT));
                }

                forEach.IncrementRef("count");
                method.Block.MethodReturn(StaticMethod(typeof(CompatExtensions), "AsList", Ref("sortProperties")));
            };
            return namedMethods.AddMethod(
                typeof(IList<object>),
                "CreateSortPropertiesWRollup",
                CodegenNamedParam.From(
                    typeof(IList<GroupByRollupKey>), REF_ORDERCURRENTGENERATORS.Ref,
                    typeof(bool), REF_ISNEWDATA.Ref,
                    typeof(ExprEvaluatorContext), REF_EXPREVALCONTEXT.Ref,
                    typeof(AggregationService), MEMBER_AGGREGATIONSVC.Ref),
                typeof(OrderByProcessorImpl),
                classScope,
                code);
        }
Esempio n. 3
0
        protected internal static CodegenMethod GenerateOrderKeyCodegen(
            string methodName,
            OrderByElementForge[] orderBy,
            CodegenClassScope classScope,
            CodegenNamedMethods namedMethods)
        {
            Consumer<CodegenMethod> code = methodNode => {
                if (orderBy.Length == 1) {
                    var expression = CodegenLegoMethodExpression.CodegenExpression(
                        orderBy[0].ExprNode.Forge,
                        methodNode,
                        classScope,
                        true);
                    methodNode.Block.MethodReturn(
                        LocalMethod(
                            expression,
                            EnumForgeCodegenNames.REF_EPS,
                            ResultSetProcessorCodegenNames.REF_ISNEWDATA,
                            REF_EXPREVALCONTEXT));
                    return;
                }

                methodNode.Block.DeclareVar<object[]>(
                    "keys",
                    NewArrayByLength(typeof(object), Constant(orderBy.Length)));
                for (var i = 0; i < orderBy.Length; i++) {
                    var expression = CodegenLegoMethodExpression.CodegenExpression(
                        orderBy[i].ExprNode.Forge,
                        methodNode,
                        classScope,
                        true);
                    methodNode.Block.AssignArrayElement(
                        "keys",
                        Constant(i),
                        LocalMethod(
                            expression,
                            EnumForgeCodegenNames.REF_EPS,
                            ResultSetProcessorCodegenNames.REF_ISNEWDATA,
                            REF_EXPREVALCONTEXT));
                }

                methodNode.Block.MethodReturn(NewInstance<HashableMultiKey>(Ref("keys")));
            };

            return namedMethods.AddMethod(
                typeof(object),
                methodName,
                CodegenNamedParam.From(
                    typeof(EventBean[]), NAME_EPS,
                    typeof(bool), NAME_ISNEWDATA,
                    typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT),
                typeof(ResultSetProcessorUtil),
                classScope,
                code);
        }
Esempio n. 4
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")));
 }
Esempio n. 5
0
 private CodegenMethod InitArrayCodegen(
     CodegenNamedMethods namedMethods,
     CodegenClassScope classScope)
 {
     Consumer<CodegenMethod> code = method => {
         method.Block
             .DeclareVar<ICollection<EventBean>>("events", ExprDotName(refSet, "Keys"))
             .AssignRef(array, StaticMethod(typeof(CollectionUtil), METHOD_TOARRAYEVENTS, Ref("events")));
     };
     return namedMethods.AddMethod(
         typeof(void),
         "InitArray_" + array.Ref,
         Collections.GetEmptyList<CodegenNamedParam>(),
         typeof(AggregatorAccessLinearJoin),
         classScope,
         code);
 }
Esempio n. 6
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);
 }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }