@Test public void testAdjustMandatoryCuboidStats() { Map<Long, Long> statistics = Maps.newHashMap(); statistics.put(60160L, 1212L); Map<Long, Long> cuboidsWithStats = Maps.newHashMap(); cuboidsWithStats.put(65280L, 1423L); cuboidsWithStats.put(63232L, 2584421L); cuboidsWithStats.put(61184L, 132L); cuboidsWithStats.put(57088L, 499L); cuboidsWithStats.put(55040L, 708L); cuboidsWithStats.put(38656L, 36507L); Map<Long, Double> cuboidHitProbabilityMap = Maps.newHashMap(); cuboidHitProbabilityMap.put(65280L, 0.2); cuboidHitProbabilityMap.put(63232L, 0.16); cuboidHitProbabilityMap.put(61184L, 0.16); cuboidHitProbabilityMap.put(57088L, 0.16); cuboidHitProbabilityMap.put(55040L, 0.16); cuboidHitProbabilityMap.put(38656L, 0.16); Map<Long, Long> cuboidsWithStatsExpected = Maps.newHashMap(cuboidsWithStats); cuboidsWithStatsExpected.put(65280L, 2584421L); cuboidsWithStatsExpected.put(57088L, 36507L); cuboidsWithStatsExpected.put(55040L, 36507L); cuboidsWithStatsExpected.put(61184L, 1212L); CuboidStatsUtil.adjustCuboidStats(cuboidsWithStats, statistics); Assert.assertEquals(cuboidsWithStatsExpected, cuboidsWithStats); }
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);  }