use of com.yahoo.bullet.common.BulletError in project bullet-core by yahoo.
the class DistributionTest method testInitialize.
@Test
public void testInitialize() {
Optional<List<BulletError>> optionalErrors;
List<BulletError> errors;
Aggregation aggregation = new Aggregation();
aggregation.setSize(20);
Distribution distribution = new Distribution(aggregation, new BulletConfig());
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_ONE_FIELD_ERROR);
aggregation.setFields(Collections.singletonMap("foo", "bar"));
distribution = new Distribution(aggregation, new BulletConfig());
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_TYPE_ERROR);
aggregation.setAttributes(Collections.singletonMap(Distribution.TYPE, "foo"));
distribution = new Distribution(aggregation, new BulletConfig());
optionalErrors = distribution.initialize();
Assert.assertTrue(optionalErrors.isPresent());
errors = optionalErrors.get();
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(errors.get(0), Distribution.REQUIRES_TYPE_ERROR);
Map<String, Object> attributes = new HashMap<>();
attributes.put(Distribution.TYPE, Distribution.Type.CDF.getName());
attributes.put(Distribution.NUMBER_OF_POINTS, 10L);
aggregation.setAttributes(attributes);
distribution = new Distribution(aggregation, new BulletConfig());
Assert.assertFalse(distribution.initialize().isPresent());
}
use of com.yahoo.bullet.common.BulletError in project bullet-core by yahoo.
the class DistributionTest method testProvidedPointsInitialization.
@Test
public void testProvidedPointsInitialization() {
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;
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, asList(0.4, 0.03, 0.99, 0.5, 14.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.QUANTILE, null));
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, Collections.emptyList()));
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, Collections.singletonList(2.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.QUANTILE, Collections.singletonList(1.0)));
optionalErrors = distribution.initialize();
Assert.assertFalse(distribution.initialize().isPresent());
aggregation.setAttributes(makeAttributes(Distribution.Type.QUANTILE, asList(0.4, 0.03, 0.99, 0.5, 0.35)));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, Collections.singletonList(0.4)));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
aggregation.setAttributes(makeAttributes(Distribution.Type.PMF, asList(0.4, 0.03, 0.99, 0.5, 14.0)));
optionalErrors = distribution.initialize();
Assert.assertFalse(optionalErrors.isPresent());
}
use of com.yahoo.bullet.common.BulletError 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);
}
use of com.yahoo.bullet.common.BulletError in project bullet-storm by yahoo.
the class JoinBoltTest method testErrorInQueryWithoutMetadata.
@Test
public void testErrorInQueryWithoutMetadata() {
Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{\"aggregation\": {\"type\": \"garbage\"}}");
bolt.execute(query);
Assert.assertEquals(collector.getEmittedCount(), 1);
BulletError expectedError = Aggregation.TYPE_NOT_SUPPORTED_ERROR;
Meta expectedMetadata = Meta.of(expectedError);
List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues();
List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get();
Assert.assertTrue(isSameResult(actual, expected));
Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
Assert.assertEquals(collector.getEmittedCount(), 1);
}
use of com.yahoo.bullet.common.BulletError in project bullet-core by yahoo.
the class MetaTest method testMetadataWithErrors.
@Test
public void testMetadataWithErrors() {
BulletError errorA = BulletError.makeError("foo", "bar");
BulletError errorB = BulletError.makeError("baz", "qux");
Meta meta = Meta.of(Arrays.asList(errorA, errorB));
BulletError errorC = BulletError.makeError("norf", "foo");
meta.addErrors(Collections.singletonList(errorC));
Map<String, Object> actual = meta.asMap();
Assert.assertEquals(actual.size(), 1);
List<BulletError> actualErrors = (List<BulletError>) actual.get(Meta.ERROR_KEY);
Assert.assertEquals(actualErrors.size(), 3);
Assert.assertEquals(actualErrors.get(0).getError(), "foo");
Assert.assertEquals(actualErrors.get(0).getResolutions(), singletonList("bar"));
Assert.assertEquals(actualErrors.get(1).getError(), "baz");
Assert.assertEquals(actualErrors.get(1).getResolutions(), singletonList("qux"));
Assert.assertEquals(actualErrors.get(2).getError(), "norf");
Assert.assertEquals(actualErrors.get(2).getResolutions(), singletonList("foo"));
}
Aggregations