Search in sources :

Example 6 with Projection

use of com.yahoo.bullet.query.Projection 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)

Example 7 with Projection

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

the class QuerierTest method testRestarting.

@Test
public void testRestarting() throws Exception {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RESULT_METADATA_ENABLE, true);
    config.validate();
    Query query = new Query(new Projection(), null, new Raw(null), null, WindowUtils.makeTumblingWindow(1), null);
    query.configure(config);
    Querier querier = new Querier(Querier.Mode.ALL, makeRunningQuery("", query), config);
    querier.consume(RecordBox.get().getRecord());
    Assert.assertEquals(querier.getRecords().size(), 1);
    long timeNow = System.currentTimeMillis();
    Meta meta = querier.getMetadata();
    Map<String, String> mapping = BulletConfigTest.allMetadataAsMap();
    Map<String, Object> queryMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.QUERY_METADATA.getName()));
    Map<String, Object> windowMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.WINDOW_METADATA.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 1L);
    long startTime = (Long) queryMeta.get(mapping.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()));
    long windowEmitTime = (Long) windowMeta.get(mapping.get(Meta.Concept.WINDOW_EMIT_TIME.getName()));
    Assert.assertTrue(startTime <= timeNow);
    Assert.assertTrue(windowEmitTime >= timeNow);
    Thread.sleep(1);
    querier.restart();
    Assert.assertEquals(querier.getRecords().size(), 1);
    meta = querier.getMetadata();
    queryMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.QUERY_METADATA.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 1L);
    long newStartTime = (Long) queryMeta.get(mapping.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()));
    // Querier#restart() no longer updates the query's start time
    Assert.assertEquals(newStartTime, startTime);
    querier.reset();
    meta = querier.getMetadata();
    windowMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.WINDOW_METADATA.getName()));
    long newEmitTime = (Long) windowMeta.get(mapping.get(Meta.Concept.WINDOW_EMIT_TIME.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 2L);
    Assert.assertTrue(newEmitTime > windowEmitTime);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 8 with Projection

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

the class QuerierTest method testMetadataDisabled.

@Test
public void testMetadataDisabled() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RESULT_METADATA_ENABLE, false);
    // Should clear out the default metadata
    config.validate();
    CountDistinct aggregation = new CountDistinct(Collections.singletonList("foo"), "count");
    Window window = WindowUtils.makeTumblingWindow(1);
    Query query = new Query(new Projection(), null, aggregation, null, window, null);
    query.configure(config);
    Querier querier = make(Querier.Mode.PARTITION, query, config);
    querier.consume(RecordBox.get().add("foo", "A").getRecord());
    Assert.assertTrue(querier.getMetadata().asMap().isEmpty());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) CountDistinct(com.yahoo.bullet.query.aggregations.CountDistinct) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 9 with Projection

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

the class RunningQueryTest method testCreatingWithQuery.

@Test
public void testCreatingWithQuery() {
    BulletConfig config = new BulletConfig();
    Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), null);
    query.configure(config);
    RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, "bar"));
    Assert.assertEquals(runningQuery.getId(), "foo");
    Assert.assertNotNull(runningQuery.getQuery());
    Assert.assertEquals(runningQuery.getQueryString(), "bar");
    Assert.assertEquals(runningQuery.toString(), query.toString());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Metadata(com.yahoo.bullet.pubsub.Metadata) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 10 with Projection

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

the class RunningQueryTest method testTimingOut.

@Test
public void testTimingOut() throws Exception {
    BulletConfig config = new BulletConfig();
    Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), 1L);
    query.configure(config);
    RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, null));
    // Sleep to make sure it's 1 ms
    Thread.sleep(1);
    Assert.assertTrue(runningQuery.isTimedOut());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Metadata(com.yahoo.bullet.pubsub.Metadata) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

Projection (com.yahoo.bullet.query.Projection)29 Query (com.yahoo.bullet.query.Query)29 Window (com.yahoo.bullet.query.Window)28 Raw (com.yahoo.bullet.query.aggregations.Raw)27 Test (org.testng.annotations.Test)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)18 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 BulletConfig (com.yahoo.bullet.common.BulletConfig)11 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 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3 Operation (com.yahoo.bullet.query.expressions.Operation)3