use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class AggregationOperationsTest method testDistributionStrategy.
@Test
public void testDistributionStrategy() {
Aggregation aggregation = new Aggregation();
BulletConfig config = new BulletConfig();
aggregation.setType(Aggregation.Type.DISTRIBUTION);
aggregation.setFields(singletonMap("field", "foo"));
aggregation.configure(config);
Assert.assertEquals(AggregationOperations.findStrategy(aggregation, config).getClass(), Distribution.class);
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class CountDistinctTest method makeAggregation.
public static Aggregation makeAggregation(Map<String, String> fields, Map<String, Object> attributes) {
Aggregation aggregation = new Aggregation();
aggregation.setFields(fields);
aggregation.setAttributes(attributes);
return aggregation;
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class CountDistinctTest method testFailValidateOnCountDistinctFieldsMissing.
@Test
public void testFailValidateOnCountDistinctFieldsMissing() {
Aggregation aggregation = makeAggregation(null, null);
CountDistinct countDistinct = makeCountDistinct(new BulletConfig(), aggregation, null);
Optional<List<BulletError>> optionalErrors = countDistinct.initialize();
Assert.assertTrue(optionalErrors.isPresent());
List<BulletError> errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Strategy.REQUIRES_FIELD_ERROR);
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class DistributionTest method makeDistribution.
public static Distribution makeDistribution(BulletConfig configuration, Map<String, Object> attributes, String field, int size, List<Map.Entry<Concept, String>> metadata) {
Aggregation aggregation = new Aggregation();
aggregation.setFields(Collections.singletonMap(field, field));
aggregation.setSize(size);
aggregation.setAttributes(attributes);
Distribution distribution = new Distribution(aggregation, addMetadata(configuration, metadata));
distribution.initialize();
return distribution;
}
use of com.yahoo.bullet.parsing.Aggregation in project bullet-core by yahoo.
the class DistributionTest method testRangeInitialization.
@Test
public void testRangeInitialization() {
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;
// start < 0
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, -1, 1, 0.5));
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);
// end > 1
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 0, 2, 0.1));
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);
// both out of range
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 3, 4, 0.1));
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.QUANTILE, 0, 1, 0.2));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
// start null
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, null, 0.5, 0.2, 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);
// end null
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 1.0, null, 0.2, 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);
// increment null
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 1.0, 2.0, 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);
// end < start
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 25, -2, 0.5));
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.PMF, 25, 200, 0.5));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
}
Aggregations