Search in sources :

Example 16 with Query

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

the class QuerierTest method testQueryAsString.

@Test
public void testQueryAsString() {
    BulletConfig config = new BulletConfig();
    Query query = makeRawQuery();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, "foo", query, config);
    Assert.assertEquals(querier.toString(), "foo : " + query.toString());
}
Also used : Query(com.yahoo.bullet.query.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 17 with Query

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

the class QuerierTest method makeCountQueryWithAllWindow.

private static RunningQuery makeCountQueryWithAllWindow(BulletConfig config, int emitInterval) {
    GroupAll groupAll = new GroupAll(singleton(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "COUNT")));
    Window window = WindowUtils.makeWindow(Window.Unit.TIME, emitInterval, Window.Unit.ALL, null);
    Query query = new Query(new Projection(), null, groupAll, null, window, null);
    query.configure(config);
    RunningQuery runningQuery = spy(makeRunningQuery("", query));
    Mockito.doReturn(false).when(runningQuery).isTimedOut();
    return runningQuery;
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) GroupAll(com.yahoo.bullet.query.aggregations.GroupAll) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation)

Example 18 with Query

use of com.yahoo.bullet.query.Query 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 19 with Query

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

the class QuerierTest method testRawQueriesWithoutWindowsThatAreTimedOutAreStillRecordBased.

@Test
public void testRawQueriesWithoutWindowsThatAreTimedOutAreStillRecordBased() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, 10);
    config.validate();
    Query query = makeRawQuery();
    query.configure(config);
    RunningQuery runningQuery = spy(makeRunningQuery("", query));
    Mockito.doAnswer(AdditionalAnswers.returnsElementsOf(Arrays.asList(false, true))).when(runningQuery).isTimedOut();
    Querier querier = new Querier(Querier.Mode.ALL, runningQuery, config);
    Assert.assertFalse(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
    Assert.assertEquals(querier.getWindow().getClass(), Basic.class);
    IntStream.range(0, 9).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    Assert.assertFalse(querier.isClosed());
    // Now runningQuery is timed out but query is not done.
    Assert.assertTrue(querier.shouldBuffer());
}
Also used : Query(com.yahoo.bullet.query.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 20 with Query

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

the class QuerierTest method testRawQueriesWithoutWindowsThatAreClosedAreRecordBased.

@Test
public void testRawQueriesWithoutWindowsThatAreClosedAreRecordBased() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, 10);
    config.validate();
    Query query = makeRawQuery();
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    Assert.assertFalse(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
    Assert.assertEquals(querier.getWindow().getClass(), Basic.class);
    querier.consume(RecordBox.get().getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
    IntStream.range(0, 9).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    Assert.assertTrue(querier.isClosed());
    Assert.assertTrue(querier.shouldBuffer());
}
Also used : Query(com.yahoo.bullet.query.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Aggregations

Query (com.yahoo.bullet.query.Query)62 Test (org.testng.annotations.Test)55 Projection (com.yahoo.bullet.query.Projection)29 Window (com.yahoo.bullet.query.Window)28 Raw (com.yahoo.bullet.query.aggregations.Raw)27 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)25 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)24 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)24 BulletConfig (com.yahoo.bullet.common.BulletConfig)22 BulletRecord (com.yahoo.bullet.record.BulletRecord)13 Expression (com.yahoo.bullet.query.expressions.Expression)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)11 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 TableFunction (com.yahoo.bullet.query.tablefunctions.TableFunction)4 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3