use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class CountDistinctTest method testCombiningAndConsuming.
@Test
public void testCombiningAndConsuming() {
BulletConfig config = makeConfiguration(4, 1024);
CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("field"));
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
byte[] aggregate = countDistinct.getData();
// New one
countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("field"));
IntStream.range(0, 768).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
countDistinct.combine(aggregate);
Clip clip = countDistinct.getResult();
Map<String, Object> meta = clip.getMeta().asMap();
Assert.assertEquals(meta.size(), 0);
Assert.assertEquals(clip.getRecords().size(), 1);
BulletRecord actual = clip.getRecords().get(0);
BulletRecord expected = RecordBox.get().add("myCount", 768.0).getRecord();
Assert.assertEquals(actual, expected);
Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
}
use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class CountDistinctTest method testResetting.
@Test
public void testResetting() {
BulletConfig config = makeConfiguration(4, 1024);
CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("field"));
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
Clip clip = countDistinct.getResult();
Map<String, Object> meta = clip.getMeta().asMap();
Assert.assertEquals(meta.size(), 0);
Assert.assertEquals(clip.getRecords().size(), 1);
BulletRecord actual = clip.getRecords().get(0);
BulletRecord expected = RecordBox.get().add("myCount", 256.0).getRecord();
Assert.assertEquals(actual, expected);
Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
countDistinct.reset();
IntStream.range(0, 15).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
clip = countDistinct.getResult();
meta = clip.getMeta().asMap();
Assert.assertEquals(meta.size(), 0);
Assert.assertEquals(clip.getRecords().size(), 1);
actual = clip.getRecords().get(0);
expected = RecordBox.get().add("myCount", 15.0).getRecord();
Assert.assertEquals(actual, expected);
Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
}
use of com.yahoo.bullet.common.BulletConfig 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.common.BulletConfig 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());
}
use of com.yahoo.bullet.common.BulletConfig 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());
}
Aggregations