Search in sources :

Example 91 with BulletConfig

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

the class QueryTest method testAggregationDefault.

@Test
public void testAggregationDefault() {
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(null);
    aggregation.setSize(BulletConfig.DEFAULT_AGGREGATION_MAX_SIZE - 1);
    query.setAggregation(aggregation);
    Assert.assertNull(aggregation.getType());
    query.configure(new BulletConfig());
    // Query no longer fixes type
    Assert.assertNull(aggregation.getType());
    Assert.assertEquals(aggregation.getSize(), new Integer(BulletConfig.DEFAULT_AGGREGATION_MAX_SIZE - 1));
}
Also used : BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 92 with BulletConfig

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

the class QueryTest method testCustomDuration.

@Test
public void testCustomDuration() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.QUERY_DEFAULT_DURATION, 200);
    config.set(BulletConfig.QUERY_MAX_DURATION, 1000);
    config.validate();
    Query query = new Query();
    query.setDuration(null);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query.setDuration(-1000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query.setDuration(0L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query.setDuration(1L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1L);
    query.setDuration(200L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 200L);
    query.setDuration(1000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1000L);
    query.setDuration(2000L);
    query.configure(config);
    Assert.assertEquals(query.getDuration(), (Long) 1000L);
}
Also used : BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 93 with BulletConfig

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

the class WindowTest method testConfiguration.

@Test
public void testConfiguration() {
    BulletConfig config = new BulletConfig();
    Window window = new Window();
    window.configure(config);
    Assert.assertNull(window.getEmitType());
    Assert.assertNull(window.getIncludeType());
    window = WindowUtils.makeWindow(Window.Unit.RECORD, 10);
    window.configure(config);
    Assert.assertEquals(window.getEmitType(), Window.Unit.RECORD);
    Assert.assertNull(window.getIncludeType());
    window = WindowUtils.makeWindow(Window.Unit.RECORD, 10);
    window.configure(config);
    window = WindowUtils.makeWindow(Window.Unit.TIME, 1000);
    window.configure(config);
    Assert.assertEquals(window.getEmitType(), Window.Unit.TIME);
    Assert.assertEquals(window.getEmit().get(Window.EMIT_EVERY_FIELD), 1000);
    config.set(BulletConfig.WINDOW_MIN_EMIT_EVERY, 5000);
    config.validate();
    window = WindowUtils.makeWindow(Window.Unit.TIME, 1000);
    Assert.assertEquals(window.getEmit().get(Window.EMIT_EVERY_FIELD), 1000);
    window.configure(config);
    Assert.assertEquals(window.getEmitType(), Window.Unit.TIME);
    Assert.assertEquals(window.getEmit().get(Window.EMIT_EVERY_FIELD), 5000);
}
Also used : BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 94 with BulletConfig

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

the class CountDistinctTest method testNewNamingOfResult.

@Test
public void testNewNamingOfResult() {
    BulletConfig config = makeConfiguration(4, 1024);
    CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("field"), Pair.of(Concept.SKETCH_METADATA, "stats"), Pair.of(Concept.SKETCH_ESTIMATED_RESULT, "est"));
    IntStream.range(0, 1000).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
    Clip clip = countDistinct.getResult();
    Map<String, Object> meta = clip.getMeta().asMap();
    Assert.assertEquals(meta.size(), 1);
    Assert.assertTrue(meta.containsKey("stats"));
    Map<String, Object> stats = (Map<String, Object>) meta.get("stats");
    Assert.assertEquals(stats.size(), 1);
    Assert.assertFalse((Boolean) stats.get("est"));
    Assert.assertEquals(clip.getRecords().size(), 1);
    BulletRecord actual = clip.getRecords().get(0);
    BulletRecord expected = RecordBox.get().add("myCount", 1000.0).getRecord();
    Assert.assertEquals(actual, expected);
    Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
    Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
}
Also used : IntStream(java.util.stream.IntStream) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) KMVSketch(com.yahoo.bullet.aggregations.sketches.KMVSketch) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Optional(java.util.Optional) ResizeFactor(com.yahoo.sketches.ResizeFactor) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 95 with BulletConfig

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

the class CountDistinctTest method testSingleFieldApproximateCountDistinctWithMetadata.

