class HistogramAction extends Action<HistogramRequest> {

    @Override
    public ActionResponse execute(HistogramRequest parameter) throws QueryStoreException {
        parameter.setTable(ElasticsearchUtils.getValidTableName(parameter.getTable()));
        if (null == parameter.getFilters()) {
            parameter.setFilters(Lists.<Filter>newArrayList(new AnyFilter(parameter.getTable())));
        }

        if (parameter.getField() == null || parameter.getField().trim().isEmpty()) {
            throw new QueryStoreException(QueryStoreException.ErrorCode.INVALID_REQUEST, "Illegal Nesting Parameters");
        }

        try {
            /*if(!tableManager.exists(query.getTable())) {
                throw new QueryStoreException(QueryStoreException.ErrorCode.NO_SUCH_TABLE,
                        "There is no table called: " + query.getTable());
            }*/
            DateHistogram.Interval interval = null;
            switch (parameter.getPeriod()) {
                case seconds:
                    interval = DateHistogram.Interval.SECOND;
                    break;
                case minutes:
                    interval = DateHistogram.Interval.MINUTE;
                    break;
                case hours:
                    interval = DateHistogram.Interval.HOUR;
                    break;
                case days:
                    interval = DateHistogram.Interval.DAY;
                    break;
            }

            String dateHistogramKey = Utils.sanitizeFieldForAggregation(parameter.getField());
            SearchResponse response = getConnection().getClient().prepareSearch(
                    ElasticsearchUtils.getIndices(parameter.getTable(), parameter))
                    .setTypes(ElasticsearchUtils.TYPE_NAME)
                    .setQuery(new ElasticSearchQueryGenerator(FilterCombinerType.and)
                            .genFilter(parameter.getFilters()))
                    .setSize(0)
                    .setSearchType(SearchType.COUNT)
                    .addAggregation(AggregationBuilders.dateHistogram(dateHistogramKey)
                            .field(parameter.getField())
                            .interval(interval))
                    .execute()
                    .actionGet();
            Aggregations aggregations = response.getAggregations();
            if (aggregations == null) {
                logger.error("Null response for Histogram. Request : " + parameter.toString());
                return new HistogramResponse(Collections.<HistogramResponse.Count>emptyList());
            }
            DateHistogram dateHistogram = aggregations.get(dateHistogramKey);
            Collection<? extends DateHistogram.Bucket> buckets = dateHistogram.getBuckets();
            List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(buckets.size());
            for (DateHistogram.Bucket bucket : buckets) {
                HistogramResponse.Count count = new HistogramResponse.Count(
                        bucket.getKeyAsNumber(), bucket.getDocCount());
                counts.add(count);
            }
            return new HistogramResponse(counts);
        } catch (QueryStoreException ex) {
            throw ex;
        } catch (Exception e) {
            throw new QueryStoreException(QueryStoreException.ErrorCode.HISTOGRAM_GENERATION_ERROR,
                    "Malformed query", e);
        }
    }

    public  HistogramAction(HistogramRequest parameter,
                           TableMetadataManager tableMetadataManager,
                           DataStore dataStore,
                           QueryStore queryStore,
                           ElasticsearchConnection connection,
                           String cacheToken);

}