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