Search in sources :

Example 6 with BulletError

use of com.yahoo.bullet.common.BulletError in project bullet-core by yahoo.

the class GroupOperationTest method testCheckingGroupOperations.

@Test
public void testCheckingGroupOperations() {
    List<GroupOperation> list = new ArrayList<>();
    Assert.assertFalse(GroupOperation.checkOperations(list).isPresent());
    list.add(new GroupOperation(AVG, "foo", "avg1"));
    list.add(new GroupOperation(MIN, "foo", null));
    list.add(new GroupOperation(COUNT, null, null));
    Assert.assertFalse(GroupOperation.checkOperations(list).isPresent());
    list.add(new GroupOperation(SUM, null, null));
    list.add(new GroupOperation(AVG, null, "foo"));
    Optional<List<BulletError>> optionalErrors = GroupOperation.checkOperations(list);
    Assert.assertTrue(optionalErrors.isPresent());
    List<BulletError> errors = optionalErrors.get();
    Assert.assertEquals(errors.size(), 2);
    Assert.assertEquals(errors.get(0), BulletError.makeError(GroupOperation.GROUP_OPERATION_REQUIRES_FIELD + SUM, GroupOperation.OPERATION_REQUIRES_FIELD_RESOLUTION));
    Assert.assertEquals(errors.get(1), BulletError.makeError(GroupOperation.GROUP_OPERATION_REQUIRES_FIELD + AVG, GroupOperation.OPERATION_REQUIRES_FIELD_RESOLUTION));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BulletError(com.yahoo.bullet.common.BulletError) AggregationUtils.makeGroupOperation(com.yahoo.bullet.parsing.AggregationUtils.makeGroupOperation) Test(org.testng.annotations.Test)

Example 7 with BulletError

use of com.yahoo.bullet.common.BulletError 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 8 with BulletError

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

use of com.yahoo.bullet.common.BulletError 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)

Example 10 with BulletError

use of com.yahoo.bullet.common.BulletError 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)

Aggregations

BulletError (com.yahoo.bullet.common.BulletError)14 Test (org.testng.annotations.Test)14 List (java.util.List)9 Arrays.asList (java.util.Arrays.asList)8 Aggregation (com.yahoo.bullet.parsing.Aggregation)7 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 Meta (com.yahoo.bullet.result.Meta)5 JsonObject (com.google.gson.JsonObject)4 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)4 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)4 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)4 TopKTest (com.yahoo.bullet.aggregations.TopKTest)4 Tuple (org.apache.storm.tuple.Tuple)4 ArrayList (java.util.ArrayList)2 AggregationUtils.makeGroupOperation (com.yahoo.bullet.parsing.AggregationUtils.makeGroupOperation)1 Query (com.yahoo.bullet.parsing.Query)1 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)1 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)1 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)1 Clip (com.yahoo.bullet.result.Clip)1