MultiTimeQueryAction extends Action<MultiTimeQueryRequest> { @Override public ActionResponse execute(MultiTimeQueryRequest parameter) { MultiTimeQueryResponse multiTimeQueryResponse = new MultiTimeQueryResponse(); multiTimeQueryResponse.setResponses(((MultiQueryResponse)action.execute(multiQueryRequest)).getResponses()); return multiTimeQueryResponse; } MultiTimeQueryAction(MultiTimeQueryRequest parameter, AnalyticsLoader analyticsLoader); @Override void preprocess(); @Override String getMetricKey(); @Override String getRequestCacheKey(); @Override void validateImpl(MultiTimeQueryRequest parameter); @Override ActionResponse execute(MultiTimeQueryRequest parameter); @Override ActionRequestBuilder getRequestBuilder(MultiTimeQueryRequest parameter); @Override ActionResponse getResponse(org.elasticsearch.action.ActionResponse multiSearchResponse, MultiTimeQueryRequest parameter);  }
@Test public void testMultiTimeQuery() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.asc); resultSort.setField("_timestamp"); query.setSort(resultSort); BetweenFilter betweenFilter = new BetweenFilter("_timestamp", 1397658117000L, 1397658118005L, false); query.setFilters(Arrays.asList(betweenFilter)); Duration duration = Duration.days(1); MultiTimeQueryRequest multiTimeQueryRequest = new MultiTimeQueryRequest(1, duration, query); ActionResponse actionResponse = getQueryExecutor().execute(multiTimeQueryRequest); MultiTimeQueryResponse multiTimeQueryResponse = null; if(actionResponse instanceof MultiTimeQueryResponse) { multiTimeQueryResponse = (MultiTimeQueryResponse)actionResponse; } assertNotNull(multiTimeQueryResponse); QueryResponse queryResponse = (QueryResponse)multiTimeQueryResponse.getResponses() .get("1397658117000"); assertEquals(9, queryResponse.getTotalHits()); }
@Test public void testQueryNoFilterAscending() throws FoxtrotException, JsonProcessingException { Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.asc); resultSort.setField("_timestamp"); query.setSort(resultSort); BetweenFilter betweenFilter = new BetweenFilter("_timestamp", 1397658117000L, 1397658118005L, false); query.setFilters(Arrays.asList(betweenFilter)); Duration duration = Duration.days(1); MultiTimeQueryRequest multiTimeQueryRequest = new MultiTimeQueryRequest(1, duration, query); List<Document> documents = new ArrayList<>(); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper())); documents.add( TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); MultiTimeQueryResponse multiTimeQueryResponse = MultiTimeQueryResponse.class.cast( getQueryExecutor().execute(multiTimeQueryRequest)); for(String key : multiTimeQueryResponse.getResponses() .keySet()) { compare(documents, ((QueryResponse)multiTimeQueryResponse.getResponses() .get(key)).getDocuments()); } }