@Override public DateTime getTableAlignment() { return getSchema().getTimeGrain().roundFloor( IntervalUtils.firstMoment(getAllAvailableIntervals().values()).orElse(new DateTime()) ); }
/** * Find all the interval overlaps between two collections of intervals. * <p> * If the left set is null, return the right. This makes this usable in a reduce function. * * @param left The intervals being streamed over * @param right The intervals being tested against * * @return A set of intervals describing the time common to both sets */ public static Set<Interval> getOverlappingSubintervals(Collection<Interval> left, Collection<Interval> right) { if (left == null) { return new LinkedHashSet<>(right); } // Each interval in left is matched against all intervals in the right, collecting overlaps return left.stream() .flatMap(leftElement -> getIntervalOverlaps(leftElement, right)) .collect(Collectors.toSet()); }
/** * Find all the interval overlaps between two collections of intervals. * <p> * If the left set is null, return the right. This makes this usable in a reduce function. * * @param left The intervals being streamed over * @param right The intervals being tested against * * @return A set of intervals describing the time common to both sets */ public static Set<Interval> getOverlappingSubintervals(Set<Interval> left, Set<Interval> right) { return getOverlappingSubintervals((Collection) left, (Collection) right); }
/** * Compare two Physical Tables based on how much missing time they have. * * @param left The first table * @param right The second table * * @return negative if table1 has less missing time than table2 */ @Override public int compare(PhysicalTable left, PhysicalTable right) { // choose table with most data available for given columns long missingDurationLeft = IntervalUtils.getTotalDuration( partialDataHandler.findMissingTimeGrainIntervals( left.getAvailableIntervals(requestConstraint), new SimplifiedIntervalList(requestConstraint.getIntervals()), requestConstraint.getRequestGranularity() ) ); long missingDurationRight = IntervalUtils.getTotalDuration( partialDataHandler.findMissingTimeGrainIntervals( right.getAvailableIntervals(requestConstraint), new SimplifiedIntervalList(requestConstraint.getIntervals()), requestConstraint.getRequestGranularity() ) ); long difference = missingDurationLeft - missingDurationRight; return (int) Math.max(Math.min(Integer.MAX_VALUE, difference), Integer.MIN_VALUE); } }
@Override public SimplifiedIntervalList getVolatileIntervals( Granularity granularity, List<Interval> intervals, PhysicalTable factSource ) { SimplifiedIntervalList simplifiedIntervals = new SimplifiedIntervalList(intervals); SimplifiedIntervalList volatileIntervals = IntervalUtils.collectBucketedIntervalsIntersectingIntervalList( intervalsFunctions.getOrDefault(factSource.getName(), defaultIntervals).getVolatileIntervals(), simplifiedIntervals, granularity ); if (granularity instanceof AllGranularity && !volatileIntervals.isEmpty()) { volatileIntervals = simplifiedIntervals; } LOG.trace("Volatile intervals: {} for grain {}", volatileIntervals, granularity); return volatileIntervals; } }
IntervalUtils.getSlicedIntervals(queryIntervals, granularity) );
long periods = IntervalUtils.countSlicedIntervals(innerQuery.getIntervals(), innerQuery.getGranularity()); long cardinalityWeight;
return IntervalUtils.getTotalDuration(tableAvailability.intersect(volatilePartialRequestIntervals));