Search in sources :

Example 61 with BulletRecord

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

the class GroupData method getAsBulletRecord.

/**
 * Gets the metrics and the group values stored as a {@link BulletRecord}.
 *
 * @param mapping An non-null new name mapping for the names of the group fields.
 * @return A non-null {@link BulletRecord} containing the data stored in this object.
 */
public BulletRecord getAsBulletRecord(Map<String, String> mapping) {
    BulletRecord record = getMetricsAsBulletRecord();
    for (Map.Entry<String, String> e : groupFields.entrySet()) {
        String field = e.getKey();
        String mapped = mapping.get(field);
        record.setString(Utilities.isEmpty(mapped) ? field : mapped, e.getValue());
    }
    return record;
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with BulletRecord

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

the class GroupData method getMetricsAsBulletRecord.

/**
 * Gets the metrics stored for the group as a {@link BulletRecord}.
 *
 * @return A non-null {@link BulletRecord} containing the data stored in this object.
 */
public BulletRecord getMetricsAsBulletRecord() {
    BulletRecord record = new BulletRecord();
    metrics.entrySet().stream().forEach(e -> addToRecord(e, record));
    return record;
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord)

Example 63 with BulletRecord

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

the class ProjectionOperations method project.

/**
 * Projects the given {@link BulletRecord} based on the given {@link Projection}.
 *
 * @param record The record to project.
 * @param projection The projection to apply.
 * @return The projected record.
 */
public static BulletRecord project(BulletRecord record, Projection projection) {
    Map<String, String> fields = projection.getFields();
    // Returning the record itself if no projections. The record itself should never be modified so it's ok.
    if (fields == null) {
        return record;
    }
    // More efficient if fields << the fields in the BulletRecord
    BulletRecord projected = new BulletRecord();
    for (Map.Entry<String, String> e : fields.entrySet()) {
        String field = e.getKey();
        String newName = e.getValue();
        try {
            copyInto(projected, newName, record, field);
        } catch (ClassCastException cce) {
            log.warn("Skipping copying {} as {} as it is not a field that can be extracted", field, newName);
        }
    }
    return projected;
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map)

Example 64 with BulletRecord

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

the class FilterOperationsTest method testNotMultiple.

@Test
public void testNotMultiple() {
    // NOT(id IN [1, 3, 5], field NOT IN ["foo"])
    // Only the id is negated
    LogicalClause clause = clause(NOT, clause("id", EQUALS, "1", "3", "5"), clause("field", NOT_EQUALS, "foo"));
    BulletRecord recordA = RecordBox.get().add("id", 5).add("field", "foo").getRecord();
    BulletRecord recordB = RecordBox.get().add("id", 3).add("field", "bar").getRecord();
    BulletRecord recordC = RecordBox.get().add("id", 1).getRecord();
    BulletRecord recordD = RecordBox.get().add("field", "baz").getRecord();
    BulletRecord recordE = RecordBox.get().getRecord();
    Assert.assertFalse(FilterOperations.perform(recordA, clause));
    Assert.assertFalse(FilterOperations.perform(recordB, clause));
    Assert.assertFalse(FilterOperations.perform(recordC, clause));
    Assert.assertTrue(FilterOperations.perform(recordD, clause));
    Assert.assertTrue(FilterOperations.perform(recordE, clause));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Example 65 with BulletRecord

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

the class FilterOperationsTest method testOr.

@Test
public void testOr() {
    // id IN [1, 3, 5] OR field NOT IN ["foo"]
    LogicalClause clause = clause(OR, clause("id", EQUALS, "1", "3", "5"), clause("field", NOT_EQUALS, "foo"));
    BulletRecord recordA = RecordBox.get().add("id", 5).add("field", "foo").getRecord();
    BulletRecord recordB = RecordBox.get().add("id", 3).add("field", "bar").getRecord();
    BulletRecord recordC = RecordBox.get().add("id", 3).getRecord();
    BulletRecord recordD = RecordBox.get().add("field", "baz").getRecord();
    BulletRecord recordE = RecordBox.get().add("id", 2).add("field", "foo").getRecord();
    BulletRecord recordF = RecordBox.get().getRecord();
    Assert.assertTrue(FilterOperations.perform(recordA, clause));
    Assert.assertTrue(FilterOperations.perform(recordB, clause));
    Assert.assertTrue(FilterOperations.perform(recordC, clause));
    Assert.assertTrue(FilterOperations.perform(recordD, clause));
    Assert.assertFalse(FilterOperations.perform(recordE, clause));
    // field != "foo" is true because field is null
    Assert.assertTrue(FilterOperations.perform(recordF, clause));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Aggregations

BulletRecord (com.yahoo.bullet.record.BulletRecord)210 Test (org.testng.annotations.Test)196 Tuple (org.apache.storm.tuple.Tuple)55 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)53 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)53 TopKTest (com.yahoo.bullet.aggregations.TopKTest)53 Clip (com.yahoo.bullet.result.Clip)53 HashMap (java.util.HashMap)53 Map (java.util.Map)53 BulletConfig (com.yahoo.bullet.common.BulletConfig)46 List (java.util.List)45 IntStream (java.util.stream.IntStream)45 Assert (org.testng.Assert)45 RecordBox (com.yahoo.bullet.result.RecordBox)43 Arrays.asList (java.util.Arrays.asList)40 Pair (org.apache.commons.lang3.tuple.Pair)40 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)34 BulletError (com.yahoo.bullet.common.BulletError)33 Aggregation (com.yahoo.bullet.parsing.Aggregation)33 Concept (com.yahoo.bullet.result.Meta.Concept)33