@Test
public void testSingleFieldApproximateCountDistinctWithMetadata() {
    BulletConfig config = makeConfiguration(4, 512);
    CountDistinct countDistinct = makeCountDistinct(config, asList("field"), Pair.of(Concept.SKETCH_METADATA, "aggregate_stats"), Pair.of(Concept.SKETCH_FAMILY, "family"), Pair.of(Concept.SKETCH_SIZE, "size"), Pair.of(Concept.SKETCH_THETA, "theta"), Pair.of(Concept.SKETCH_ESTIMATED_RESULT, "isEstimate"), Pair.of(Concept.SKETCH_STANDARD_DEVIATIONS, "stddev"));
    IntStream.range(0, 1000).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(countDistinct::consume);
    Assert.assertNotNull(countDistinct.getData());
    Clip clip = countDistinct.getResult();
    Map<String, Object> meta = clip.getMeta().asMap();
    Assert.assertEquals(meta.size(), 1);
    Assert.assertTrue(meta.containsKey("aggregate_stats"));
    Map<String, Object> stats = (Map<String, Object>) meta.get("aggregate_stats");
    Assert.assertEquals(stats.size(), 5);
    Assert.assertTrue((Boolean) stats.get("isEstimate"));
    Assert.assertEquals(stats.get("family").toString(), Family.ALPHA.getFamilyName());
    int size = (Integer) stats.get("size");
    // We inserted more than 512 unique entries
    Assert.assertTrue(size > 512);
    double theta = (Double) stats.get("theta");
    Assert.assertTrue(theta <= 1.0);
    Assert.assertTrue(stats.containsKey("stddev"));
    Map<String, Map<String, Double>> standardDeviations = (Map<String, Map<String, Double>>) stats.get("stddev");
    Assert.assertEquals(standardDeviations.size(), 3);
    Assert.assertEquals(clip.getRecords().size(), 1);
    BulletRecord actual = clip.getRecords().get(0);
    double actualEstimate = (Double) actual.get(CountDistinct.DEFAULT_NEW_NAME);
    double upperOneSigma = standardDeviations.get(KMVSketch.META_STD_DEV_1).get(KMVSketch.META_STD_DEV_UB);
    double lowerOneSigma = standardDeviations.get(KMVSketch.META_STD_DEV_1).get(KMVSketch.META_STD_DEV_LB);
    double upperTwoSigma = standardDeviations.get(KMVSketch.META_STD_DEV_2).get(KMVSketch.META_STD_DEV_UB);
    double lowerTwoSigma = standardDeviations.get(KMVSketch.META_STD_DEV_2).get(KMVSketch.META_STD_DEV_LB);
    double upperThreeSigma = standardDeviations.get(KMVSketch.META_STD_DEV_3).get(KMVSketch.META_STD_DEV_UB);
    double lowerThreeSigma = standardDeviations.get(KMVSketch.META_STD_DEV_3).get(KMVSketch.META_STD_DEV_LB);
    Assert.assertTrue(actualEstimate >= lowerOneSigma);
    Assert.assertTrue(actualEstimate <= upperOneSigma);
    Assert.assertTrue(actualEstimate >= lowerTwoSigma);
    Assert.assertTrue(actualEstimate <= upperTwoSigma);
    Assert.assertTrue(actualEstimate >= lowerThreeSigma);
    Assert.assertTrue(actualEstimate <= upperThreeSigma);
    Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
    Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
}
Also used : IntStream(java.util.stream.IntStream) BulletRecord(com.yahoo.bullet.record.BulletRecord) Aggregation(com.yahoo.bullet.parsing.Aggregation) KMVSketch(com.yahoo.bullet.aggregations.sketches.KMVSketch) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Optional(java.util.Optional) ResizeFactor(com.yahoo.sketches.ResizeFactor) AggregationUtils.makeGroupFields(com.yahoo.bullet.parsing.AggregationUtils.makeGroupFields) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

BulletConfig (com.yahoo.bullet.common.BulletConfig)101 Test (org.testng.annotations.Test)87 Aggregation (com.yahoo.bullet.parsing.Aggregation)37 List (java.util.List)25 Query (com.yahoo.bullet.parsing.Query)20 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)17 BulletError (com.yahoo.bullet.common.BulletError)16 BulletRecord (com.yahoo.bullet.record.BulletRecord)16 Arrays.asList (java.util.Arrays.asList)16 Clip (com.yahoo.bullet.result.Clip)14 Collections.singletonList (java.util.Collections.singletonList)12 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)11 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)11 Map (java.util.Map)11 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)10 Window (com.yahoo.bullet.parsing.Window)10 Concept (com.yahoo.bullet.result.Meta.Concept)10 RecordBox (com.yahoo.bullet.result.RecordBox)10 ArrayList (java.util.ArrayList)10 IntStream (java.util.stream.IntStream)10