Search in sources :

Example 16 with Query

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());
}
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 17 with Query

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());
}
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) Test(org.testng.annotations.Test)

Example 18 with Query

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());
}
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) Test(org.testng.annotations.Test)

Example 19 with Query

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);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Meta(com.yahoo.bullet.result.Meta) 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) BulletError(com.yahoo.bullet.common.BulletError) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 20 with Query

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));
}
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) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Booleans.asList(com.google.common.primitives.Booleans.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) 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