Search in sources :

Example 1 with BulletError

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());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) HashMap(java.util.HashMap) 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 2 with BulletError

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());
}
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 3 with BulletError

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

Example 4 with BulletError

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);
}
Also used : Meta(com.yahoo.bullet.result.Meta) JsonObject(com.google.gson.JsonObject) BulletError(com.yahoo.bullet.common.BulletError) Tuple(org.apache.storm.tuple.Tuple) Test(org.testng.annotations.Test) GroupByTest(com.yahoo.bullet.aggregations.GroupByTest) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) TopKTest(com.yahoo.bullet.aggregations.TopKTest) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest)

Example 5 with BulletError

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"));
}
Also used : ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) BulletError(com.yahoo.bullet.common.BulletError) 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