use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.
the class QuerierTest method testRawQueriesWithoutWindowsThatAreClosedAreNotTimeBased.
@Test
public void testRawQueriesWithoutWindowsThatAreClosedAreNotTimeBased() {
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);
Querier querier = make(Querier.Mode.ALL, query, config);
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.shouldBuffer());
Assert.assertEquals(querier.getWindow().getClass(), Basic.class);
querier.consume(RecordBox.get().getRecord());
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.shouldBuffer());
IntStream.range(0, 9).forEach(i -> querier.consume(RecordBox.get().getRecord()));
Assert.assertTrue(querier.isClosed());
Assert.assertFalse(querier.shouldBuffer());
}
use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.
the class QuerierTest method testDefaults.
@Test
public void testDefaults() {
Querier querier = make(Querier.Mode.ALL, new Query());
Query query = querier.getRunningQuery().getQuery();
Assert.assertEquals((Object) query.getAggregation().getSize(), BulletConfig.DEFAULT_AGGREGATION_SIZE);
Assert.assertEquals(query.getAggregation().getType(), Aggregation.Type.RAW);
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.isDone());
Assert.assertFalse(querier.isExceedingRateLimit());
Assert.assertNull(querier.getRateLimitError());
// RAW query without window and not timed out.
Assert.assertFalse(querier.shouldBuffer());
Assert.assertEquals(querier.getResult().getRecords(), emptyList());
}
use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.
the class QuerierTest method testFiltering.
@Test
public void testFiltering() {
Query query = new Query();
query.setFilters(singletonList(getFieldFilter(Clause.Operation.EQUALS, "foo", "bar")));
query.setWindow(WindowUtils.makeReactiveWindow());
Querier querier = make(Querier.Mode.PARTITION, query);
querier.consume(RecordBox.get().add("field", "foo").getRecord());
Assert.assertTrue(querier.isClosed());
querier.reset();
querier.consume(RecordBox.get().add("field", "bar").getRecord());
Assert.assertTrue(querier.isClosed());
querier.reset();
querier.consume(RecordBox.get().add("field", "baz").getRecord());
Assert.assertFalse(querier.isClosed());
}
use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.
the class QuerierTest method testExceptionWrapping.
@Test
public void testExceptionWrapping() {
FailingScheme failingScheme = new FailingScheme(null, null, new BulletConfig());
Querier querier = make(Querier.Mode.ALL, new Query());
querier.setWindow(failingScheme);
querier.consume(RecordBox.get().getRecord());
querier.combine(new byte[0]);
Assert.assertNull(querier.getData());
Assert.assertNull(querier.getRecords());
Meta meta = querier.getMetadata();
Map<String, Object> actualMeta = meta.asMap();
Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
BulletError expected = BulletError.makeError("Getting metadata failure", Querier.TRY_AGAIN_LATER);
Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
Clip actual = querier.getResult();
Assert.assertNotNull(actual.getMeta());
Assert.assertEquals(actual.getRecords().size(), 0);
actualMeta = actual.getMeta().asMap();
Assert.assertEquals(actualMeta.size(), 1);
Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
expected = BulletError.makeError("Getting result failure", Querier.TRY_AGAIN_LATER);
Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
Assert.assertEquals(failingScheme.consumptionFailure, 1);
Assert.assertEquals(failingScheme.combiningFailure, 1);
Assert.assertEquals(failingScheme.serializingFailure, 1);
Assert.assertEquals(failingScheme.aggregationFailure, 3);
}
use of com.yahoo.bullet.parsing.Query in project bullet-core by yahoo.
the class QuerierTest method testRawQueriesWithNonReactiveWindowsAreErrors.
@Test
public void testRawQueriesWithNonReactiveWindowsAreErrors() {
BulletConfig config = new BulletConfig();
Query query = new Query();
query.setWindow(WindowUtils.makeWindow(Window.Unit.RECORD, 2));
query.configure(config);
Querier querier = new Querier(new RunningQuery("", query), config);
Optional<List<BulletError>> errors = querier.initialize();
Assert.assertTrue(errors.isPresent());
Assert.assertEquals(errors.get(), singletonList(Window.NOT_ONE_RECORD_EMIT));
}
Aggregations