/** * Gets the number of rows to limit results to for a Group by Query. Otherwise no limit is applied. * * @param druidQuery The query to get the row limit from. * * @return the number of rows to include in the results. */ protected int getLimit(DruidAggregationQuery<?> druidQuery) { if (druidQuery.getQueryType().equals(GROUP_BY)) { GroupByQuery groupByQuery = (GroupByQuery) druidQuery; LimitSpec limitSpec = groupByQuery.getLimitSpec(); if (limitSpec != null) { return limitSpec.getLimit().orElse(NO_LIMIT); } } return NO_LIMIT; }
/** * Gets the collection of having filters to be applied from the druid query. * * @param builder The RelBuilder created with Calcite. * @param druidQuery The query to find the having filter from. * @param apiToFieldMapper The mapping from api to physical name. * * @return the collection of equivalent filters for calcite. */ protected Collection<RexNode> getHavingFilter( RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper ) { RexNode filter = null; if (druidQuery.getQueryType().equals(GROUP_BY)) { Having having = ((GroupByQuery) druidQuery).getHaving(); if (having != null) { filter = havingEvaluator.evaluateHaving(having, builder, apiToFieldMapper); } } return Collections.singletonList(filter); }
/** * Build a result set using the api request time grain. * * @param json The json representing the druid response. * @param druidQuery The druid query being processed * @param dateTimeZone The date time zone for parsing result rows * * @return The initial result set from the json node. */ public ResultSet buildResultSet(JsonNode json, DruidAggregationQuery<?> druidQuery, DateTimeZone dateTimeZone) { LinkedHashSet<Column> columns = druidResponseParser.buildSchemaColumns(druidQuery) .collect(Collectors.toCollection(LinkedHashSet::new)); ResultSetSchema resultSetSchema = new ResultSetSchema(granularity, columns); return druidResponseParser.parse(json, resultSetSchema, druidQuery.getQueryType(), dateTimeZone); } }
/** * 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 ); }
if (druidQuery.getQueryType().equals(GROUP_BY)) { GroupByQuery groupByQuery = (GroupByQuery) druidQuery; LimitSpec limitSpec = groupByQuery.getLimitSpec();
if (innerQuery.getQueryType() == DefaultQueryType.TOP_N) { TopNQuery topNQuery = (TopNQuery) innerQuery; cardinalityWeight = Math.min(
postAggregations = Collections.singletonList(new ConstantPostAggregation("count", weight)); if (!(innerQuery.getQueryType() instanceof DefaultQueryType)) { return null; DefaultQueryType innerQueryType = (DefaultQueryType) innerQuery.getQueryType(); switch (innerQueryType) { case GROUP_BY: