Search in sources :

Example 71 with BulletRecord

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

the class ProjectionOperationsTest method testNullFieldName.

@Test
public void testNullFieldName() {
    Projection projection = makeProjection(ImmutablePair.of(null, "test"), ImmutablePair.of("map_field.foo", "foo"));
    BulletRecord record = RecordBox.get().add("field", "test").addMap("map_field", Pair.of("foo", "baz")).getRecord();
    BulletRecord actual = ProjectionOperations.project(record, projection);
    BulletRecord expected = RecordBox.get().add("foo", "baz").getRecord();
    Assert.assertEquals(actual, expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) ProjectionUtils.makeProjection(com.yahoo.bullet.parsing.ProjectionUtils.makeProjection) Projection(com.yahoo.bullet.parsing.Projection) Test(org.testng.annotations.Test)

Example 72 with BulletRecord

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

the class QuerierTest method testReceiveTimestampNoProjection.

@Test
public void testReceiveTimestampNoProjection() {
    Long start = System.currentTimeMillis();
    Query query = new Query();
    query.setProjection(null);
    query.setWindow(WindowUtils.makeReactiveWindow());
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RECORD_INJECT_TIMESTAMP, true);
    config.validate();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    BulletRecord input = RecordBox.get().add("field", "foo").add("mid", "123").getRecord();
    querier.consume(input);
    Assert.assertTrue(querier.isClosed());
    List<BulletRecord> records = querier.getRecords();
    Assert.assertEquals(records.size(), 1);
    BulletRecord actual = records.get(0);
    Long end = System.currentTimeMillis();
    Assert.assertEquals(size(actual), 3);
    Assert.assertEquals(actual.get("field"), "foo");
    Assert.assertEquals(actual.get("mid"), "123");
    Long recordedTimestamp = (Long) actual.get(BulletConfig.DEFAULT_RECORD_INJECT_TIMESTAMP_KEY);
    Assert.assertTrue(recordedTimestamp >= start);
    Assert.assertTrue(recordedTimestamp <= end);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 73 with BulletRecord

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

the class QuerierTest method testReceiveTimestamp.

@Test
public void testReceiveTimestamp() {
    Long start = System.currentTimeMillis();
    Query query = new Query();
    query.setProjection(ProjectionUtils.makeProjection("field", "bid"));
    query.setWindow(WindowUtils.makeReactiveWindow());
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RECORD_INJECT_TIMESTAMP, true);
    config.validate();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    BulletRecord input = RecordBox.get().add("field", "foo").add("mid", "123").getRecord();
    querier.consume(input);
    Assert.assertTrue(querier.isClosed());
    List<BulletRecord> records = querier.getRecords();
    Assert.assertEquals(records.size(), 1);
    BulletRecord actual = records.get(0);
    Long end = System.currentTimeMillis();
    Assert.assertEquals(size(actual), 2);
    Assert.assertEquals(actual.get("bid"), "foo");
    Long recordedTimestamp = (Long) actual.get(BulletConfig.DEFAULT_RECORD_INJECT_TIMESTAMP_KEY);
    Assert.assertTrue(recordedTimestamp >= start);
    Assert.assertTrue(recordedTimestamp <= end);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 74 with BulletRecord

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

the class QuerierTest method testAdditiveWindowsDoNotResetInAllMode.

@Test
public void testAdditiveWindowsDoNotResetInAllMode() {
    BulletConfig config = new BulletConfig();
    RunningQuery runningQuery = makeCountQueryWithAllWindow(config, 2000);
    Querier querier = new Querier(Querier.Mode.ALL, runningQuery, config);
    querier.initialize();
    Assert.assertFalse(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
    Assert.assertEquals(querier.getWindow().getClass(), AdditiveTumbling.class);
    IntStream.range(0, 10).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    Assert.assertFalse(querier.isClosed());
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 1);
    BulletRecord record = result.get(0);
    Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 10L);
    IntStream.range(0, 10).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 1);
    record = result.get(0);
    Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 20L);
    // This will not reset
    querier.reset();
    IntStream.range(0, 5).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 1);
    record = result.get(0);
    Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 25L);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 75 with BulletRecord

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

the class ClipTest method testInvalidDoubles.

@Test
public void testInvalidDoubles() {
    BulletRecord record = new RecordBox().addNull("field").add("plus_inf", Double.POSITIVE_INFINITY).add("neg_inf", Double.NEGATIVE_INFINITY).add("not_a_number", Double.NaN).getRecord();
    Meta meta = new Meta().add("foo", Double.POSITIVE_INFINITY).add("bar", Double.NaN).add("baz", Double.NEGATIVE_INFINITY);
    assertJSONEquals(Clip.of(record).add(meta).asJSON(), makeJSON("{'foo': 'Infinity', 'baz': '-Infinity', 'bar': 'NaN'}", "[{'field': null, 'plus_inf': 'Infinity', 'neg_inf': '-Infinity', 'not_a_number': 'NaN'}]"));
}
Also used : 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