@Test public void testMapRange2() throws Exception { Pair<String, String> results = lookupTable.mapRange("WEEK_BEG_DT", millis("2013-05-01"), millis("2013-08-01"), "CAL_DT"); System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getFirst()))); System.out.println(DateFormat.formatToDateStr(Long.parseLong(results.getSecond()))); Assert.assertEquals(millis("2013-05-05"), results.getFirst()); Assert.assertEquals(millis("2013-08-03"), results.getSecond()); }
public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); Comparator<T> colComp = getComparator(colIdx); Comparator<T> returnComp = getComparator(returnIdx); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue, colComp)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnComp.compare(returnValue, returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnComp.compare(returnValue, returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return Pair.newPair(returnBegin, returnEnd); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); Comparator<T> colComp = getComparator(colIdx); Comparator<T> returnComp = getComparator(returnIdx); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue, colComp)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnComp.compare(returnValue, returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnComp.compare(returnValue, returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return Pair.newPair(returnBegin, returnEnd); } }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); Comparator<T> colComp = getComparator(colIdx); Comparator<T> returnComp = getComparator(returnIdx); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue, colComp)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnComp.compare(returnValue, returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnComp.compare(returnValue, returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return Pair.newPair(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, IReadableTable table); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); Comparator<T> colComp = getComparator(colIdx); Comparator<T> returnComp = getComparator(returnIdx); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue, colComp)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnComp.compare(returnValue, returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnComp.compare(returnValue, returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return Pair.newPair(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, IReadableTable table); T[] getRow(Array<T> key); Collection<T[]> getAllRows(); List<T> scan(String col, List<T> values, String returnCol); Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol); Set<T> mapValues(String col, Set<T> values, String returnCol); String toString(); abstract Class<?> getType(); void dump(); }
LookupTable { public Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol) { int colIdx = tableDesc.findColumnByName(col).getZeroBasedIndex(); int returnIdx = tableDesc.findColumnByName(returnCol).getZeroBasedIndex(); Comparator<T> colComp = getComparator(colIdx); Comparator<T> returnComp = getComparator(returnIdx); T returnBegin = null; T returnEnd = null; for (T[] row : data.values()) { if (between(beginValue, row[colIdx], endValue, colComp)) { T returnValue = row[returnIdx]; if (returnBegin == null || returnComp.compare(returnValue, returnBegin) < 0) { returnBegin = returnValue; } if (returnEnd == null || returnComp.compare(returnValue, returnEnd) > 0) { returnEnd = returnValue; } } } if (returnBegin == null && returnEnd == null) return null; else return Pair.newPair(returnBegin, returnEnd); } LookupTable(TableDesc tableDesc, String[] keyColumns, IReadableTable table); T[] getRow(Array<T> key); Collection<T[]> getAllRows(); List<T> scan(String col, List<T> values, String returnCol); Pair<T, T> mapRange(String col, T beginValue, T endValue, String returnCol); Set<T> mapValues(String col, Set<T> values, String returnCol); String toString(); abstract Class<?> getType(); void dump();  }