use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class DistributionTest method testNumberOfPointsInitialization.
@Test
public void testNumberOfPointsInitialization() {
Aggregation aggregation = new Aggregation();
aggregation.setSize(20);
aggregation.setFields(Collections.singletonMap("foo", "bar"));
Distribution distribution = new Distribution(aggregation, new BulletConfig());
Optional<List<BulletError>> optionalErrors;
List<BulletError> errors;
// Null points
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, null, null, null, null, null));
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
// Negative points
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, -10));
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 2);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
Assert.assertEquals(errors.get(1), Distribution.REQUIRES_POINTS_PROPER_RANGE);
// 0 points
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 0));
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 2);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
Assert.assertEquals(errors.get(1), Distribution.REQUIRES_POINTS_PROPER_RANGE);
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 0));
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 1));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class GroupAllTest method makeAggregation.
public static Aggregation makeAggregation(Map<String, Object> attributes) {
Aggregation aggregation = new Aggregation();
aggregation.setType(Aggregation.Type.GROUP);
// Does not matter
aggregation.setSize(1);
aggregation.setAttributes(attributes);
return aggregation;
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class GroupAllTest method makeGroupAll.
public static GroupAll makeGroupAll(List<GroupOperation> groupOperations) {
Aggregation aggregation = mock(Aggregation.class);
List<Map<String, String>> operations = groupOperations.stream().map(AggregationUtils::makeGroupOperation).collect(Collectors.toList());
when(aggregation.getAttributes()).thenReturn(makeAttributes(operations));
GroupAll all = new GroupAll(aggregation);
all.initialize();
return all;
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class GroupAllTest method testAttributeOperationBadFormat.
@Test
public void testAttributeOperationBadFormat() {
Aggregation aggregation = makeAggregation(singletonMap(GroupOperation.OPERATIONS, asList("foo")));
GroupAll groupAll = new GroupAll(aggregation);
Optional<List<BulletError>> optionalErrors = groupAll.initialize();
Assert.assertTrue(optionalErrors.isPresent());
List<BulletError> errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), GroupOperation.REQUIRES_FIELD_OR_OPERATION_ERROR);
}
Aggregations