@Override public TimePartition next() { TimePartition ret = current; current = current.next(); return ret; }
@Override public TimePartition next() { TimePartition ret = current; current = current.next(); return ret; }
public TimePartitionRange singletonRange() throws LensException { return rangeUpto(next()); }
public TimePartitionRange singletonRange() throws LensException { return rangeUpto(next()); }
public static TimePartitionRange parseFrom(UpdatePeriod updatePeriod, String from, String to) throws LensException { boolean incrementFrom = false; boolean incrementTo = false; if (from.charAt(0) == '[') { from = from.substring(1); } else if (from.charAt(0) == '(') { from = from.substring(1); incrementFrom = true; } if (to.charAt(to.length() - 1) == ']') { to = to.substring(0, to.length() - 1); incrementTo = true; } else if (to.charAt(to.length() - 1) == ')') { to = to.substring(0, to.length() - 1); } TimePartition fromPartition = TimePartition.of(updatePeriod, from); TimePartition toPartition = TimePartition.of(updatePeriod, to); if (incrementFrom) { fromPartition = fromPartition.next(); } if (incrementTo) { toPartition = toPartition.next(); } return new TimePartitionRange(fromPartition, toPartition); }
public static TimePartitionRange parseFrom(UpdatePeriod updatePeriod, String from, String to) throws LensException { boolean incrementFrom = false; boolean incrementTo = false; if (from.charAt(0) == '[') { from = from.substring(1); } else if (from.charAt(0) == '(') { from = from.substring(1); incrementFrom = true; } if (to.charAt(to.length() - 1) == ']') { to = to.substring(0, to.length() - 1); incrementTo = true; } else if (to.charAt(to.length() - 1) == ')') { to = to.substring(0, to.length() - 1); } TimePartition fromPartition = TimePartition.of(updatePeriod, from); TimePartition toPartition = TimePartition.of(updatePeriod, to); if (incrementFrom) { fromPartition = fromPartition.next(); } if (incrementTo) { toPartition = toPartition.next(); } return new TimePartitionRange(fromPartition, toPartition); }
private void addHolesBetween(TimePartition begin, TimePartition end, UpdatePeriod updatePeriod) throws LensException { for (Date date : TimeRange.iterable(begin.next().getDate(), end.getDate(), updatePeriod, 1)) { addHole(TimePartition.of(updatePeriod, date)); } }
private void addHolesBetween(TimePartition begin, TimePartition end, UpdatePeriod updatePeriod) throws LensException { for (Date date : TimeRange.iterable(begin.next().getDate(), end.getDate(), updatePeriod, 1)) { addHole(TimePartition.of(updatePeriod, date)); } }
public FactPartition next() throws LensException { return new FactPartition(getPartCol(), getTimePartition().next(), getContainingPart(), getStorageTables()); }
public FactPartition next() throws LensException { return new FactPartition(getPartCol(), getTimePartition().next(), getContainingPart(), getStorageTables()); }
private void assertTimeline(EndsAndHolesPartitionTimeline endsAndHolesPartitionTimeline, StoreAllPartitionTimeline storeAllPartitionTimeline, UpdatePeriod updatePeriod, Date first, Date latest, Date... holes) throws LensException { TimePartition firstPart = TimePartition.of(updatePeriod, first); TimePartition latestPart = TimePartition.of(updatePeriod, latest); assertEquals(endsAndHolesPartitionTimeline.getFirst(), firstPart); assertEquals(endsAndHolesPartitionTimeline.getLatest(), TimePartition.of(updatePeriod, latest)); assertEquals(endsAndHolesPartitionTimeline.getHoles().size(), holes.length); for (Date date : holes) { assertTrue(endsAndHolesPartitionTimeline.getHoles().contains(TimePartition.of(updatePeriod, date))); } TreeSet<TimePartition> partitions = new TreeSet<>(); for (Date dt : TimeRange.iterable(firstPart.getDate(), latestPart.next().getDate(), updatePeriod, 1)) { partitions.add(TimePartition.of(updatePeriod, dt)); } for (Date holeDate : holes) { partitions.remove(TimePartition.of(updatePeriod, holeDate)); } assertEquals(storeAllPartitionTimeline.getAllPartitions(), partitions); }
assertEquals(TimePartitionRange.parseFrom(up, "[" + nowStr, tenLaterStr + ")"), range); assertEquals(TimePartitionRange.parseFrom(up, "[" + nowStr, tenLaterStr + "]"), nowPartition.rangeUpto(tenLater.next())); assertEquals(TimePartitionRange.parseFrom(up, "(" + nowStr, tenLaterStr + "]"), nowPartition.next().rangeUpto( tenLater.next())); assertEquals(TimePartitionRange.parseFrom(up, "(" + nowStr, tenLaterStr + ")"), nowPartition.next().rangeUpto(tenLater));
public void add(String partCol, TimePartition partition) throws LensException { if (get(partCol) == null) { put(partCol, new RangesPartitionTimeline("", UpdatePeriod.values()[0], partCol)); } get(partCol).add(partition.withUpdatePeriod(UpdatePeriod.values()[0]) .rangeUpto(partition.next().withUpdatePeriod(UpdatePeriod.values()[0]))); }
public void add(String partCol, TimePartition partition) throws LensException { if (get(partCol) == null) { put(partCol, new RangesPartitionTimeline("", UpdatePeriod.values()[0], partCol)); } get(partCol).add(partition.withUpdatePeriod(UpdatePeriod.values()[0]) .rangeUpto(partition.next().withUpdatePeriod(UpdatePeriod.values()[0]))); }
@Override public boolean drop(TimePartition toDrop) throws LensException { int ind = getStrictlyAfterIndex(toDrop); if (ind == 0) { return true; // nothing to do } if (ranges.get(ind - 1).getBegin().equals(toDrop)) { ranges.get(ind - 1).setBegin(toDrop.next()); } else if (ranges.get(ind - 1).getEnd().previous().equals(toDrop)) { ranges.get(ind - 1).setEnd(toDrop); } else { TimePartition end = ranges.get(ind - 1).getEnd(); ranges.get(ind - 1).setEnd(toDrop); ranges.add(ind, toDrop.next().rangeUpto(end)); } if (ranges.get(ind - 1).isEmpty()) { ranges.remove(ind - 1); } return true; }
@Override public boolean drop(TimePartition toDrop) throws LensException { int ind = getStrictlyAfterIndex(toDrop); if (ind == 0) { return true; // nothing to do } if (ranges.get(ind - 1).getBegin().equals(toDrop)) { ranges.get(ind - 1).setBegin(toDrop.next()); } else if (ranges.get(ind - 1).getEnd().previous().equals(toDrop)) { ranges.get(ind - 1).setEnd(toDrop); } else { TimePartition end = ranges.get(ind - 1).getEnd(); ranges.get(ind - 1).setEnd(toDrop); ranges.add(ind, toDrop.next().rangeUpto(end)); } if (ranges.get(ind - 1).isEmpty()) { ranges.remove(ind - 1); } return true; }
@Test(dataProvider = "update-periods") public void test(UpdatePeriod up) throws LensException { // Normal date object parsable String nowStr = up.format(NOW); // Create partition by date object or it's string representation -- both should be same. TimePartition nowPartition = TimePartition.of(up, NOW); TimePartition nowStrPartition = TimePartition.of(up, nowStr); assertEquals(nowPartition, nowStrPartition); // Test next and previous assertTrue(nowPartition.next().after(nowPartition)); assertTrue(nowPartition.previous().before(nowPartition)); // date parse failures should give lens exception assertEquals(getLensExceptionFromPartitionParsing(up, "garbage").getMessage(), TimePartition.getWrongUpdatePeriodMessage(up, "garbage")); getLensExceptionFromPartitionParsing(up, (Date) null); getLensExceptionFromPartitionParsing(up, (String) null); getLensExceptionFromPartitionParsing(up, ""); // parse with other update periods for (UpdatePeriod up2 : UpdatePeriod.values()) { // handles the equality case and the case where monthly-quarterly have same format strings. if (up.formatStr().equals(up2.formatStr())) { continue; } // Parsing a string representation with differnet update period should give lens exception. assertEquals(getLensExceptionFromPartitionParsing(up2, nowStr).getMessage(), TimePartition.getWrongUpdatePeriodMessage(up2, nowStr)); } }
ranges.get(ind - 1).setEnd(partition.next());