Search in sources :

Example 36 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class RawTest method testWritingBadRecord.

@Test
public void testWritingBadRecord() {
    BulletRecord mocked = new NoSerDeBulletRecord();
    Raw raw = makeRaw(1);
    raw.consume(mocked);
    Assert.assertNull(raw.getData());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 37 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class RawTest method testLimitZero.

@Test
public void testLimitZero() {
    Raw raw = makeRaw(0);
    List<BulletRecord> aggregate = raw.getResult().getRecords();
    Assert.assertTrue(raw.isClosed());
    Assert.assertEquals(aggregate.size(), 0);
    BulletRecord record = RecordBox.get().add("foo", "bar").getRecord();
    raw.consume(record);
    Assert.assertTrue(raw.isClosed());
    Assert.assertNull(raw.getData());
    Assert.assertEquals(raw.getResult().getRecords().size(), 0);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 38 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class TopKTest method testExactTopKThreshold.

@Test
public void testExactTopKThreshold() {
    TopK topK = makeTopK(ErrorType.NO_FALSE_POSITIVES, asList("A", "B"), "cnt", 64, 3, 25L);
    IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
    IntStream.range(0, 25).mapToObj(i -> RecordBox.get().add("A", 108).getRecord()).forEach(topK::consume);
    IntStream.range(0, 24).mapToObj(i -> RecordBox.get().add("A", "foo").add("B", "bar").getRecord()).forEach(topK::consume);
    IntStream.range(0, 100).mapToObj(i -> RecordBox.get().add("A", 42L).getRecord()).forEach(topK::consume);
    Clip result = topK.getResult();
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 2);
    BulletRecord expectedA = RecordBox.get().add("A", "42").add("B", "null").add("cnt", 100L).getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "108").add("B", "null").add("cnt", 25L).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
    IntStream.range(0, 11).mapToObj(i -> RecordBox.get().add("A", "foo").add("B", "bar").getRecord()).forEach(topK::consume);
    result = topK.getResult();
    records = result.getRecords();
    Assert.assertEquals(records.size(), 3);
    expectedA = RecordBox.get().add("A", "42").add("B", "null").add("cnt", 100L).getRecord();
    expectedB = RecordBox.get().add("A", "foo").add("B", "bar").add("cnt", 35L).getRecord();
    BulletRecord expectedC = RecordBox.get().add("A", "108").add("B", "null").add("cnt", 25L).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
    Assert.assertEquals(records.get(2), expectedC);
    Assert.assertEquals(topK.getRecords(), records);
    Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Collections.singletonMap(java.util.Collections.singletonMap) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) Set(java.util.Set) List(java.util.List) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) BulletConfig(com.yahoo.bullet.common.BulletConfig) Optional(java.util.Optional) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 39 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class TopKTest method testExactTopKSizeLimiting.

@Test
public void testExactTopKSizeLimiting() {
    TopK topK = makeTopK(ErrorType.NO_FALSE_POSITIVES, singletonList("A"), "cnt", 64, 2, null);
    IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
    IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", 108.1).getRecord()).forEach(topK::consume);
    IntStream.range(0, 100).mapToObj(i -> RecordBox.get().add("A", 42L).getRecord()).forEach(topK::consume);
    Clip result = topK.getResult();
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 5);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 2);
    BulletRecord expectedA = RecordBox.get().add("A", "42").add("cnt", 100L).getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "108.1").add("cnt", 20L).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
    Assert.assertEquals(topK.getRecords(), records);
    Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Collections.singletonMap(java.util.Collections.singletonMap) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) Set(java.util.Set) List(java.util.List) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) BulletConfig(com.yahoo.bullet.common.BulletConfig) Optional(java.util.Optional) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.testng.annotations.Test)

Example 40 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class TopKTest method testBadMaxMapEntries.

@Test
public void testBadMaxMapEntries() {
    TopK topK = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, -1), null, singletonMap("A", "foo"), BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES, null);
    int uniqueGroups = BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES / 4;
    IntStream.range(0, uniqueGroups).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
    Clip result = topK.getResult();
    Assert.assertNull(result.getMeta().asMap().get("meta"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), uniqueGroups);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 2);
        int fieldA = Integer.valueOf(actual.get("foo").toString());
        Assert.assertTrue(fieldA < uniqueGroups);
        Assert.assertEquals(actual.get(TopK.DEFAULT_NEW_NAME), 1L);
    }
    Assert.assertEquals(topK.getRecords(), records);
    Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
    // Not a power of 2
    TopK another = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, 5), null, singletonMap("A", "foo"), BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES, null);
    IntStream.range(0, uniqueGroups).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(another::consume);
    result = another.getResult();
    Assert.assertNull(result.getMeta().asMap().get("meta"));
    records = result.getRecords();
    Assert.assertEquals(records.size(), uniqueGroups);
    Assert.assertEquals(another.getRecords(), records);
    Assert.assertEquals(another.getMetadata().asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Collections.singletonMap(java.util.Collections.singletonMap) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) Set(java.util.Set) List(java.util.List) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) BulletConfig(com.yahoo.bullet.common.BulletConfig) Optional(java.util.Optional) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Aggregations

BulletRecord (com.yahoo.bullet.record.BulletRecord)210 Test (org.testng.annotations.Test)196 Tuple (org.apache.storm.tuple.Tuple)55 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)53 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)53 TopKTest (com.yahoo.bullet.aggregations.TopKTest)53 Clip (com.yahoo.bullet.result.Clip)53 HashMap (java.util.HashMap)53 Map (java.util.Map)53 BulletConfig (com.yahoo.bullet.common.BulletConfig)46 List (java.util.List)45 IntStream (java.util.stream.IntStream)45 Assert (org.testng.Assert)45 RecordBox (com.yahoo.bullet.result.RecordBox)43 Arrays.asList (java.util.Arrays.asList)40 Pair (org.apache.commons.lang3.tuple.Pair)40 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)34 BulletError (com.yahoo.bullet.common.BulletError)33 Aggregation (com.yahoo.bullet.parsing.Aggregation)33 Concept (com.yahoo.bullet.result.Meta.Concept)33