@Override public void accept(Result result) { DateTime timestamp = result.getTimeStamp(); if (!timestamp.equals(recentTimeStamp)) { filledBuckets = 0; recentTimeStamp = timestamp; } if (filledBuckets++ < topN) { data.add(result); } } }
/** * Constructor. * * @param result Result row from a result set */ public ResultSerializationProxy(Result result) { this.result = result; this.dimensionValues = getDimensionValues(result); this.metricValues = getMetricValues(result); this.timeStamp = result.getTimeStamp().toString(); }
/** * Expand the result by adding a new metric column with the row number as the metric value. * * @param result Result to expand * @param metricColumn New column to add * @param rowNum Row number to use as the metric value * * @return the expanded Result */ private Result rowNumMap(Result result, MetricColumn metricColumn, int rowNum) { Map<MetricColumn, Object> metricValues = new LinkedHashMap<>(result.getMetricValues()); metricValues.put(metricColumn, BigDecimal.valueOf(rowNum)); return new Result(result.getDimensionRows(), metricValues, result.getTimeStamp()); } }
/** * Sorting the resultSet based on dateTime column sort direction. * * @param resultSet The result set need to be sorted in ascending or descending order * * @return sorted ResultSet */ @Override public ResultSet map(ResultSet resultSet) { Map<DateTime, List<Result>> bucketizedResultsMap = new LinkedHashMap<>(); RequestLog.startTiming("sortResultSet"); try { for (Result result : resultSet) { bucketizedResultsMap.computeIfAbsent(result.getTimeStamp(), ignored -> new ArrayList<>()).add(result); } List<DateTime> dateTimeList = new ArrayList<>(bucketizedResultsMap.keySet()); Collections.sort(dateTimeList, direction == SortDirection.ASC ? Comparator.naturalOrder() : Comparator.reverseOrder()); return new ResultSet( resultSet.getSchema(), dateTimeList.stream() .map(bucketizedResultsMap::get) .flatMap(List::stream) .collect(Collectors.toList()) ); } finally { RequestLog.stopTiming("sortResultSet"); } }
row.put("dateTime", result.getTimeStamp().toString(DateTimeFormatterFactory.getOutputFormatter()));
row.put("dateTime", result.getTimeStamp().toString(DateTimeFormatterFactory.getOutputFormatter()));
/** * Remove result records which are missing and not marked as volatile. * Any bucket which is partially volatile is not removed. In the case of the All granularity, all data is * considered to be in a single bucket. * * @param result The result row being transformed * @param schema The schema for that result * @return Null if the bucket this result falls in is missing but not volatile */ @Override public Result map(Result result, ResultSetSchema schema) { Granularity grain = schema.getGranularity(); if (grain.equals(AllGranularity.INSTANCE)) { return ! volatileIntervalSupply.get().isEmpty() || missingIntervals.isEmpty() ? result : null; } // Currently any Granularity which isn't 'ALL' must currently be a TimeGrain Interval resultInterval = new Interval(result.getTimeStamp(), ((TimeGrain) grain).getPeriod()); return getMissingNotVolatile().stream().anyMatch((it) -> it.overlaps(resultInterval)) ? null : result; }