use of org.talend.dataprep.transformation.aggregation.api.AggregationOperation in project data-prep by Talend.
the class AggregationServiceTest method shouldNotAggregateBecauseNoGroupBy.
@Test(expected = TDPException.class)
public void shouldNotAggregateBecauseNoGroupBy() {
final AggregationParameters params = new AggregationParameters();
params.addOperation(new AggregationOperation("0001", Operator.AVERAGE));
service.aggregate(params, new DataSet());
}
use of org.talend.dataprep.transformation.aggregation.api.AggregationOperation in project data-prep by Talend.
the class AggregatorFactory method get.
/**
* Return the first aggregator out of the given parameters.
*
* @param parameters the aggregation parameters.
* @return the first aggregator out of the given parameters or an empty aggregator if there's none.
*/
public Aggregator get(AggregationParameters parameters) {
// return empty aggregator if empty
if (parameters.getOperations().isEmpty() || parameters.getGroupBy().isEmpty()) {
throw new IllegalArgumentException("Invalid aggregation parameters");
}
final AggregationOperation operation = parameters.getOperations().get(0);
String groupBy = parameters.getGroupBy().get(0);
switch(operation.getOperator()) {
case AVERAGE:
return new Average(groupBy, operation.getColumnId());
case MIN:
return new Min(groupBy, operation.getColumnId());
case MAX:
return new Max(groupBy, operation.getColumnId());
case SUM:
return new Sum(groupBy, operation.getColumnId());
default:
throw new IllegalArgumentException("Operation '" + operation.getOperator() + "' not supported");
}
}
Aggregations