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));
}
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);
}
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);
}
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());
}
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());
}
Aggregations