private void assertEmptyBrokerResponse(BrokerResponse brokerResponse) throws JSONException { Assert.assertEquals(0, brokerResponse.getNumDocsScanned()); Assert.assertEquals(_numAggregations, brokerResponse.getAggregationResults().size()); for (int i = 0; i < _numAggregations; ++i) { Assert.assertEquals( "[\"column11\",\"column10\"]", brokerResponse.getAggregationResults().get(i).getJSONArray("groupByColumns").toString()); Assert.assertEquals( 0, brokerResponse.getAggregationResults().get(i).getJSONArray("groupByResult").length()); } // Assertion on Count assertionOnCount(brokerResponse); }
private void assertBrokerResponse(int numSegments, BrokerResponse brokerResponse) throws JSONException { Assert.assertEquals(10001 * numSegments, brokerResponse.getNumDocsScanned()); Assert.assertEquals(_numAggregations, brokerResponse.getAggregationResults().size()); for (int i = 0; i < _numAggregations; ++i) { Assert.assertEquals( "[\"column11\",\"column10\"]", brokerResponse.getAggregationResults().get(i).getJSONArray("groupByColumns").toString()); Assert.assertEquals( 15, brokerResponse.getAggregationResults().get(i).getJSONArray("groupByResult").length()); } // Assertion on Count assertionOnCount(brokerResponse); // Assertion on Aggregation Results LOGGER.info("brokerResponse = {}", brokerResponse); final List<double[]> aggregationResult = getAggregationResult(numSegments); final List<String[]> groupByResult = getGroupResult(); for (int j = 0; j < _numAggregations; ++j) { final double[] aggResult = aggregationResult.get(j); final String[] groupResult = groupByResult.get(j); for (int i = 0; i < 15; ++i) { Assert.assertEquals( 0, DoubleComparisonUtil.defaultDoubleCompare( aggResult[i], brokerResponse .getAggregationResults() .get(j) .getJSONArray("groupByResult") .getJSONObject(i) .getDouble("value"))); if ((i < 14 && aggResult[i] == aggResult[i + 1]) || (i > 0 && aggResult[i] == aggResult[i - 1])) { // do nothing, as we have multiple groups within same value. } else { Assert.assertEquals( groupResult[i], brokerResponse .getAggregationResults() .get(j) .getJSONArray("groupByResult") .getJSONObject(i) .getString("group")); } } } }
@Test public void testRangeQuery() throws RecognitionException, Exception { String query = "select count(*) from testTable where column1 in ('999983251', '510705831', '1000720716', '1001058817', '1001099410')"; LOGGER.info("running : " + query); final Map<ServerInstance, DataTable> instanceResponseMap = new HashMap<ServerInstance, DataTable>(); final BrokerRequest brokerRequest = RequestConverter.fromJSON(REQUEST_COMPILER.compile(query)); InstanceRequest instanceRequest = new InstanceRequest(1, brokerRequest); instanceRequest.setSearchSegments(new ArrayList<String>()); instanceRequest.getSearchSegments().add(segmentName); final DataTable instanceResponse = QUERY_EXECUTOR.processQuery(instanceRequest); instanceResponseMap.clear(); instanceResponseMap.put(new ServerInstance("localhost:0000"), instanceResponse); final BrokerResponse brokerResponse = REDUCE_SERVICE.reduceOnDataTable(brokerRequest, instanceResponseMap); LOGGER.info("BrokerResponse is " + brokerResponse.getAggregationResults().get(0)); Assert.assertEquals(brokerResponse.getAggregationResults().get(0).getInt("value"), 14); Assert.assertEquals(brokerResponse.getNumDocsScanned(), 14); }
private void assertBrokerResponse(int numSegments, BrokerResponse brokerResponse) throws JSONException { Assert.assertEquals(10001 * numSegments, brokerResponse.getNumDocsScanned()); final int groupSize = 15; assertBrokerResponse(brokerResponse, groupSize); // Assertion on Aggregation Results final List<double[]> aggregationResult = getAggregationResult(numSegments); final List<String[]> groupByResult = getGroupResult(); for (int j = 0; j < _numAggregations; ++j) { final double[] aggResult = aggregationResult.get(j); final String[] groupResult = groupByResult.get(j); for (int i = 0; i < 15; ++i) { Assert.assertEquals( 0, DoubleComparisonUtil.defaultDoubleCompare( aggResult[i], brokerResponse .getAggregationResults() .get(j) .getJSONArray("groupByResult") .getJSONObject(i) .getDouble("value"))); if ((i < 14 && aggResult[i] == aggResult[i + 1]) || (i > 0 && aggResult[i] == aggResult[i - 1])) { // do nothing, as we have multiple groups within same value. } else { Assert.assertEquals( groupResult[i], brokerResponse .getAggregationResults() .get(j) .getJSONArray("groupByResult") .getJSONObject(i) .getString("group")); } } } }
@Test public void testMatchAllQuery() throws RecognitionException, Exception { String query = "select count(*),sum(count) from testTable "; LOGGER.info("running : " + query); final Map<ServerInstance, DataTable> instanceResponseMap = new HashMap<ServerInstance, DataTable>(); final BrokerRequest brokerRequest = RequestConverter.fromJSON(REQUEST_COMPILER.compile(query)); InstanceRequest instanceRequest = new InstanceRequest(1, brokerRequest); instanceRequest.setSearchSegments(new ArrayList<String>()); instanceRequest.getSearchSegments().add(segmentName); final DataTable instanceResponse = QUERY_EXECUTOR.processQuery(instanceRequest); instanceResponseMap.clear(); instanceResponseMap.put(new ServerInstance("localhost:0000"), instanceResponse); final BrokerResponse brokerResponse = REDUCE_SERVICE.reduceOnDataTable(brokerRequest, instanceResponseMap); LOGGER.info("BrokerResponse is " + brokerResponse); LOGGER.info("BrokerResponse is " + brokerResponse.getAggregationResults().get(0)); LOGGER.info("BrokerResponse is " + brokerResponse.getAggregationResults().get(1)); Assert.assertEquals(brokerResponse.getAggregationResults().get(0).getInt("value"), 100000); Assert.assertEquals( brokerResponse.getAggregationResults().get(1).getDouble("value"), 8.90662862E13); Assert.assertEquals(brokerResponse.getNumDocsScanned(), 100000); }
private void assertEmptyBrokerResponse(BrokerResponse brokerResponse) throws JSONException { Assert.assertEquals(0, brokerResponse.getNumDocsScanned()); final int groupSize = 0; assertBrokerResponse(brokerResponse, groupSize); }