/** * Get the weight check query for the given query. * * @param druidQuery Druid query to convert to a weight check query * * @return the converted query */ public WeightEvaluationQuery makeWeightEvaluationQuery(DruidAggregationQuery<?> druidQuery) { return WeightEvaluationQuery.makeWeightEvaluationQuery(druidQuery); } }
/** * Generate a query that calculates the even weight of the response cardinality of the given query. * * @param query Query to calculate the weighted response cardinality of * @param weight Weight to apply to each response row */ public WeightEvaluationQuery(DruidAggregationQuery<?> query, int weight) { super( makeInnerQuery(query, weight), AllGranularity.INSTANCE, Collections.<Dimension>emptyList(), (Filter) null, (Having) null, Collections.<Aggregation>singletonList(new LongSumAggregation("count", "count")), Collections.<PostAggregation>emptyList(), query.getIntervals(), query.getQueryType() == DefaultQueryType.GROUP_BY ? stripColumnsFromLimitSpec(query) : null ); }
/** * Indicate if the weight check query can be skipped based on heuristics. * * @param query Query to test * * @return true if the weight check query does not need to be run */ public boolean skipWeightCheckQuery(DruidAggregationQuery<?> query) { try { long worstCaseRows = WeightEvaluationQuery.getWorstCaseWeightEstimate(query); double skipThreshold = getQueryWeightThreshold(query.getGranularity()) / weightCheckBypassFactor; return worstCaseRows <= skipThreshold; } catch (ArithmeticException ignored) { // We got a really big estimate, so don't skip the check LOG.debug("worst case weight larger than {}", Long.MAX_VALUE); return false; } }
/** * Evaluate Druid query for expensive aggregation that could bring down Druid. * * @param query Druid Query * * @return query or null if not required */ public static WeightEvaluationQuery makeWeightEvaluationQuery(DruidAggregationQuery<?> query) { // get inner-most query for evaluation DruidAggregationQuery<?> innerQuery = query.getInnermostQuery(); int weight = Utils.getSubsetByType(innerQuery.getAggregations(), SketchAggregation.class).size(); return new WeightEvaluationQuery(innerQuery, weight); }
postAggregations, innerQuery.getIntervals(), stripColumnsFromLimitSpec(innerQuery) ); return new QueryDataSource(inner);