Search in sources :

Example 31 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig 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 32 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class QuerierTest method testTimes.

@Test
public void testTimes() {
    BulletConfig defaults = new BulletConfig();
    Map<String, String> names = (Map<String, String>) defaults.get(BulletConfig.RESULT_METADATA_METRICS);
    long startTime = System.currentTimeMillis();
    Querier querier = make(Querier.Mode.ALL, "", "{'aggregation' : {}}", emptyMap());
    Map<String, Object> meta = querier.getMetadata().asMap();
    Assert.assertEquals(meta.size(), 2);
    Map<String, Object> queryMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.QUERY_METADATA.getName()));
    Map<String, Object> windowMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.WINDOW_METADATA.getName()));
    long creationTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()))).longValue();
    long emitTime = ((Number) windowMeta.get(names.get(Meta.Concept.WINDOW_EMIT_TIME.getName()))).longValue();
    long endTime = System.currentTimeMillis();
    Assert.assertTrue(creationTime >= startTime && creationTime <= endTime);
    Assert.assertTrue(emitTime >= startTime && emitTime <= endTime);
    Clip finalResult = querier.finish();
    Assert.assertNotNull(finalResult);
    Assert.assertTrue(finalResult.getRecords().isEmpty());
    meta = finalResult.getMeta().asMap();
    queryMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.QUERY_METADATA.getName()));
    windowMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.WINDOW_METADATA.getName()));
    creationTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()))).longValue();
    emitTime = ((Number) windowMeta.get(names.get(Meta.Concept.WINDOW_EMIT_TIME.getName()))).longValue();
    long finishTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_FINISH_TIME.getName()))).longValue();
    endTime = System.currentTimeMillis();
    Assert.assertTrue(creationTime >= startTime && creationTime <= finishTime);
    Assert.assertTrue(emitTime >= startTime && emitTime <= finishTime);
    Assert.assertTrue(finishTime <= endTime);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 33 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig 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 34 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class QuerierTest method testDisabledQueryMeta.

@Test
public void testDisabledQueryMeta() {
    BulletConfig defaults = new BulletConfig();
    defaults.set(BulletConfig.RESULT_METADATA_METRICS, emptyMap());
    Querier querier = make(Querier.Mode.ALL, "", "{'aggregation' : {}}", defaults);
    Assert.assertTrue(querier.getMetadata().asMap().isEmpty());
    Clip result = querier.finish();
    Assert.assertNotNull(result);
    Assert.assertTrue(result.getRecords().isEmpty());
    Assert.assertTrue(result.getMeta().asMap().isEmpty());
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 35 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig 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)

Aggregations

BulletConfig (com.yahoo.bullet.common.BulletConfig)101 Test (org.testng.annotations.Test)87 Aggregation (com.yahoo.bullet.parsing.Aggregation)37 List (java.util.List)25 Query (com.yahoo.bullet.parsing.Query)20 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)17 BulletError (com.yahoo.bullet.common.BulletError)16 BulletRecord (com.yahoo.bullet.record.BulletRecord)16 Arrays.asList (java.util.Arrays.asList)16 Clip (com.yahoo.bullet.result.Clip)14 Collections.singletonList (java.util.Collections.singletonList)12 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)11 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)11 Map (java.util.Map)11 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)10 Window (com.yahoo.bullet.parsing.Window)10 Concept (com.yahoo.bullet.result.Meta.Concept)10 RecordBox (com.yahoo.bullet.result.RecordBox)10 ArrayList (java.util.ArrayList)10 IntStream (java.util.stream.IntStream)10