Search in sources :

Example 41 with BulletRecord

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

the class TopKTest method testResetting.

@Test
public void testResetting() {
    TopK topK = makeTopK(asList("A", "B"), 64, 4);
    IntStream.range(0, 60).mapToObj(i -> RecordBox.get().add("A", i % 3).getRecord()).forEach(topK::consume);
    BulletRecord expectedA = RecordBox.get().add("A", "0").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "1").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
    BulletRecord expectedC = RecordBox.get().add("A", "2").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
    Clip result = topK.getResult();
    List<BulletRecord> records = result.getRecords();
    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());
    topK.reset();
    topK.consume(RecordBox.get().add("A", 0).getRecord());
    topK.consume(RecordBox.get().add("A", 0).getRecord());
    topK.consume(RecordBox.get().add("A", 1).getRecord());
    result = topK.getResult();
    records = result.getRecords();
    Assert.assertEquals(records.size(), 2);
    expectedA = RecordBox.get().add("A", "0").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 2L).getRecord();
    expectedB = RecordBox.get().add("A", "1").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 1L).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) Test(org.testng.annotations.Test)

Example 42 with BulletRecord

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

the class GroupDataSummarySetOperationsTest method testUnionRightNull.

@Test
public void testUnionRightNull() {
    GroupDataSummarySetOperations operations = new GroupDataSummarySetOperations();
    GroupDataSummary summary = new GroupDataSummary();
    summary.setData(makeSampleGroupData(15, 0.1));
    GroupDataSummary result = operations.union(summary, null);
    BulletRecord actual = result.getData().getAsBulletRecord(emptyMap());
    BulletRecord expected = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("sum", 15.0).add("min", 0.1).getRecord();
    // In-place
    Assert.assertTrue(summary == result);
    Assert.assertTrue(actual.equals(expected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 43 with BulletRecord

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

the class GroupDataSummaryTest method testSerialization.

@Test
public void testSerialization() {
    List<String> groups = asList("foo", "bar", "baz");
    List<GroupOperation.GroupOperationType> operations = asList(COUNT, MAX, MIN);
    CachingGroupData data = new CachingGroupData(makeGroups(groups), makeMetrics(operations));
    data.setCachedRecord(RecordBox.get().getRecord());
    GroupDataSummary summary = new GroupDataSummary();
    summary.update(data);
    byte[] serialized = summary.toByteArray();
    Assert.assertNotNull(serialized);
    Memory memory = new NativeMemory(serialized);
    byte initializedByte = memory.getByte(GroupDataSummary.INITIALIZED_POSITION);
    int length = memory.getInt(GroupDataSummary.SIZE_POSITION);
    byte[] dataSerialized = new byte[length];
    memory.getByteArray(GroupDataSummary.DATA_POSITION, dataSerialized, 0, length);
    CachingGroupData deserialized = SerializerDeserializer.fromBytes(dataSerialized);
    Assert.assertTrue(initializedByte == 1);
    Assert.assertTrue(length > 0);
    Assert.assertNotNull(deserialized);
    Assert.assertNull(deserialized.getCachedRecord());
    BulletRecord actual = deserialized.getAsBulletRecord(emptyMap());
    BulletRecord expected = RecordBox.get().add("field_0", "foo").add("field_1", "bar").add("field_2", "baz").add("COUNT_metric_0", 1).addNull("MAX_metric_1").addNull("MIN_metric_2").getRecord();
    Assert.assertTrue(actual.equals(expected));
}
Also used : NativeMemory(com.yahoo.memory.NativeMemory) BulletRecord(com.yahoo.bullet.record.BulletRecord) Memory(com.yahoo.memory.Memory) NativeMemory(com.yahoo.memory.NativeMemory) Test(org.testng.annotations.Test)

Example 44 with BulletRecord

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

the class GroupDataSummaryTest method testMergeValidSummaries.

@Test
public void testMergeValidSummaries() {
    List<String> groups = asList("foo", "bar");
    List<GroupOperation.GroupOperationType> operations = asList(SUM, MIN);
    CachingGroupData data = new CachingGroupData(makeGroups(groups), makeMetrics(operations));
    GroupDataSummary summaryA = new GroupDataSummary();
    GroupDataSummary summaryB = new GroupDataSummary();
    BulletRecord record = makeRecord(groups, operations, 0);
    data.setCachedRecord(record);
    summaryA.update(data);
    record = makeRecord(groups, operations, 15);
    data.setCachedRecord(record);
    summaryA.update(data);
    record = makeRecord(groups, operations, -10);
    data.setCachedRecord(record);
    summaryB.update(data);
    GroupDataSummary merged = GroupDataSummary.mergeInPlace(summaryA, summaryB);
    Assert.assertNotNull(merged);
    GroupData mergedData = merged.getData();
    GroupData summaryAData = summaryA.getData();
    GroupData summaryBData = summaryB.getData();
    Assert.assertNotNull(mergedData);
    // They are the same object
    Assert.assertTrue(mergedData == summaryAData);
    Assert.assertTrue(mergedData.groupFields == summaryAData.groupFields);
    Assert.assertTrue(mergedData.metrics == summaryAData.metrics);
    // They are different objects
    Assert.assertFalse(mergedData == summaryBData);
    BulletRecord actual = mergedData.getAsBulletRecord(emptyMap());
    BulletRecord expected = RecordBox.get().add("field_0", "foo").add("field_1", "bar").add("SUM_metric_0", 5.0).add("MIN_metric_1", -13.0).getRecord();
    Assert.assertTrue(actual.equals(expected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 45 with BulletRecord

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

the class CountDistinctTest method testMultipleFieldsCountDistinct.

@Test
public void testMultipleFieldsCountDistinct() {
    BulletConfig config = makeConfiguration(4, 512);
    CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("fieldA", "fieldB"));
    IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i).add("fieldB", 255 - i).getRecord()).forEach(countDistinct::consume);
    IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i).add("fieldB", 255 - i).getRecord()).forEach(countDistinct::consume);
    Clip clip = countDistinct.getResult();
    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());
}
Also used : IntStream(java.util.stream.IntStream) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) KMVSketch(com.yahoo.bullet.aggregations.sketches.KMVSketch) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Optional(java.util.Optional) ResizeFactor(com.yahoo.sketches.ResizeFactor) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BulletConfig(com.yahoo.bullet.common.BulletConfig) 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