@Test public void generateMandatoryCuboidSetTest() { Map<Long, Long> srcCuboidSet = CuboidStatsUtil.generateSourceCuboidStats(simulateCount(), simulateHitProbability(baseCuboidId), simulateRollingUpCount()); Assert.assertTrue(srcCuboidSet.get(239L) == 200L); Assert.assertTrue(srcCuboidSet.get(187L) == 1000L); Assert.assertTrue(srcCuboidSet.get(178L) == 800L); Assert.assertTrue(!srcCuboidSet.containsKey(0L)); }
public static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics, Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap) { Map<Long, Long> srcCuboidsStats = Maps.newHashMap(); if (cuboidHitProbabilityMap == null || cuboidHitProbabilityMap.isEmpty() || rollingUpSourceMap == null || rollingUpSourceMap.isEmpty()) { return srcCuboidsStats; } for (Long cuboid : cuboidHitProbabilityMap.keySet()) { if (statistics.get(cuboid) != null) { continue; } Map<Long, Pair<Long, Long>> innerRollingUpTargetMap = rollingUpSourceMap.get(cuboid); if (innerRollingUpTargetMap == null || innerRollingUpTargetMap.isEmpty()) { continue; } long totalEstRowCount = 0L; int nEffective = 0; boolean ifHasStats = false; for (Long tgtCuboid : innerRollingUpTargetMap.keySet()) { Pair<Long, Long> rollingupStats = innerRollingUpTargetMap.get(tgtCuboid); if (statistics.get(tgtCuboid) != null) { if (!ifHasStats) { totalEstRowCount = 0L; nEffective = 0; ifHasStats = true; } double rollupRatio = calculateRollupRatio(rollingupStats); totalEstRowCount += (1 - rollupRatio) * statistics.get(tgtCuboid); nEffective++; } else { if (ifHasStats) { continue; } totalEstRowCount += rollingupStats.getSecond(); nEffective++; } } if (nEffective != 0) srcCuboidsStats.put(cuboid, totalEstRowCount / nEffective); else throw new ArithmeticException("/ by zero"); } srcCuboidsStats.remove(0L); adjustCuboidStats(srcCuboidsStats, statistics); return srcCuboidsStats; }
CuboidStatsUtil { public static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics, Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap) { Map<Long, Long> srcCuboidsStats = Maps.newHashMap(); if (cuboidHitProbabilityMap == null || cuboidHitProbabilityMap.isEmpty() || rollingUpSourceMap == null || rollingUpSourceMap.isEmpty()) { return srcCuboidsStats; } for (Long cuboid : cuboidHitProbabilityMap.keySet()) { if (statistics.get(cuboid) != null) { continue; } Map<Long, Pair<Long, Long>> innerRollingUpTargetMap = rollingUpSourceMap.get(cuboid); if (innerRollingUpTargetMap == null || innerRollingUpTargetMap.isEmpty()) { continue; } long totalEstRowCount = 0L; int nEffective = 0; boolean ifHasStats = false; for (Long tgtCuboid : innerRollingUpTargetMap.keySet()) { Pair<Long, Long> rollingupStats = innerRollingUpTargetMap.get(tgtCuboid); if (statistics.get(tgtCuboid) != null) { if (!ifHasStats) { totalEstRowCount = 0L; nEffective = 0; ifHasStats = true; } double rollupRatio = calculateRollupRatio(rollingupStats); totalEstRowCount += (1 - rollupRatio) * statistics.get(tgtCuboid); nEffective++; } else { if (ifHasStats) { continue; } totalEstRowCount += rollingupStats.getSecond(); nEffective++; } } if (nEffective != 0) srcCuboidsStats.put(cuboid, totalEstRowCount / nEffective); else throw new ArithmeticException("/ by zero"); } srcCuboidsStats.remove(0L); adjustCuboidStats(srcCuboidsStats, statistics); return srcCuboidsStats; } }
CuboidStatsUtil { public static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics, Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap) { Map<Long, Long> srcCuboidsStats = Maps.newHashMap(); if (cuboidHitProbabilityMap == null || cuboidHitProbabilityMap.isEmpty() || rollingUpSourceMap == null || rollingUpSourceMap.isEmpty()) { return srcCuboidsStats; } for (Long cuboid : cuboidHitProbabilityMap.keySet()) { if (statistics.get(cuboid) != null) { continue; } Map<Long, Pair<Long, Long>> innerRollingUpTargetMap = rollingUpSourceMap.get(cuboid); if (innerRollingUpTargetMap == null || innerRollingUpTargetMap.isEmpty()) { continue; } long totalEstRowCount = 0L; int nEffective = 0; boolean ifHasStats = false; for (Long tgtCuboid : innerRollingUpTargetMap.keySet()) { Pair<Long, Long> rollingupStats = innerRollingUpTargetMap.get(tgtCuboid); if (statistics.get(tgtCuboid) != null) { if (!ifHasStats) { totalEstRowCount = 0L; nEffective = 0; ifHasStats = true; } double rollupRatio = calculateRollupRatio(rollingupStats); totalEstRowCount += (1 - rollupRatio) * statistics.get(tgtCuboid); nEffective++; } else { if (ifHasStats) { continue; } totalEstRowCount += rollingupStats.getSecond(); nEffective++; } } if (nEffective != 0) srcCuboidsStats.put(cuboid, totalEstRowCount / nEffective); else throw new ArithmeticException("/ by zero"); } srcCuboidsStats.remove(0L); adjustCuboidStats(srcCuboidsStats, statistics); return srcCuboidsStats; } private  CuboidStatsUtil(); }
CuboidStatsUtil { public static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics, Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap) { Map<Long, Long> srcCuboidsStats = Maps.newHashMap(); if (cuboidHitProbabilityMap == null || cuboidHitProbabilityMap.isEmpty() || rollingUpSourceMap == null || rollingUpSourceMap.isEmpty()) { return srcCuboidsStats; } for (Long cuboid : cuboidHitProbabilityMap.keySet()) { if (statistics.get(cuboid) != null) { continue; } Map<Long, Pair<Long, Long>> innerRollingUpTargetMap = rollingUpSourceMap.get(cuboid); if (innerRollingUpTargetMap == null || innerRollingUpTargetMap.isEmpty()) { continue; } long totalEstRowCount = 0L; int nEffective = 0; boolean ifHasStats = false; for (Long tgtCuboid : innerRollingUpTargetMap.keySet()) { Pair<Long, Long> rollingupStats = innerRollingUpTargetMap.get(tgtCuboid); if (statistics.get(tgtCuboid) != null) { if (!ifHasStats) { totalEstRowCount = 0L; nEffective = 0; ifHasStats = true; } double rollupRatio = calculateRollupRatio(rollingupStats); totalEstRowCount += (1 - rollupRatio) * statistics.get(tgtCuboid); nEffective++; } else { if (ifHasStats) { continue; } totalEstRowCount += rollingupStats.getSecond(); nEffective++; } } if (nEffective != 0) srcCuboidsStats.put(cuboid, totalEstRowCount / nEffective); else throw new ArithmeticException("/ by zero"); } srcCuboidsStats.remove(0L); adjustCuboidStats(srcCuboidsStats, statistics); return srcCuboidsStats; } private  CuboidStatsUtil(); static Map<Long, Double> calculateCuboidHitProbability(Set<Long> selectionCuboidSet,
            Map<Long, Long> hitFrequencyMap, long nTotalCuboids, double queryUncertaintyRatio); static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics,
            Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap); static Map<Long, Long> complementRowCountForCuboids(final Map<Long, Long> statistics, Set<Long> cuboids); static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics); static void adjustCuboidStats(Map<Long, Long> mandatoryCuboidsWithStats, Map<Long, Long> statistics); static Map<Long, List<Long>> createDirectChildrenCache(final Set<Long> cuboidSet); static boolean isDescendant(long cuboidToCheck, long parentCuboid); }
