Search in sources :

Example 6 with Aggregation

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

the class GroupAllTest method testAttributeOperationMissing.

@Test
public void testAttributeOperationMissing() {
    Aggregation aggregation = makeAggregation(singletonMap(GroupOperation.OPERATIONS, null));
    GroupAll groupAll = new GroupAll(aggregation);
    Optional<List<BulletError>> optionalErrors = groupAll.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    List<BulletError> errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 1);
    Assert.assertEquals(errors.get(0), GroupOperation.REQUIRES_FIELD_OR_OPERATION_ERROR);
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) List(java.util.List) Arrays.asList(java.util.Arrays.asList) BulletError(com.yahoo.bullet.common.BulletError) Test(org.testng.annotations.Test)

Example 7 with Aggregation

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

the class QuerierTest method testNonRawQueriesWithRecordWindowsAreErrors.

@Test
public void testNonRawQueriesWithRecordWindowsAreErrors() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.COUNT_DISTINCT);
    query.setAggregation(aggregation);
    query.setWindow(WindowUtils.makeWindow(Window.Unit.RECORD, 1));
    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(Query.ONLY_RAW_RECORD));
}
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) 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)

Example 8 with Aggregation

use of com.yahoo.bullet.parsing.Aggregation 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 9 with Aggregation

use of com.yahoo.bullet.parsing.Aggregation 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 10 with Aggregation

use of com.yahoo.bullet.parsing.Aggregation 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

Aggregation (com.yahoo.bullet.parsing.Aggregation)39 Test (org.testng.annotations.Test)31 BulletConfig (com.yahoo.bullet.common.BulletConfig)30 Query (com.yahoo.bullet.parsing.Query)12 List (java.util.List)11 BulletError (com.yahoo.bullet.common.BulletError)10 Arrays.asList (java.util.Arrays.asList)10 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)7 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)5 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)5 Window (com.yahoo.bullet.parsing.Window)5 Map (java.util.Map)4 TestHelpers.addMetadata (com.yahoo.bullet.TestHelpers.addMetadata)3 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)3 BulletRecord (com.yahoo.bullet.record.BulletRecord)3 Clip (com.yahoo.bullet.result.Clip)3 Concept (com.yahoo.bullet.result.Meta.Concept)3 RecordBox (com.yahoo.bullet.result.RecordBox)3 Collections.singletonList (java.util.Collections.singletonList)3 Collections.singletonMap (java.util.Collections.singletonMap)3