예제 #1
0
        public static AggregationLocalGroupByPlanForge Analyze(
            ExprForge[][] methodForges,
            AggregationForgeFactory[] methodFactories,
            AggregationStateFactoryForge[] accessAggregations,
            AggregationGroupByLocalGroupDesc localGroupDesc,
            ExprNode[] groupByExpressions,
            AggregationAccessorSlotPairForge[] accessors,
            ImportService importService,
            bool fireAndForget,
            string statementName)
        {
            if (groupByExpressions == null) {
                groupByExpressions = ExprNodeUtilityQuery.EMPTY_EXPR_ARRAY;
            }

            var columns = new AggregationLocalGroupByColumnForge[localGroupDesc.NumColumns];
            IList<AggregationLocalGroupByLevelForge> levelsList = new List<AggregationLocalGroupByLevelForge>();
            AggregationLocalGroupByLevelForge optionalTopLevel = null;

            // determine optional top level (level number is -1)
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    optionalTopLevel = GetLevel(
                        -1,
                        levelDesc,
                        methodForges,
                        methodFactories,
                        accessAggregations,
                        columns,
                        groupByExpressions.Length == 0,
                        accessors,
                        importService,
                        fireAndForget,
                        statementName);
                }
            }

            // determine default (same as group-by) level, if any, assign level number 0
            var levelNumber = 0;
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    continue;
                }

                var isDefaultLevel = groupByExpressions != null &&
                                     ExprNodeUtilityCompare.DeepEqualsIgnoreDupAndOrder(
                                         groupByExpressions,
                                         levelDesc.PartitionExpr);
                if (isDefaultLevel) {
                    var level = GetLevel(
                        0,
                        levelDesc,
                        methodForges,
                        methodFactories,
                        accessAggregations,
                        columns,
                        isDefaultLevel,
                        accessors,
                        importService,
                        fireAndForget,
                        statementName);
                    levelsList.Add(level);
                    levelNumber++;
                    break;
                }
            }

            // determine all other levels, assign level numbers
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    continue;
                }

                var isDefaultLevel = groupByExpressions != null &&
                                     ExprNodeUtilityCompare.DeepEqualsIgnoreDupAndOrder(
                                         groupByExpressions,
                                         levelDesc.PartitionExpr);
                if (isDefaultLevel) {
                    continue;
                }

                var level = GetLevel(
                    levelNumber,
                    levelDesc,
                    methodForges,
                    methodFactories,
                    accessAggregations,
                    columns,
                    isDefaultLevel,
                    accessors,
                    importService,
                    fireAndForget,
                    statementName);
                levelsList.Add(level);
                levelNumber++;
            }

            // totals
            var numMethods = 0;
            var numAccesses = 0;
            if (optionalTopLevel != null) {
                numMethods += optionalTopLevel.MethodFactories.Length;
                numAccesses += optionalTopLevel.AccessStateForges.Length;
            }

            foreach (var level in levelsList) {
                numMethods += level.MethodFactories.Length;
                numAccesses += level.AccessStateForges.Length;
            }

            AggregationLocalGroupByLevelForge[] levels = levelsList.ToArray();
            return new AggregationLocalGroupByPlanForge(numMethods, numAccesses, columns, optionalTopLevel, levels);
        }
        public static AggregationLocalGroupByPlanDesc Analyze(
            ExprForge[][] methodForges,
            AggregationForgeFactory[] methodFactories,
            AggregationStateFactoryForge[] accessAggregations,
            AggregationGroupByLocalGroupDesc localGroupDesc,
            ExprNode[] groupByExpressions,
            MultiKeyClassRef groupByMultiKey,
            AggregationAccessorSlotPairForge[] accessors,
            StatementRawInfo raw,
            SerdeCompileTimeResolver serdeResolver)
        {
            if (groupByExpressions == null) {
                groupByExpressions = ExprNodeUtilityQuery.EMPTY_EXPR_ARRAY;
            }

            var columns = new AggregationLocalGroupByColumnForge[localGroupDesc.NumColumns];
            var levelsList = new List<AggregationLocalGroupByLevelForge>();
            AggregationLocalGroupByLevelForge optionalTopLevel = null;
            var additionalForgeables = new List<StmtClassForgeableFactory>();

            // determine optional top level (level number is -1)
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    AggregationGroupByLocalGroupLevelDesc top = GetLevel(
                        -1,
                        levelDesc,
                        methodForges,
                        methodFactories,
                        accessAggregations,
                        columns,
                        groupByExpressions.Length == 0,
                        accessors,
                        groupByExpressions,
                        groupByMultiKey,
                        raw,
                        serdeResolver);
                    optionalTopLevel = top.Forge;
                    additionalForgeables.AddRange(top.AdditionalForgeables);
                }
            }

            // determine default (same as group-by) level, if any, assign level number 0
            var levelNumber = 0;
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    continue;
                }

                var isDefaultLevel = groupByExpressions != null &&
                                     ExprNodeUtilityCompare.DeepEqualsIgnoreDupAndOrder(
                                         groupByExpressions,
                                         levelDesc.PartitionExpr);

                if (isDefaultLevel) {
                    AggregationGroupByLocalGroupLevelDesc level = GetLevel(
                        0,
                        levelDesc,
                        methodForges,
                        methodFactories,
                        accessAggregations,
                        columns,
                        isDefaultLevel,
                        accessors,
                        groupByExpressions,
                        groupByMultiKey,
                        raw,
                        serdeResolver);
                    additionalForgeables.AddRange(level.AdditionalForgeables);
                    levelsList.Add(level.Forge);
                    levelNumber++;
                    break;
                }
            }

            // determine all other levels, assign level numbers
            for (var i = 0; i < localGroupDesc.Levels.Length; i++) {
                var levelDesc = localGroupDesc.Levels[i];
                if (levelDesc.PartitionExpr.Length == 0) {
                    continue;
                }

                var isDefaultLevel = groupByExpressions != null &&
                                     ExprNodeUtilityCompare.DeepEqualsIgnoreDupAndOrder(
                                         groupByExpressions,
                                         levelDesc.PartitionExpr);
                if (isDefaultLevel) {
                    continue;
                }

                AggregationGroupByLocalGroupLevelDesc level = GetLevel(
                    levelNumber,
                    levelDesc,
                    methodForges,
                    methodFactories,
                    accessAggregations,
                    columns,
                    isDefaultLevel,
                    accessors,
                    groupByExpressions,
                    groupByMultiKey,
                    raw,
                    serdeResolver);
                levelsList.Add(level.Forge);
                additionalForgeables.AddRange(level.AdditionalForgeables);
                levelNumber++;
            }

            // totals
            var numMethods = 0;
            var numAccesses = 0;
            if (optionalTopLevel != null) {
                numMethods += optionalTopLevel.MethodFactories.Length;
                numAccesses += optionalTopLevel.AccessStateForges.Length;
            }

            foreach (var level in levelsList) {
                numMethods += level.MethodFactories.Length;
                numAccesses += level.AccessStateForges.Length;
            }

            AggregationLocalGroupByLevelForge[] levels = levelsList.ToArray();
            AggregationLocalGroupByPlanForge forge = new AggregationLocalGroupByPlanForge(numMethods, numAccesses, columns, optionalTopLevel, levels);
            return new AggregationLocalGroupByPlanDesc(forge, additionalForgeables);
        }