Search in sources :

Example 6 with Query

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

the class QuerierTest method testRawQueriesWithoutWindowsThatAreTimedOutAreTimeBased.

@Test
public void testRawQueriesWithoutWindowsThatAreTimedOutAreTimeBased() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, 10);
    config.validate();
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.RAW);
    query.setAggregation(aggregation);
    query.configure(config);
    RunningQuery runningQuery = spy(new RunningQuery("", query));
    doAnswer(returnsElementsOf(asList(false, true))).when(runningQuery).isTimedOut();
    Querier querier = new Querier(Querier.Mode.ALL, runningQuery, config);
    querier.initialize();
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(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 : Aggregation(com.yahoo.bullet.parsing.Aggregation) 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 7 with Query

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

the class QuerierTest method testQueryAsString.

@Test
public void testQueryAsString() {
    Querier querier = make(Querier.Mode.ALL, "ahdf3", "{}", emptyMap());
    Assert.assertEquals(querier.toString(), "ahdf3 : {}");
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    query.configure(config);
    query.initialize();
    querier = make(Querier.Mode.ALL, "ahdf3", query, config);
    Assert.assertEquals(querier.toString(), "ahdf3 : " + query.toString());
}
Also used : 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 8 with Query

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

the class QuerierTest method makeCountQueryWithAllWindow.

private static RunningQuery makeCountQueryWithAllWindow(BulletConfig config, int emitInterval) {
    Query query = new Query();
    query.setWindow(WindowUtils.makeWindow(Window.Unit.TIME, emitInterval, Window.Unit.ALL, null));
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.GROUP);
    Map<String, String> count = Collections.singletonMap(GroupOperation.OPERATION_TYPE, GroupOperation.GroupOperationType.COUNT.getName());
    aggregation.setAttributes(Collections.singletonMap(GroupOperation.OPERATIONS, Collections.singletonList(count)));
    query.setAggregation(aggregation);
    query.configure(config);
    RunningQuery runningQuery = spy(new RunningQuery("", query));
    doReturn(false).when(runningQuery).isTimedOut();
    return runningQuery;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) 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)

Example 9 with Query

use of com.yahoo.bullet.parsing.Query 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();
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.COUNT_DISTINCT);
    aggregation.setFields(singletonMap("foo", "bar"));
    query.setAggregation(aggregation);
    query.setWindow(WindowUtils.makeWindow(Window.Unit.TIME, 1));
    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 : Aggregation(com.yahoo.bullet.parsing.Aggregation) 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 10 with Query

use of com.yahoo.bullet.parsing.Query 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();
    query.setAggregation(new Aggregation());
    query.setDuration(1L);
    query.configure(config);
    Assert.assertFalse(query.initialize().isPresent());
    RunningQuery runningQuery = new RunningQuery("foo", query);
    Assert.assertFalse(runningQuery.initialize().isPresent());
    // Sleep to make sure it's 1 ms
    Thread.sleep(1);
    Assert.assertTrue(runningQuery.isTimedOut());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

Query (com.yahoo.bullet.parsing.Query)24 Test (org.testng.annotations.Test)22 BulletConfig (com.yahoo.bullet.common.BulletConfig)20 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)16 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)14 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)14 Aggregation (com.yahoo.bullet.parsing.Aggregation)12 Window (com.yahoo.bullet.parsing.Window)6 List (java.util.List)4 Booleans.asList (com.google.common.primitives.Booleans.asList)3 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 Collections.singletonList (java.util.Collections.singletonList)3 BulletRecord (com.yahoo.bullet.record.BulletRecord)2 Strategy (com.yahoo.bullet.aggregations.Strategy)1 BulletError (com.yahoo.bullet.common.BulletError)1 Clip (com.yahoo.bullet.result.Clip)1 Meta (com.yahoo.bullet.result.Meta)1