@Test public void testMergeRangeMap() { DataModelDesc model = DataModelManager.getInstance(getTestConfig()).getDataModelDesc("ci_inner_join_model"); String colId = "TEST_KYLIN_FACT.CAL_DT"; { Map<String, DimensionRangeInfo> m1 = new HashMap<>(); m1.put(colId, new DimensionRangeInfo("2012-01-01", "2012-05-31")); Map<String, DimensionRangeInfo> m2 = new HashMap<>(); m2.put(colId, new DimensionRangeInfo("2012-06-01", "2013-06-30")); DimensionRangeInfo r1 = DimensionRangeInfo.mergeRangeMap(model, m1, m2).get(colId); Assert.assertEquals("2012-01-01", r1.getMin()); Assert.assertEquals("2013-06-30", r1.getMax()); } { Map<String, DimensionRangeInfo> m1 = new HashMap<>(); m1.put(colId, new DimensionRangeInfo("2012-01-01", "2012-05-31")); Map<String, DimensionRangeInfo> m2 = new HashMap<>(); Assert.assertTrue(DimensionRangeInfo.mergeRangeMap(model, m1, m2).isEmpty()); Assert.assertTrue(DimensionRangeInfo.mergeRangeMap(model, m2, m1).isEmpty()); } { Map<String, DimensionRangeInfo> m1 = new HashMap<>(); m1.put(colId, new DimensionRangeInfo(null, null)); Map<String, DimensionRangeInfo> m2 = new HashMap<>(); m2.put(colId, new DimensionRangeInfo("2012-06-01", "2013-06-30")); DimensionRangeInfo r1 = DimensionRangeInfo.mergeRangeMap(model, m1, m2).get(colId); Assert.assertEquals("2012-06-01", r1.getMin()); Assert.assertEquals("2013-06-30", r1.getMax()); } }
public static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1, Map<String, DimensionRangeInfo> m2) { if (!m1.keySet().equals(m2.keySet())) { logger.warn("Merging incompatible maps of DimensionRangeInfo, keys in m1 " + m1.keySet() + ", keys in m2 " + m2.keySet()); } Map<String, DimensionRangeInfo> result = Maps.newHashMap(); for (String colId : m1.keySet()) { if (!m2.containsKey(colId)) continue; DimensionRangeInfo r1 = m1.get(colId); DimensionRangeInfo r2 = m2.get(colId); DimensionRangeInfo newR; if (r1.getMin() == null && r1.getMax() == null) { newR = r2; } else if (r2.getMin() == null && r2.getMax() == null) { newR = r1; } else { DataTypeOrder order = model.findColumn(colId).getType().getOrder(); String newMin = order.min(r1.getMin(), r2.getMin()); String newMax = order.max(r1.getMax(), r2.getMax()); newR = new DimensionRangeInfo(newMin, newMax); } result.put(colId, newR); } return result; }
DimensionRangeInfo implements Serializable { public static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1, Map<String, DimensionRangeInfo> m2) { if (!m1.keySet().equals(m2.keySet())) { logger.warn("Merging incompatible maps of DimensionRangeInfo, keys in m1 " + m1.keySet() + ", keys in m2 " + m2.keySet()); } Map<String, DimensionRangeInfo> result = Maps.newHashMap(); for (String colId : m1.keySet()) { if (!m2.containsKey(colId)) continue; DimensionRangeInfo r1 = m1.get(colId); DimensionRangeInfo r2 = m2.get(colId); DimensionRangeInfo newR; if (r1.getMin() == null && r1.getMax() == null) { newR = r2; } else if (r2.getMin() == null && r2.getMax() == null) { newR = r1; } else { DataTypeOrder order = model.findColumn(colId).getType().getOrder(); String newMin = order.min(r1.getMin(), r2.getMin()); String newMax = order.max(r1.getMax(), r2.getMax()); newR = new DimensionRangeInfo(newMin, newMax); } result.put(colId, newR); } return result; } }
DimensionRangeInfo implements Serializable { public static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1, Map<String, DimensionRangeInfo> m2) { if (!m1.keySet().equals(m2.keySet())) { logger.warn("Merging incompatible maps of DimensionRangeInfo, keys in m1 " + m1.keySet() + ", keys in m2 " + m2.keySet()); } Map<String, DimensionRangeInfo> result = Maps.newHashMap(); for (String colId : m1.keySet()) { if (!m2.containsKey(colId)) continue; DimensionRangeInfo r1 = m1.get(colId); DimensionRangeInfo r2 = m2.get(colId); DimensionRangeInfo newR; if (r1.getMin() == null && r1.getMax() == null) { newR = r2; } else if (r2.getMin() == null && r2.getMax() == null) { newR = r1; } else { DataTypeOrder order = model.findColumn(colId).getType().getOrder(); String newMin = order.min(r1.getMin(), r2.getMin()); String newMax = order.max(r1.getMax(), r2.getMax()); newR = new DimensionRangeInfo(newMin, newMax); } result.put(colId, newR); } return result; } DimensionRangeInfo();  DimensionRangeInfo(String min, String max); }
DimensionRangeInfo implements Serializable { public static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1, Map<String, DimensionRangeInfo> m2) { if (!m1.keySet().equals(m2.keySet())) { logger.warn("Merging incompatible maps of DimensionRangeInfo, keys in m1 " + m1.keySet() + ", keys in m2 " + m2.keySet()); } Map<String, DimensionRangeInfo> result = Maps.newHashMap(); for (String colId : m1.keySet()) { if (!m2.containsKey(colId)) continue; DimensionRangeInfo r1 = m1.get(colId); DimensionRangeInfo r2 = m2.get(colId); DimensionRangeInfo newR; if (r1.getMin() == null && r1.getMax() == null) { newR = r2; } else if (r2.getMin() == null && r2.getMax() == null) { newR = r1; } else { DataTypeOrder order = model.findColumn(colId).getType().getOrder(); String newMin = order.min(r1.getMin(), r2.getMin()); String newMax = order.max(r1.getMax(), r2.getMax()); newR = new DimensionRangeInfo(newMin, newMax); } result.put(colId, newR); } return result; } DimensionRangeInfo();  DimensionRangeInfo(String min, String max); static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1,
            Map<String, DimensionRangeInfo> m2); String getMin(); void setMin(String min); String getMax(); void setMax(String max); @Override String toString(); }
