Search in sources :

Example 31 with Aggregation

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

the class AggregationOperationsTest method testDistributionStrategy.

@Test
public void testDistributionStrategy() {
    Aggregation aggregation = new Aggregation();
    BulletConfig config = new BulletConfig();
    aggregation.setType(Aggregation.Type.DISTRIBUTION);
    aggregation.setFields(singletonMap("field", "foo"));
    aggregation.configure(config);
    Assert.assertEquals(AggregationOperations.findStrategy(aggregation, config).getClass(), Distribution.class);
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 32 with Aggregation

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

the class CountDistinctTest method makeAggregation.

public static Aggregation makeAggregation(Map<String, String> fields, Map<String, Object> attributes) {
    Aggregation aggregation = new Aggregation();
    aggregation.setFields(fields);
    aggregation.setAttributes(attributes);
    return aggregation;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation)

Example 33 with Aggregation

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

the class CountDistinctTest method testFailValidateOnCountDistinctFieldsMissing.

@Test
public void testFailValidateOnCountDistinctFieldsMissing() {
    Aggregation aggregation = makeAggregation(null, null);
    CountDistinct countDistinct = makeCountDistinct(new BulletConfig(), aggregation, null);
    Optional<List<BulletError>> optionalErrors = countDistinct.initialize();
    Assert.assertTrue(optionalErrors.isPresent());
    List<BulletError> errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 1);
    Assert.assertEquals(errors.get(0), Strategy.REQUIRES_FIELD_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) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 34 with Aggregation

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

the class DistributionTest method makeDistribution.

public static Distribution makeDistribution(BulletConfig configuration, Map<String, Object> attributes, String field, int size, List<Map.Entry<Concept, String>> metadata) {
    Aggregation aggregation = new Aggregation();
    aggregation.setFields(Collections.singletonMap(field, field));
    aggregation.setSize(size);
    aggregation.setAttributes(attributes);
    Distribution distribution = new Distribution(aggregation, addMetadata(configuration, metadata));
    distribution.initialize();
    return distribution;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation)

Example 35 with Aggregation

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

the class DistributionTest method testRangeInitialization.

@Test
public void testRangeInitialization() {
    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;
    // start  < 0
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, -1, 1, 0.5));
    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);
    // end > 1
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 0, 2, 0.1));
    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);
    // both out of range
    aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, 3, 4, 0.1));
    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.QUANTILE, 0, 1, 0.2));
    optionalErrors = distribution.initialize();
    Assert.assertFalse(optionalErrors.isPresent());
    // start null
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, null, 0.5, 0.2, 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);
    // end null
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 1.0, null, 0.2, 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);
    // increment null
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 1.0, 2.0, 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);
    // end < start
    aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, 25, -2, 0.5));
    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.PMF, 25, 200, 0.5));
    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)

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