Search in sources :

Example 36 with Aggregation

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

the class DistributionTest method testNumberOfPointsInitialization.

@Test
public void testNumberOfPointsInitialization() {
    Aggregation aggregation = new Aggregation();
    aggregation.setSize(20);
    aggregation.setFields(Collections.singletonMap("foo", "bar"));
    Distribution distribution = new Distribution(aggregation, new BulletConfig());
    Optional<List<BulletError>> optionalErrors;
    List<BulletError> errors;
    // Null points
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, null, null, null, null, null));
    optionalErrors = distribution.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 1);
    Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
    // Negative points
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, -10));
    optionalErrors = distribution.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 2);
    Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
    Assert.assertEquals(errors.get(1), Distribution.REQUIRES_POINTS_PROPER_RANGE);
    // 0 points
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 0));
    optionalErrors = distribution.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 2);
    Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
    Assert.assertEquals(errors.get(1), Distribution.REQUIRES_POINTS_PROPER_RANGE);
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 0));
    optionalErrors = distribution.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 1);
    Assert.assertEquals(errors.get(0), Distribution.REQUIRES_POINTS_ERROR);
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 1));
    optionalErrors = distribution.initialize();
    Assert.assertFalse(optionalErrors.isPresent());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) Arrays.asList(java.util.Arrays.asList) List(java.util.List) BulletError(com.yahoo.bullet.common.BulletError) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 37 with Aggregation

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

the class GroupAllTest method makeAggregation.

public static Aggregation makeAggregation(Map<String, Object> attributes) {
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.GROUP);
    // Does not matter
    aggregation.setSize(1);
    aggregation.setAttributes(attributes);
    return aggregation;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation)

Example 38 with Aggregation

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

the class GroupAllTest method makeGroupAll.

public static GroupAll makeGroupAll(List<GroupOperation> groupOperations) {
    Aggregation aggregation = mock(Aggregation.class);
    List<Map<String, String>> operations = groupOperations.stream().map(AggregationUtils::makeGroupOperation).collect(Collectors.toList());
    when(aggregation.getAttributes()).thenReturn(makeAttributes(operations));
    GroupAll all = new GroupAll(aggregation);
    all.initialize();
    return all;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 39 with Aggregation

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

the class GroupAllTest method testAttributeOperationBadFormat.

@Test
public void testAttributeOperationBadFormat() {
    Aggregation aggregation = makeAggregation(singletonMap(GroupOperation.OPERATIONS, asList("foo")));
    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)

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