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());
}
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());
}
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;
}
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());
}
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());
}
Aggregations