DimensionRangeInfo implements Serializable { public static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1, Map<String, DimensionRangeInfo> m2) { if (!m1.keySet().equals(m2.keySet())) { logger.warn("Merging incompatible maps of DimensionRangeInfo, keys in m1 " + m1.keySet() + ", keys in m2 " + m2.keySet()); } Map<String, DimensionRangeInfo> result = Maps.newHashMap(); for (String colId : m1.keySet()) { if (!m2.containsKey(colId)) continue; DimensionRangeInfo r1 = m1.get(colId); DimensionRangeInfo r2 = m2.get(colId); DimensionRangeInfo newR; if (r1.getMin() == null && r1.getMax() == null) { newR = r2; } else if (r2.getMin() == null && r2.getMax() == null) { newR = r1; } else { DataTypeOrder order = model.findColumn(colId).getType().getOrder(); String newMin = order.min(r1.getMin(), r2.getMin()); String newMax = order.max(r1.getMax(), r2.getMax()); newR = new DimensionRangeInfo(newMin, newMax); } result.put(colId, newR); } return result; } DimensionRangeInfo();  DimensionRangeInfo(String min, String max); static Map<String, DimensionRangeInfo> mergeRangeMap(DataModelDesc model, Map<String, DimensionRangeInfo> m1,
            Map<String, DimensionRangeInfo> m2); String getMin(); void setMin(String min); String getMax(); void setMax(String max); @Override String toString();  }