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