Search in sources :

Example 26 with Raw

use of com.yahoo.bullet.query.aggregations.Raw in project bullet-core by yahoo.

the class QuerierTest method testLogicFilterOr.

@Test
public void testLogicFilterOr() {
    // legacy test
    Expression filter = new BinaryExpression(new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.EQUALS), new BinaryExpression(new FieldExpression("id"), new ValueExpression("1"), Operation.EQUALS), Operation.OR);
    Query query = new Query(new Projection(), filter, new Raw(null), null, new Window(), null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    querier.consume(RecordBox.get().add("field", "abc").add("id", "2").getRecord());
    Assert.assertTrue(querier.hasNewData());
    querier.consume(RecordBox.get().add("field", "abc").add("id", "1").getRecord());
    Assert.assertTrue(querier.hasNewData());
}
Also used : Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 27 with Raw

use of com.yahoo.bullet.query.aggregations.Raw in project bullet-core by yahoo.

the class QuerierTest method testOrderBy.

@Test
public void testOrderBy() {
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    OrderBy orderBy = new OrderBy(Collections.singletonList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC)));
    Query query = new Query(new Projection(), filter, new Raw(500), Collections.singletonList(orderBy), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", 10 - i).add("b", i + 10).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("a").getValue(), 10);
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 10);
    Assert.assertEquals(result.get(1).typedGet("a").getValue(), 9);
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 11);
    Assert.assertEquals(result.get(2).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 12);
    Assert.assertEquals(result.get(3).typedGet("a").getValue(), 7);
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 13);
}
Also used : OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Window(com.yahoo.bullet.query.Window) BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 28 with Raw

use of com.yahoo.bullet.query.aggregations.Raw in project bullet-core by yahoo.

the class QuerierTest method testFiltering.

@Test
public void testFiltering() {
    Expression filter = new BinaryExpression(new FieldExpression("field"), new ListExpression(Arrays.asList(new ValueExpression("foo"), new ValueExpression("bar"))), Operation.EQUALS_ANY);
    Window window = WindowUtils.makeSlidingWindow(1);
    Query query = new Query(new Projection(), filter, new Raw(null), null, window, null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    querier.consume(RecordBox.get().add("field", "foo").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "bar").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "baz").getRecord());
    Assert.assertFalse(querier.isClosed());
}
Also used : Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 29 with Raw

use of com.yahoo.bullet.query.aggregations.Raw in project bullet-core by yahoo.

the class RawStrategyTest method makeRaw.

private static RawStrategy makeRaw(int size, int maxSize) {
    Aggregation aggregation = new Raw(size);
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, maxSize);
    config.validate();
    return (RawStrategy) aggregation.getStrategy(config);
}
Also used : Aggregation(com.yahoo.bullet.query.aggregations.Aggregation) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig)

Example 30 with Raw

use of com.yahoo.bullet.query.aggregations.Raw in project bullet-core by yahoo.

the class PubSubMessageTest method testReadingDataAsDifferentTypes.

@Test
public void testReadingDataAsDifferentTypes() {
    String string = getRandomString();
    byte[] bytes = getRandomBytes();
    Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), Long.MAX_VALUE);
    PubSubMessage message;
    message = new PubSubMessage("foo", string);
    Assert.assertEquals(message.getContent(), string);
    Assert.assertEquals(message.getContentAsString(), string);
    message = new PubSubMessage("foo", bytes);
    Assert.assertEquals(message.getContent(), bytes);
    Assert.assertEquals(message.getContentAsByteArray(), bytes);
    message = new PubSubMessage("foo", query);
    Assert.assertSame(message.getContent(), query);
    Assert.assertSame(message.getContentAsQuery(), query);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Test(org.testng.annotations.Test)

Aggregations

Raw (com.yahoo.bullet.query.aggregations.Raw)40 Test (org.testng.annotations.Test)33 Projection (com.yahoo.bullet.query.Projection)27 Query (com.yahoo.bullet.query.Query)27 Window (com.yahoo.bullet.query.Window)26 BulletConfig (com.yahoo.bullet.common.BulletConfig)21 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)17 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)11 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)11 Expression (com.yahoo.bullet.query.expressions.Expression)10 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 Operation (com.yahoo.bullet.query.expressions.Operation)3 Computation (com.yahoo.bullet.query.postaggregations.Computation)3 Culling (com.yahoo.bullet.query.postaggregations.Culling)3