Search in sources :

Example 6 with Raw

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

the class QueryTest method testCustomDuration.

@Test
public void testCustomDuration() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.QUERY_DEFAULT_DURATION, 200);
    config.set(BulletConfig.QUERY_MAX_DURATION, 1000);
    config.validate();
    Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), null);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), -1000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), 0L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), 1L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), 200L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), 1000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1000L);
    query = new Query(new Projection(), null, new Raw(null), null, new Window(), 2000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1000L);
}
Also used : Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 7 with Raw

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

the class QuerierTest method testTableFunction.

@Test
public void testTableFunction() {
    TableFunction tableFunction = new LateralView(new Explode(new FieldExpression("map"), "key", "value", true));
    Projection projection = new Projection(Arrays.asList(new Field("key", new FieldExpression("key")), new Field("value", new FieldExpression("value")), new Field("abc", new FieldExpression("abc"))), false);
    Expression filter = new UnaryExpression(new FieldExpression("map"), Operation.IS_NOT_NULL);
    Query query = new Query(tableFunction, projection, filter, new Raw(500), null, new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    querier.consume(RecordBox.get().addMap("map", Pair.of("a", 0), Pair.of("b", 1), Pair.of("c", 2)).add("abc", 1).getRecord());
    querier.consume(RecordBox.get().add("abc", 2).getRecord());
    querier.consume(RecordBox.get().add("abc", 3).add("map", new HashMap<>()).getRecord());
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).fieldCount(), 3);
    Assert.assertEquals(result.get(0).typedGet("key").getValue(), "a");
    Assert.assertEquals(result.get(0).typedGet("value").getValue(), 0);
    Assert.assertEquals(result.get(0).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(1).fieldCount(), 3);
    Assert.assertEquals(result.get(1).typedGet("key").getValue(), "b");
    Assert.assertEquals(result.get(1).typedGet("value").getValue(), 1);
    Assert.assertEquals(result.get(1).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(2).fieldCount(), 3);
    Assert.assertEquals(result.get(2).typedGet("key").getValue(), "c");
    Assert.assertEquals(result.get(2).typedGet("value").getValue(), 2);
    Assert.assertEquals(result.get(2).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(3).fieldCount(), 1);
    Assert.assertEquals(result.get(3).typedGet("abc").getValue(), 3);
}
Also used : Window(com.yahoo.bullet.query.Window) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) Query(com.yahoo.bullet.query.Query) 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) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) 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) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 8 with Raw

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

the class QuerierTest method testNullConfig.

@Test(expectedExceptions = NullPointerException.class)
public void testNullConfig() {
    RunningQuery query = makeRunningQuery("", new Query(new Projection(), null, new Raw(null), null, new Window(), null));
    new Querier(query, null);
}
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) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 9 with Raw

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

the class QuerierTest method testRawQueriesWithTimeWindowsAreNotChanged.

@Test
public void testRawQueriesWithTimeWindowsAreNotChanged() {
    BulletConfig config = new BulletConfig();
    Window window = WindowUtils.makeTumblingWindow(Integer.MAX_VALUE);
    Query query = new Query(new Projection(), null, new Raw(null), null, window, null);
    query.configure(config);
    Querier querier = make(Querier.Mode.PARTITION, query, config);
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.shouldBuffer());
    querier.consume(RecordBox.get().getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertEquals(querier.getWindow().getClass(), Tumbling.class);
}
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) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 10 with Raw

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

the class QuerierTest method testCopyProjection.

@Test
public void testCopyProjection() {
    Projection projection = new Projection(Collections.singletonList(new Field("mid", new FieldExpression("map_field", "id"))), true);
    Query query = new Query(projection, null, new Raw(null), null, new Window(), null);
    BulletConfig config = new BulletConfig();
    query.configure(config);
    Querier querier = new Querier(makeRunningQuery("", query), config);
    RecordBox boxA = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
    BulletRecord expected = boxA.getRecord().copy();
    expected.setString("mid", "23");
    querier.consume(boxA.getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertEquals(querier.getData(), getListBytes(expected));
}
Also used : Window(com.yahoo.bullet.query.Window) RecordBox(com.yahoo.bullet.result.RecordBox) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

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