CuboidStatsUtil { public static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics, Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap) { Map<Long, Long> srcCuboidsStats = Maps.newHashMap(); if (cuboidHitProbabilityMap == null || cuboidHitProbabilityMap.isEmpty() || rollingUpSourceMap == null || rollingUpSourceMap.isEmpty()) { return srcCuboidsStats; } for (Long cuboid : cuboidHitProbabilityMap.keySet()) { if (statistics.get(cuboid) != null) { continue; } Map<Long, Pair<Long, Long>> innerRollingUpTargetMap = rollingUpSourceMap.get(cuboid); if (innerRollingUpTargetMap == null || innerRollingUpTargetMap.isEmpty()) { continue; } long totalEstRowCount = 0L; int nEffective = 0; boolean ifHasStats = false; for (Long tgtCuboid : innerRollingUpTargetMap.keySet()) { Pair<Long, Long> rollingupStats = innerRollingUpTargetMap.get(tgtCuboid); if (statistics.get(tgtCuboid) != null) { if (!ifHasStats) { totalEstRowCount = 0L; nEffective = 0; ifHasStats = true; } double rollupRatio = calculateRollupRatio(rollingupStats); totalEstRowCount += (1 - rollupRatio) * statistics.get(tgtCuboid); nEffective++; } else { if (ifHasStats) { continue; } totalEstRowCount += rollingupStats.getSecond(); nEffective++; } } if (nEffective != 0) srcCuboidsStats.put(cuboid, totalEstRowCount / nEffective); else throw new ArithmeticException("/ by zero"); } srcCuboidsStats.remove(0L); adjustCuboidStats(srcCuboidsStats, statistics); return srcCuboidsStats; } private  CuboidStatsUtil(); static Map<Long, Double> calculateCuboidHitProbability(Set<Long> selectionCuboidSet,
            Map<Long, Long> hitFrequencyMap, long nTotalCuboids, double queryUncertaintyRatio); static Map<Long, Long> generateSourceCuboidStats(Map<Long, Long> statistics,
            Map<Long, Double> cuboidHitProbabilityMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpSourceMap); static Map<Long, Long> complementRowCountForCuboids(final Map<Long, Long> statistics, Set<Long> cuboids); static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics); static void adjustCuboidStats(Map<Long, Long> mandatoryCuboidsWithStats, Map<Long, Long> statistics); static Map<Long, List<Long>> createDirectChildrenCache(final Set<Long> cuboidSet); static boolean isDescendant(long cuboidToCheck, long parentCuboid);  }