Search in sources :

Example 1 with AggregationOperation

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());
}
Also used : DataSet(org.talend.dataprep.api.dataset.DataSet) AggregationParameters(org.talend.dataprep.transformation.aggregation.api.AggregationParameters) AggregationOperation(org.talend.dataprep.transformation.aggregation.api.AggregationOperation) Test(org.junit.Test) TransformationBaseTest(org.talend.dataprep.transformation.TransformationBaseTest)

Example 2 with AggregationOperation

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");
    }
}
Also used : AggregationOperation(org.talend.dataprep.transformation.aggregation.api.AggregationOperation)

Aggregations

AggregationOperation (org.talend.dataprep.transformation.aggregation.api.AggregationOperation)2 Test (org.junit.Test)1 DataSet (org.talend.dataprep.api.dataset.DataSet)1 TransformationBaseTest (org.talend.dataprep.transformation.TransformationBaseTest)1 AggregationParameters (org.talend.dataprep.transformation.aggregation.api.AggregationParameters)1