test_class.declarator: mapper = new ObjectMapper()
test_class.modifier: private final
test_class.original_string: private final ObjectMapper mapper = new ObjectMapper();
test_class.type: ObjectMapper
test_class.var_name: mapper
test_class.declarator: queryExecutor
test_class.modifier: private
test_class.original_string: private QueryExecutor queryExecutor;
test_class.type: QueryExecutor
test_class.var_name: queryExecutor
test_class.declarator: elasticsearchServer
test_class.modifier: private
test_class.original_string: private MockElasticsearchServer elasticsearchServer;
test_class.type: MockElasticsearchServer
test_class.var_name: elasticsearchServer
test_class.declarator: hazelcastInstance
test_class.modifier: private
test_class.original_string: private HazelcastInstance hazelcastInstance;
test_class.type: HazelcastInstance
test_class.var_name: hazelcastInstance
test_class.file: real-time/foxtrot/foxtrot-core/src/test/java/com/flipkart/foxtrot/core/querystore/actions/CountActionTest.java
test_class.identifier: CountActionTest
test_case.body: @Test
      public void testCount() throws QueryStoreException {
          CountRequest countRequest = new CountRequest();
          countRequest.setTable(TestUtils.TEST_TABLE_NAME);
          countRequest.setField("os");
          countRequest.setDistinct(false);
          CountResponse countResponse = CountResponse.class.cast(queryExecutor.execute(countRequest));
  
          assertNotNull(countResponse);
          assertEquals(11, countResponse.getCount());
      }
test_case.class_method_signature: CountActionTest.testCount()
test_case.full_signature: @Test public void testCount()
test_case.identifier: testCount
test_case.invocations: setTable setField setDistinct cast execute assertNotNull assertEquals getCount
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCount()
focal_class.declarator: logger = LoggerFactory.getLogger(CountAction.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(CountAction.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: real-time/foxtrot/foxtrot-core/src/main/java/com/flipkart/foxtrot/core/querystore/actions/CountAction.java
focal_class.identifier: CountAction
focal_class.class_method_signature: CountAction.CountAction(CountRequest parameter,
                         TableMetadataManager tableMetadataManager,
                         DataStore dataStore,
                         QueryStore queryStore,
                         ElasticsearchConnection connection,
                         String cacheToken)
focal_class.full_signature: public  CountAction(CountRequest parameter,
                         TableMetadataManager tableMetadataManager,
                         DataStore dataStore,
                         QueryStore queryStore,
                         ElasticsearchConnection connection,
                         String cacheToken)
focal_class.identifier: CountAction
focal_class.modifiers: public
focal_class.parameters: (CountRequest parameter,
                         TableMetadataManager tableMetadataManager,
                         DataStore dataStore,
                         QueryStore queryStore,
                         ElasticsearchConnection connection,
                         String cacheToken)
focal_class.signature:  CountAction(CountRequest parameter,
                         TableMetadataManager tableMetadataManager,
                         DataStore dataStore,
                         QueryStore queryStore,
                         ElasticsearchConnection connection,
                         String cacheToken)
focal_class.class_method_signature: CountAction.getRequestCacheKey()
focal_class.full_signature: @Override protected String getRequestCacheKey()
focal_class.identifier: getRequestCacheKey
focal_class.modifiers: @Override protected
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getRequestCacheKey()
focal_class.class_method_signature: CountAction.execute(CountRequest parameter)
focal_class.full_signature: @Override public ActionResponse execute(CountRequest parameter)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (CountRequest parameter)
focal_class.return: ActionResponse
focal_class.signature: ActionResponse execute(CountRequest parameter)
focal_class.superclass: extends Action<CountRequest>
focal_method.body: @Override
      public ActionResponse execute(CountRequest parameter) throws QueryStoreException {
          parameter.setTable(ElasticsearchUtils.getValidTableName(parameter.getTable()));
          if (null == parameter.getFilters() || parameter.getFilters().isEmpty()) {
              parameter.setFilters(Lists.<Filter>newArrayList(new AnyFilter(parameter.getTable())));
          }
  
          // Null field implies complete doc count
          if (parameter.getField() != null) {
              parameter.getFilters().add(new ExistsFilter(parameter.getField()));
          }
  
          try {
              if (parameter.isDistinct()){
                  SearchRequestBuilder query = getConnection().getClient()
                          .prepareSearch(ElasticsearchUtils.getIndices(parameter.getTable(), parameter))
                          .setSearchType(SearchType.COUNT)
                          .setQuery(new ElasticSearchQueryGenerator(FilterCombinerType.and)
                                  .genFilter(parameter.getFilters()))
                          .addAggregation(AggregationBuilders
                                  .cardinality(Utils.sanitizeFieldForAggregation(parameter.getField()))
                                  .field(parameter.getField())
                          );
                  SearchResponse response = query.execute().actionGet();
                  Aggregations aggregations = response.getAggregations();
                  Cardinality cardinality = aggregations.get(Utils.sanitizeFieldForAggregation(parameter.getField()));
                  if (cardinality == null){
                      return new CountResponse(0);
                  } else {
                      return new CountResponse(cardinality.getValue());
                  }
              } else {
                  CountRequestBuilder countRequestBuilder = getConnection().getClient()
                          .prepareCount(ElasticsearchUtils.getIndices(parameter.getTable(), parameter))
                          .setQuery(new ElasticSearchQueryGenerator(FilterCombinerType.and).genFilter(parameter.getFilters()));
                  org.elasticsearch.action.count.CountResponse countResponse = countRequestBuilder.execute().actionGet();
                  return new CountResponse(countResponse.getCount());
              }
          } catch (Exception e) {
              logger.error("Error running count: ", e);
              throw new QueryStoreException(QueryStoreException.ErrorCode.QUERY_EXECUTION_ERROR,
                      "Error running count query.", e);
          }
      }
focal_method.class_method_signature: CountAction.execute(CountRequest parameter)
focal_method.full_signature: @Override public ActionResponse execute(CountRequest parameter)
focal_method.identifier: execute
focal_method.invocations: setTable getValidTableName getTable getFilters isEmpty getFilters setFilters newArrayList getTable getField add getFilters getField isDistinct addAggregation setQuery setSearchType prepareSearch getClient getConnection getIndices getTable genFilter getFilters field cardinality sanitizeFieldForAggregation getField getField actionGet execute getAggregations get sanitizeFieldForAggregation getField getValue setQuery prepareCount getClient getConnection getIndices getTable genFilter getFilters actionGet execute getCount error
focal_method.modifiers: @Override public
focal_method.parameters: (CountRequest parameter)
focal_method.return: ActionResponse
focal_method.signature: ActionResponse execute(CountRequest parameter)