use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class DistributionTest method testResetting.
@Test
public void testResetting() {
Distribution distribution = makeDistribution(Distribution.Type.CDF, asList(5.0, 2.5));
IntStream.range(0, 25).mapToDouble(i -> (i * 0.1)).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 2.5 + END_EXCLUSIVE).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 1.0).getRecord();
BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 5.0 + END_EXCLUSIVE).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 1.0).getRecord();
BulletRecord expectedC = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 1.0).getRecord();
Clip result = distribution.getResult();
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 3);
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(records.get(2), expectedC);
Assert.assertEquals(distribution.getRecords(), records);
Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
distribution.reset();
IntStream.range(50, 100).mapToDouble(i -> (i * 0.1)).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 2.5 + END_EXCLUSIVE).add(COUNT_FIELD, 0.0).add(PROBABILITY_FIELD, 0.0).getRecord();
expectedB = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 5.0 + END_EXCLUSIVE).add(COUNT_FIELD, 0.0).add(PROBABILITY_FIELD, 0.0).getRecord();
expectedC = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 1.0).getRecord();
result = distribution.getResult();
records = result.getRecords();
Assert.assertEquals(records.size(), 3);
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(records.get(2), expectedC);
Assert.assertEquals(distribution.getRecords(), records);
Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class DistributionTest method testPMF.
@Test
public void testPMF() {
Distribution distribution = makeDistribution(Distribution.Type.PMF, asList(5.0, 2.5));
IntStream.range(0, 100).mapToDouble(i -> (i * 0.1)).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
Clip result = distribution.getResult();
Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
Assert.assertEquals(metadata.size(), 7);
Assert.assertFalse((Boolean) metadata.get("isEst"));
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 3);
BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 2.5 + END_EXCLUSIVE).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 0.25).getRecord();
BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 2.5 + SEPARATOR + 5.0 + END_EXCLUSIVE).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 0.25).getRecord();
BulletRecord expectedC = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 5.0 + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 0.5).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(records.get(2), expectedC);
Assert.assertEquals(distribution.getRecords(), result.getRecords());
Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class DistributionTest method testNegativeSize.
@Test
public void testNegativeSize() {
// MAX_POINTS is configured to -1 and we will use the min BulletConfig.DEFAULT_DISTRIBUTION_AGGREGATION_MAX_POINTS
// and aggregation size, which is 1
Distribution distribution = makeDistribution(makeConfiguration(-1, 128), makeAttributes(Distribution.Type.PMF, 10L), "field", 1, ALL_METADATA);
IntStream.range(0, 100).mapToDouble(i -> i).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
Clip result = distribution.getResult();
Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
Assert.assertEquals(metadata.size(), 7);
Assert.assertFalse((Boolean) metadata.get("isEst"));
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 2);
BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 0.0 + END_EXCLUSIVE).add(COUNT_FIELD, 0.0).add(PROBABILITY_FIELD, 0.0).getRecord();
BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 0.0 + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 100.0).add(PROBABILITY_FIELD, 1.0).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(distribution.getRecords(), result.getRecords());
Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupAllTest method testSum.
@Test
public void testSum() {
GroupAll groupAll = makeGroupAll(makeGroupOperation(GroupOperation.GroupOperationType.SUM, "someField", "sum"));
Assert.assertNotNull(groupAll.getData());
groupAll.consume(RecordBox.get().addNull("someField").getRecord());
BulletRecord expected = RecordBox.get().addNull("sum").getRecord();
Assert.assertEquals(groupAll.getResult().getRecords().get(0), expected);
groupAll.consume(RecordBox.get().add("someField", -4.8).getRecord());
groupAll.consume(RecordBox.get().add("someField", -8).getRecord());
groupAll.consume(RecordBox.get().add("someField", 51.44).getRecord());
expected = RecordBox.get().add("sum", 38.64).getRecord();
Assert.assertEquals(groupAll.getResult().getRecords().get(0), expected);
groupAll.consume(RecordBox.get().addNull("someField").getRecord());
expected = RecordBox.get().add("sum", 38.64).getRecord();
Assert.assertEquals(groupAll.getResult().getRecords().get(0), expected);
groupAll.consume(RecordBox.get().add("someField", 88.0).getRecord());
expected = RecordBox.get().add("sum", 126.64).getRecord();
Assert.assertEquals(groupAll.getResult().getRecords().get(0), expected);
Assert.assertEquals(groupAll.getResult().getRecords().size(), 1);
Assert.assertEquals(groupAll.getRecords(), groupAll.getResult().getRecords());
Assert.assertEquals(groupAll.getMetadata().asMap(), groupAll.getResult().getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupAllTest method testCounting.
@Test
public void testCounting() {
GroupAll groupAll = makeGroupAll(makeGroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count"));
BulletRecord someRecord = RecordBox.get().add("foo", 1).getRecord();
IntStream.range(0, 10).forEach(i -> groupAll.consume(someRecord));
Assert.assertNotNull(groupAll.getData());
List<BulletRecord> aggregate = groupAll.getResult().getRecords();
Assert.assertEquals(aggregate.size(), 1);
BulletRecord actual = aggregate.get(0);
BulletRecord expected = RecordBox.get().add("count", 10).getRecord();
Assert.assertEquals(actual, expected);
Assert.assertEquals(groupAll.getRecords(), aggregate);
Assert.assertEquals(groupAll.getMetadata().asMap(), groupAll.getResult().getMeta().asMap());
}
Aggregations