@Test public void testDistinctFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.DISTINCT); Object result = sf.aggregate(listOfStrings); assertThat(result).isEqualTo(3d); } }
@Test public void testMaxFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.MAX); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(5d); }
@Test public void testCountFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.COUNT); Object result = sf.aggregate(listOfStrings); assertThat(result).isEqualTo(5d); }
@Test public void testMinFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.MIN); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(1d); }
@Test public void testSumFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.SUM); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(15d); }
@Test public void testAvgFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.AVERAGE); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(3d); }
@Test public void testMinFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.MIN); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(1d); }
@Test public void testDistinctFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.DISTINCT); Object result = sf.aggregate(listOfStrings); assertThat(result).isEqualTo(3d); } }
@Test public void testSumFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.SUM); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(15d); }
@Test public void testMaxFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.MAX); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(5d); }
@Test public void testAvgFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.AVERAGE); Object result = sf.aggregate(listOfNumbers); assertThat(result).isEqualTo(3d); }
@Test public void testCountFunction() throws Exception { AggregateFunction sf = aggregateFunctionManager.getFunctionByType(AggregateFunctionType.COUNT); Object result = sf.aggregate(listOfStrings); assertThat(result).isEqualTo(5d); }
private Object _calculateFunction(DataColumn column, AggregateFunctionType type, DataSetIndexNode index) { // Preconditions if (type == null) { throw new IllegalArgumentException("No aggregation function specified for the column: " + column.getId()); } // Look into the index first if (index != null) { Object sv = index.getAggValue(column.getId(), type); if (sv != null) { return sv; } } // Do the aggregate calculations. chronometer.start(); AggregateFunction function = aggregateFunctionManager.getFunctionByType(type); Object aggValue = function.aggregate(column.getValues(), index.getRows()); chronometer.stop(); // Index the result if (index != null) { index.indexAggValue(column.getId(), type, aggValue, chronometer.elapsedTime()); } return aggValue; }