Example #1
0
  private void parseGroupBy(String context, QueryMetric queryMetric, JsonArray groupBys)
      throws QueryException, BeanValidationException {
    for (int J = 0; J < groupBys.size(); J++) {
      String groupContext = "group_by[" + J + "]";
      JsonObject jsGroupBy = groupBys.get(J).getAsJsonObject();

      JsonElement nameElement = jsGroupBy.get("name");
      if (nameElement == null || nameElement.getAsString().isEmpty())
        throw new BeanValidationException(
            new SimpleConstraintViolation(groupContext, "must have a name"), context);

      String name = nameElement.getAsString();

      GroupBy groupBy = m_groupByFactory.createGroupBy(name);
      if (groupBy == null)
        throw new BeanValidationException(
            new SimpleConstraintViolation(groupContext + "." + name, "invalid group_by name"),
            context);

      deserializeProperties(context + "." + groupContext, jsGroupBy, name, groupBy);
      validateObject(groupBy, context + "." + groupContext);

      groupBy.setStartDate(queryMetric.getStartTime());

      queryMetric.addGroupBy(groupBy);
    }
  }
Example #2
0
  private void parseAggregators(
      String context, QueryMetric queryMetric, JsonArray aggregators, DateTimeZone timeZone)
      throws QueryException, BeanValidationException {
    for (int J = 0; J < aggregators.size(); J++) {
      JsonObject jsAggregator = aggregators.get(J).getAsJsonObject();

      JsonElement name = jsAggregator.get("name");
      if (name == null || name.getAsString().isEmpty())
        throw new BeanValidationException(
            new SimpleConstraintViolation("aggregators[" + J + "]", "must have a name"), context);

      String aggContext = context + ".aggregators[" + J + "]";
      String aggName = name.getAsString();
      Aggregator aggregator = m_aggregatorFactory.createAggregator(aggName);

      if (aggregator == null)
        throw new BeanValidationException(
            new SimpleConstraintViolation(aggName, "invalid aggregator name"), aggContext);

      // If it is a range aggregator we will default the start time to
      // the start of the query.
      if (aggregator instanceof RangeAggregator) {
        RangeAggregator ra = (RangeAggregator) aggregator;
        ra.setStartTime(queryMetric.getStartTime());
      }

      if (aggregator instanceof TimezoneAware) {
        TimezoneAware ta = (TimezoneAware) aggregator;
        ta.setTimeZone(timeZone);
      }

      if (aggregator instanceof GroupByAware) {
        GroupByAware groupByAware = (GroupByAware) aggregator;
        groupByAware.setGroupBys(queryMetric.getGroupBys());
      }

      deserializeProperties(aggContext, jsAggregator, aggName, aggregator);

      validateObject(aggregator, aggContext);

      queryMetric.addAggregator(aggregator);
    }
  }