@Test public void testAdjustCuboidStats() { Map<Long, Long> statistics = Maps.newHashMap(); statistics.put(1L, 20L); statistics.put(2L, 80L); statistics.put(4L, 60L); statistics.put(3L, 40L); statistics.put(11L, 90L); statistics.put(14L, 50L); statistics.put(15L, 70L); Map<Long, Long> cuboidsWithStatsExpected = Maps.newHashMap(statistics); cuboidsWithStatsExpected.put(3L, 80L); cuboidsWithStatsExpected.put(14L, 80L); cuboidsWithStatsExpected.put(15L, 90L); statistics = CuboidStatsUtil.adjustCuboidStats(statistics); Assert.assertEquals(cuboidsWithStatsExpected, statistics); Map<Long, Long> mandatoryCuboidsWithStats = Maps.newHashMap(); mandatoryCuboidsWithStats.put(7L, 70L); mandatoryCuboidsWithStats.put(8L, 100L); mandatoryCuboidsWithStats.put(9L, 85L); CuboidStatsUtil.adjustCuboidStats(mandatoryCuboidsWithStats, statistics); Map<Long, Long> mandatoryCuboidsWithStatsExpected = Maps.newHashMap(); mandatoryCuboidsWithStatsExpected.put(7L, 80L); mandatoryCuboidsWithStatsExpected.put(8L, 80L); mandatoryCuboidsWithStatsExpected.put(9L, 85L); Assert.assertEquals(mandatoryCuboidsWithStatsExpected, mandatoryCuboidsWithStats); }
public static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics) { Map<Long, Long> ret = Maps.newHashMapWithExpectedSize(statistics.size()); List<Long> cuboids = Lists.newArrayList(statistics.keySet()); Collections.sort(cuboids); for (Long cuboid : cuboids) { Long rowCount = statistics.get(cuboid); for (Long childCuboid : ret.keySet()) { if (isDescendant(childCuboid, cuboid)) { Long childRowCount = ret.get(childCuboid); if (rowCount < childRowCount) { rowCount = childRowCount; } } } ret.put(cuboid, rowCount); } return ret; }
CuboidStatsUtil { public static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics) { Map<Long, Long> ret = Maps.newHashMapWithExpectedSize(statistics.size()); List<Long> cuboids = Lists.newArrayList(statistics.keySet()); Collections.sort(cuboids); for (Long cuboid : cuboids) { Long rowCount = statistics.get(cuboid); for (Long childCuboid : ret.keySet()) { if (isDescendant(childCuboid, cuboid)) { Long childRowCount = ret.get(childCuboid); if (rowCount < childRowCount) { rowCount = childRowCount; } } } ret.put(cuboid, rowCount); } return ret; } }
CuboidStatsUtil { public static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics) { Map<Long, Long> ret = Maps.newHashMapWithExpectedSize(statistics.size()); List<Long> cuboids = Lists.newArrayList(statistics.keySet()); Collections.sort(cuboids); for (Long cuboid : cuboids) { Long rowCount = statistics.get(cuboid); for (Long childCuboid : ret.keySet()) { if (isDescendant(childCuboid, cuboid)) { Long childRowCount = ret.get(childCuboid); if (rowCount < childRowCount) { rowCount = childRowCount; } } } ret.put(cuboid, rowCount); } return ret; } private  CuboidStatsUtil(); }
CuboidStatsUtil { public static Map<Long, Long> adjustCuboidStats(Map<Long, Long> statistics) { Map<Long, Long> ret = Maps.newHashMapWithExpectedSize(statistics.size()); List<Long> cuboids = Lists.newArrayList(statistics.keySet()); Collections.sort(cuboids); for (Long cuboid : cuboids) { Long rowCount = statistics.get(cuboid); for (Long childCuboid : ret.keySet()) { if (isDescendant(childCuboid, cuboid)) { Long childRowCount = ret.get(childCuboid); if (rowCount < childRowCount) { rowCount = childRowCount; } } } ret.put(cuboid, rowCount); } return ret; } 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> adjustCuboidStats(Map<Long, Long> statistics) { Map<Long, Long> ret = Maps.newHashMapWithExpectedSize(statistics.size()); List<Long> cuboids = Lists.newArrayList(statistics.keySet()); Collections.sort(cuboids); for (Long cuboid : cuboids) { Long rowCount = statistics.get(cuboid); for (Long childCuboid : ret.keySet()) { if (isDescendant(childCuboid, cuboid)) { Long childRowCount = ret.get(childCuboid); if (rowCount < childRowCount) { rowCount = childRowCount; } } } ret.put(cuboid, rowCount); } return ret; } 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);  }