Search in sources :

Example 1 with BulletRecordProvider

use of com.yahoo.bullet.record.BulletRecordProvider in project bullet-core by yahoo.

the class BulletConfigTest method testGetBulletRecordProvider.

@Test
public void testGetBulletRecordProvider() {
    BulletConfig config = new BulletConfig();
    BulletRecordProvider providerA = config.getBulletRecordProvider();
    BulletRecordProvider providerB = config.getBulletRecordProvider();
    // Uses the same provider
    Assert.assertSame(providerA, providerB);
}
Also used : TypedSimpleBulletRecordProvider(com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider) BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) TypedAvroBulletRecordProvider(com.yahoo.bullet.record.avro.TypedAvroBulletRecordProvider) Test(org.testng.annotations.Test)

Example 2 with BulletRecordProvider

use of com.yahoo.bullet.record.BulletRecordProvider in project bullet-core by yahoo.

the class BulletConfigTest method testCreateBulletRecordProvider.

@Test
public void testCreateBulletRecordProvider() {
    BulletConfig config = new BulletConfig();
    BulletRecordProvider providerA = config.createBulletRecordProvider();
    BulletRecordProvider providerB = config.createBulletRecordProvider();
    // Creates a new provider each time
    Assert.assertNotSame(providerA, providerB);
    // Ensure the provider generates new records each time
    BulletRecord recordA = providerA.getInstance();
    BulletRecord recordB = providerA.getInstance();
    Assert.assertNotNull(recordA);
    Assert.assertNotNull(recordB);
    recordB.setString("someField", "someValue");
    Assert.assertEquals(recordB.typedGet("someField"), new TypedObject(Type.STRING, "someValue"));
    Assert.assertTrue(recordA.typedGet("someField").isNull());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) TypedObject(com.yahoo.bullet.typesystem.TypedObject) TypedSimpleBulletRecordProvider(com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider) BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) TypedAvroBulletRecordProvider(com.yahoo.bullet.record.avro.TypedAvroBulletRecordProvider) Test(org.testng.annotations.Test)

Example 3 with BulletRecordProvider

use of com.yahoo.bullet.record.BulletRecordProvider in project bullet-core by yahoo.

the class QuantileSketchingStrategy method getSketch.

private static QuantileSketch getSketch(Distribution aggregation, BulletConfig config) {
    int entries = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_SKETCH_ENTRIES, Integer.class);
    int rounding = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_GENERATED_POINTS_ROUNDING, Integer.class);
    int pointLimit = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_MAX_POINTS, Integer.class);
    int maxPoints = Math.min(pointLimit, aggregation.getSize());
    BulletRecordProvider provider = config.getBulletRecordProvider();
    if (aggregation instanceof LinearDistribution) {
        int numberOfPoints = ((LinearDistribution) aggregation).getNumberOfPoints();
        return new QuantileSketch(entries, rounding, aggregation.getDistributionType(), Math.min(numberOfPoints, maxPoints), provider);
    } else if (aggregation instanceof ManualDistribution) {
        // Limit number of points
        List<Double> points = ((ManualDistribution) aggregation).getPoints();
        double[] cleanedPoints = points.stream().limit(maxPoints).mapToDouble(d -> d).toArray();
        return new QuantileSketch(entries, aggregation.getDistributionType(), cleanedPoints, provider);
    } else if (aggregation instanceof RegionDistribution) {
        RegionDistribution distribution = (RegionDistribution) aggregation;
        double start = distribution.getStart();
        double end = distribution.getEnd();
        double increment = distribution.getIncrement();
        return new QuantileSketch(entries, aggregation.getDistributionType(), getPoints(start, end, increment, maxPoints, rounding), provider);
    }
    throw new IllegalArgumentException("Unknown distribution input mode.");
}
Also used : RegionDistribution(com.yahoo.bullet.query.aggregations.RegionDistribution) LinearDistribution(com.yahoo.bullet.query.aggregations.LinearDistribution) BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) List(java.util.List) ManualDistribution(com.yahoo.bullet.query.aggregations.ManualDistribution) QuantileSketch(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch)

Example 4 with BulletRecordProvider

use of com.yahoo.bullet.record.BulletRecordProvider in project bullet-core by yahoo.

the class ExplodeFunctor method explodeMap.

private List<BulletRecord> explodeMap(BulletRecord record, BulletRecordProvider provider) {
    TypedObject typedObject = getField(record);
    if (!typedObject.isMap() || typedObject.size() == 0) {
        return Collections.emptyList();
    }
    Map<String, Serializable> map = (Map<String, Serializable>) typedObject.getValue();
    return map.entrySet().stream().map(entry -> getRecord(entry, provider)).collect(Collectors.toList());
}
Also used : BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) TypedObject(com.yahoo.bullet.typesystem.TypedObject) List(java.util.List) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Evaluator(com.yahoo.bullet.querying.evaluators.Evaluator) Serializable(java.io.Serializable) Serializable(java.io.Serializable) TypedObject(com.yahoo.bullet.typesystem.TypedObject) Map(java.util.Map)

Example 5 with BulletRecordProvider

use of com.yahoo.bullet.record.BulletRecordProvider in project bullet-core by yahoo.

the class ExplodeFunctor method explodeList.

private List<BulletRecord> explodeList(BulletRecord record, BulletRecordProvider provider) {
    TypedObject typedObject = getField(record);
    if (!typedObject.isList() || typedObject.size() == 0) {
        return Collections.emptyList();
    }
    List<Serializable> list = (List<Serializable>) typedObject.getValue();
    return list.stream().map(object -> getRecord(object, provider)).collect(Collectors.toList());
}
Also used : BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) TypedObject(com.yahoo.bullet.typesystem.TypedObject) List(java.util.List) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Evaluator(com.yahoo.bullet.querying.evaluators.Evaluator) Serializable(java.io.Serializable) Serializable(java.io.Serializable) TypedObject(com.yahoo.bullet.typesystem.TypedObject) List(java.util.List)

Aggregations

BulletRecordProvider (com.yahoo.bullet.record.BulletRecordProvider)5 BulletRecord (com.yahoo.bullet.record.BulletRecord)3 TypedObject (com.yahoo.bullet.typesystem.TypedObject)3 List (java.util.List)3 Explode (com.yahoo.bullet.query.tablefunctions.Explode)2 Evaluator (com.yahoo.bullet.querying.evaluators.Evaluator)2 TypedAvroBulletRecordProvider (com.yahoo.bullet.record.avro.TypedAvroBulletRecordProvider)2 TypedSimpleBulletRecordProvider (com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider)2 Serializable (java.io.Serializable)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Test (org.testng.annotations.Test)2 LinearDistribution (com.yahoo.bullet.query.aggregations.LinearDistribution)1 ManualDistribution (com.yahoo.bullet.query.aggregations.ManualDistribution)1 RegionDistribution (com.yahoo.bullet.query.aggregations.RegionDistribution)1 QuantileSketch (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch)1