Search in sources :

Example 1 with Interpolator

use of io.cdap.cdap.api.dataset.lib.cube.Interpolator in project cdap by caskdata.

the class MetricsQueryHelper method setTimeRangeInQueryRequest.

private void setTimeRangeInQueryRequest(MetricQueryRequest request, Map<String, List<String>> queryTimeParams) {
    Long start = queryTimeParams.containsKey(PARAM_START_TIME) ? TimeMathParser.parseTimeInSeconds(queryTimeParams.get(PARAM_START_TIME).get(0)) : null;
    Long end = queryTimeParams.containsKey(PARAM_END_TIME) ? TimeMathParser.parseTimeInSeconds(queryTimeParams.get(PARAM_END_TIME).get(0)) : null;
    Integer count = null;
    AggregationOption aggregationOption = queryTimeParams.containsKey(PARAM_AGGREGATE) ? AggregationOption.valueOf(queryTimeParams.get(PARAM_AGGREGATE).get(0).toUpperCase()) : AggregationOption.FALSE;
    boolean aggregate = aggregationOption.equals(AggregationOption.TRUE) || ((start == null) && (end == null));
    Integer resolution = queryTimeParams.containsKey(PARAM_RESOLUTION) ? getResolution(queryTimeParams.get(PARAM_RESOLUTION).get(0), start, end) : getResolution(null, start, end);
    Interpolator interpolator = null;
    if (queryTimeParams.containsKey(PARAM_INTERPOLATE)) {
        long timeLimit = queryTimeParams.containsKey(PARAM_MAX_INTERPOLATE_GAP) ? Long.parseLong(queryTimeParams.get(PARAM_MAX_INTERPOLATE_GAP).get(0)) : Long.MAX_VALUE;
        interpolator = getInterpolator(queryTimeParams.get(PARAM_INTERPOLATE).get(0), timeLimit);
    }
    if (queryTimeParams.containsKey(PARAM_COUNT)) {
        count = Integer.valueOf(queryTimeParams.get(PARAM_COUNT).get(0));
        if (start == null && end != null) {
            start = end - count * resolution;
        } else if (start != null && end == null) {
            end = start + count * resolution;
        }
    } else if (start != null && end != null) {
        count = (int) (((end / resolution * resolution) - (start / resolution * resolution)) / resolution + 1);
    } else if (!aggregate) {
        throw new IllegalArgumentException("At least two of count/start/end parameters " + "are required for time-range queries ");
    }
    if (aggregate) {
        request.setTimeRange(0L, 0L, 1, Integer.MAX_VALUE, null, aggregationOption);
    } else {
        request.setTimeRange(start, end, count, resolution, interpolator, aggregationOption);
    }
}
Also used : Interpolator(io.cdap.cdap.api.dataset.lib.cube.Interpolator) AggregationOption(io.cdap.cdap.api.dataset.lib.cube.AggregationOption)

Aggregations

AggregationOption (io.cdap.cdap.api.dataset.lib.cube.AggregationOption)1 Interpolator (io.cdap.cdap.api.dataset.lib.cube.Interpolator)1