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/DistinctActionTest.java
test_class.identifier: DistinctActionTest
test_case.body: @Test
      public void testDistinctDesc() throws QueryStoreException {
          DistinctRequest distinctRequest = new DistinctRequest();
          distinctRequest.setTable(TestUtils.TEST_TABLE_NAME);
          ResultSort resultSort = new ResultSort();
          resultSort.setField("version");
          resultSort.setOrder(ResultSort.Order.desc);
          distinctRequest.setNesting(Arrays.asList(resultSort));
  
          DistinctResponse expectedResponse = new DistinctResponse();
          expectedResponse.setHeaders(Arrays.asList("version"));
  
          List<List<String>> listResponse = new ArrayList<List<String>>();
          listResponse.add(Arrays.asList("3"));
          listResponse.add(Arrays.asList("2"));
          listResponse.add(Arrays.asList("1"));
          expectedResponse.setResult(listResponse);
  
          DistinctResponse distinctResponse = DistinctResponse.class.cast(queryExecutor.execute(distinctRequest));
          assertNotNull(distinctResponse);
          assertEquals(expectedResponse, distinctResponse);
      }
test_case.class_method_signature: DistinctActionTest.testDistinctDesc()
test_case.full_signature: @Test public void testDistinctDesc()
test_case.identifier: testDistinctDesc
test_case.invocations: setTable setField setOrder setNesting asList setHeaders asList add asList add asList add asList setResult cast execute assertNotNull assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDistinctDesc()
focal_class.declarator: logger = LoggerFactory.getLogger(GroupAction.class.getSimpleName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(GroupAction.class.getSimpleName());
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/DistinctAction.java
focal_class.identifier: DistinctAction
focal_class.class_method_signature: DistinctAction.DistinctAction(DistinctRequest request,
                            TableMetadataManager tableMetadataManager,
                            DataStore dataStore,
                            QueryStore queryStore,
                            ElasticsearchConnection connection,
                            String cacheToken)
focal_class.full_signature: public  DistinctAction(DistinctRequest request,
                            TableMetadataManager tableMetadataManager,
                            DataStore dataStore,
                            QueryStore queryStore,
                            ElasticsearchConnection connection,
                            String cacheToken)
focal_class.identifier: DistinctAction
focal_class.modifiers: public
focal_class.parameters: (DistinctRequest request,
                            TableMetadataManager tableMetadataManager,
                            DataStore dataStore,
                            QueryStore queryStore,
                            ElasticsearchConnection connection,
                            String cacheToken)
focal_class.signature:  DistinctAction(DistinctRequest request,
                            TableMetadataManager tableMetadataManager,
                            DataStore dataStore,
                            QueryStore queryStore,
                            ElasticsearchConnection connection,
                            String cacheToken)
focal_class.class_method_signature: DistinctAction.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: DistinctAction.execute(DistinctRequest request)
focal_class.full_signature: @Override public ActionResponse execute(DistinctRequest request)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (DistinctRequest request)
focal_class.return: ActionResponse
focal_class.signature: ActionResponse execute(DistinctRequest request)
focal_class.class_method_signature: DistinctAction.getDistinctResponse(DistinctRequest request, Aggregations aggregations)
focal_class.full_signature: private DistinctResponse getDistinctResponse(DistinctRequest request, Aggregations aggregations)
focal_class.identifier: getDistinctResponse
focal_class.modifiers: private
focal_class.parameters: (DistinctRequest request, Aggregations aggregations)
focal_class.return: DistinctResponse
focal_class.signature: DistinctResponse getDistinctResponse(DistinctRequest request, Aggregations aggregations)
focal_class.class_method_signature: DistinctAction.flatten(String parentKey, List<String> fields, List<List<String>> responseList, Aggregations aggregations)
focal_class.full_signature: private void flatten(String parentKey, List<String> fields, List<List<String>> responseList, Aggregations aggregations)
focal_class.identifier: flatten
focal_class.modifiers: private
focal_class.parameters: (String parentKey, List<String> fields, List<List<String>> responseList, Aggregations aggregations)
focal_class.return: void
focal_class.signature: void flatten(String parentKey, List<String> fields, List<List<String>> responseList, Aggregations aggregations)
focal_class.class_method_signature: DistinctAction.getProperKey(String parentKey, String currentKey)
focal_class.full_signature: private String getProperKey(String parentKey, String currentKey)
focal_class.identifier: getProperKey
focal_class.modifiers: private
focal_class.parameters: (String parentKey, String currentKey)
focal_class.return: String
focal_class.signature: String getProperKey(String parentKey, String currentKey)
focal_class.class_method_signature: DistinctAction.getValueList(String parentKey, String currentKey)
focal_class.full_signature: private List<String> getValueList(String parentKey, String currentKey)
focal_class.identifier: getValueList
focal_class.modifiers: private
focal_class.parameters: (String parentKey, String currentKey)
focal_class.return: List<String>
focal_class.signature: List<String> getValueList(String parentKey, String currentKey)
focal_class.superclass: extends Action<DistinctRequest>
focal_method.body: @Override
      public ActionResponse execute(DistinctRequest request) throws QueryStoreException {
          request.setTable(ElasticsearchUtils.getValidTableName(request.getTable()));
          if (null == request.getFilters()) {
              request.setFilters(Lists.<Filter>newArrayList(new AnyFilter(request.getTable())));
          }
          if (request.getTable() == null) {
              throw new QueryStoreException(QueryStoreException.ErrorCode.INVALID_REQUEST, "Invalid Table");
          }
          try {
              SearchRequestBuilder query = getConnection().getClient().prepareSearch(ElasticsearchUtils.getIndices(
                      request.getTable(), request));
              TermsBuilder rootBuilder = null;
              TermsBuilder termsBuilder = null;
  
              for (ResultSort nestedField : request.getNesting()) {
                  if (nestedField.getField() == null || nestedField.getField().trim().isEmpty()) {
                      throw new QueryStoreException(QueryStoreException.ErrorCode.INVALID_REQUEST, "Illegal Nesting Parameters");
                  }
  
                  String aggregationKey = Utils.sanitizeFieldForAggregation(nestedField.getField());
                  Terms.Order order = (nestedField.getOrder() == ResultSort.Order.desc) ? Terms.Order.term(false) : Terms.Order.term(true);
  
                  if (null == termsBuilder) {
                      termsBuilder = AggregationBuilders.terms(aggregationKey).field(nestedField.getField()).order(order);
                  } else {
                      TermsBuilder tempBuilder = AggregationBuilders.terms(aggregationKey).field(nestedField.getField()).order(order);
                      termsBuilder.subAggregation(tempBuilder);
                      termsBuilder = tempBuilder;
                  }
                  termsBuilder.size(0);
                  if (null == rootBuilder) {
                      rootBuilder = termsBuilder;
                  }
              }
              query.setQuery(new ElasticSearchQueryGenerator(FilterCombinerType.and)
                      .genFilter(request.getFilters()))
                      .setSearchType(SearchType.COUNT)
                      .addAggregation(rootBuilder);
              SearchResponse response = query.execute().actionGet();
              Aggregations aggregations = response.getAggregations();
              // Check if any aggregation is present or not
              if (aggregations == null) {
                  logger.error("Null response for Group. Request : " + request.toString());
                  return new DistinctResponse(new ArrayList<String>(), new ArrayList<List<String>>());
              }
              return getDistinctResponse(request, aggregations);
          } catch (QueryStoreException ex) {
              throw ex;
          } catch (Exception e) {
              logger.error("Error running grouping: ", e);
              throw new QueryStoreException(QueryStoreException.ErrorCode.QUERY_EXECUTION_ERROR,
                      "Error running group query.", e);
          }
      }
focal_method.class_method_signature: DistinctAction.execute(DistinctRequest request)
focal_method.full_signature: @Override public ActionResponse execute(DistinctRequest request)
focal_method.identifier: execute
focal_method.invocations: setTable getValidTableName getTable getFilters setFilters newArrayList getTable getTable prepareSearch getClient getConnection getIndices getTable getNesting getField isEmpty trim getField sanitizeFieldForAggregation getField getOrder term term order field terms getField order field terms getField subAggregation size addAggregation setSearchType setQuery genFilter getFilters actionGet execute getAggregations error toString getDistinctResponse error
focal_method.modifiers: @Override public
focal_method.parameters: (DistinctRequest request)
focal_method.return: ActionResponse
focal_method.signature: ActionResponse execute(DistinctRequest request)