/** * Add partition range to the timeline. Default implementation is to iterate over the range and add * each time partition belonging to the given range. Implementing classes can override. * * @param partitionRange * @return whether add was successful * @throws LensException */ boolean add(TimePartitionRange partitionRange) throws LensException { boolean ret = true; for (TimePartition part : partitionRange) { ret &= add(part); } return ret; }
@Override public Iterator<TimePartition> iterator() { return new Iterator<TimePartition>() { TimePartition cur = getFirst(); @Override public boolean hasNext() { return cur != null && getLatest() != null && !cur.after(getLatest()); } @Override public TimePartition next() { while (holes.contains(cur)) { cur = cur.next(); } TimePartition toReturn = cur; cur = cur.next(); return toReturn; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }
@Override public Iterator<TimePartition> iterator() { return getAllPartitions().iterator(); } }
/** * Commit all partitions that were added to batch addition queue. //TODO: improve batch addition implementation. * * @return true if all the partitions were added successfully, or no partitions needed to be added * @throws LensException */ public boolean commitBatchAdditions() throws LensException { if (getAll() == null) { return true; } log.info("initializing timeline from batch addition: {},{},{}", getStorageTableName(), getUpdatePeriod(), getPartCol()); boolean result = add(getAll()); all = null; log.info("initialized to: {}", this); return result; }
@Override public boolean exists(TimePartition toCheck) { if (isEmpty()) { return false; } for (TimePartitionRange range : ranges) { if (range.contains(toCheck)) { return true; } } return false; }
/** check partition existence in the appropriate timeline if it exists */ public boolean partitionTimeExists(String name, String storage, UpdatePeriod period, String partCol, Date partSpec) throws HiveException, LensException { return get(name, storage, period, partCol) != null && get(name, storage, period, partCol).exists(TimePartition.of(period, partSpec)); }
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)); } }
/** * Commit all partitions that were added to batch addition queue. //TODO: improve batch addition implementation. * * @return true if all the partitions were added successfully, or no partitions needed to be added * @throws LensException */ public boolean commitBatchAdditions() throws LensException { if (getAll() == null) { return true; } log.info("initializing timeline from batch addition: {},{},{}", getStorageTableName(), getUpdatePeriod(), getPartCol()); boolean result = add(getAll()); all = null; log.info("initialized to: {}", this); return result; }
/** * Add partition range to the timeline. Default implementation is to iterate over the range and add * each time partition belonging to the given range. Implementing classes can override. * * @param partitionRange * @return whether add was successful * @throws LensException */ boolean add(TimePartitionRange partitionRange) throws LensException { boolean ret = true; for (TimePartition part : partitionRange) { ret &= add(part); } return ret; }
@Override public Iterator<TimePartition> iterator() { return getAllPartitions().iterator(); } }
@Override public Iterator<TimePartition> iterator() { return new Iterator<TimePartition>() { TimePartition cur = getFirst(); @Override public boolean hasNext() { return cur != null && getLatest() != null && !cur.after(getLatest()); } @Override public TimePartition next() { while (holes.contains(cur)) { cur = cur.next(); } TimePartition toReturn = cur; cur = cur.next(); return toReturn; } @Override public void remove() { throw new UnsupportedOperationException(); } }; } }
@Override public boolean exists(TimePartition toCheck) { if (isEmpty()) { return false; } for (TimePartitionRange range : ranges) { if (range.contains(toCheck)) { return true; } } return false; }
/** check partition existence in the appropriate timeline if it exists */ public boolean partitionTimeExists(String name, String storage, UpdatePeriod period, String partCol, Date partSpec) throws HiveException, LensException { return get(name, storage, period, partCol) != null && get(name, storage, period, partCol).exists(TimePartition.of(period, partSpec)); }
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)); } }
/** * Add multiple partitions to timeline * * @param partitions * @return whether add was successful * @throws LensException */ public boolean add(@NonNull Collection<TimePartition> partitions) throws LensException { boolean result = true; for (TimePartition partition : partitions) { result &= add(partition); } // Can also return the failed to add items. return result; }
/** * Add multiple partitions to timeline * * @param partitions * @return whether add was successful * @throws LensException */ public boolean add(@NonNull Collection<TimePartition> partitions) throws LensException { boolean result = true; for (TimePartition partition : partitions) { result &= add(partition); } // Can also return the failed to add items. return result; }