use of com.yahoo.bullet.query.aggregations.GroupBy in project bullet-core by yahoo.
the class QuerierTest method testOuterQuery.
@Test
public void testOuterQuery() {
Expression outerQueryFilter = new BinaryExpression(new FieldExpression("count"), new ValueExpression(1), Operation.GREATER_THAN);
Query outerQuery = new Query(new Projection(), outerQueryFilter, new Raw(3), null, new Window(), null);
GroupBy groupBy = new GroupBy(null, singletonMap("color", "color"), singleton(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count")));
Query query = new Query(null, new Projection(), null, groupBy, null, outerQuery, new Window(), null);
Querier querier = make(Querier.Mode.ALL, query);
BulletRecord red = RecordBox.get().add("color", "red").getRecord();
BulletRecord orange = RecordBox.get().add("color", "orange").getRecord();
BulletRecord yellow = RecordBox.get().add("color", "yellow").getRecord();
BulletRecord green = RecordBox.get().add("color", "green").getRecord();
BulletRecord blue = RecordBox.get().add("color", "blue").getRecord();
BulletRecord indigo = RecordBox.get().add("color", "indigo").getRecord();
BulletRecord violet = RecordBox.get().add("color", "violet").getRecord();
querier.consume(red);
querier.consume(orange);
querier.consume(yellow);
querier.consume(green);
querier.consume(blue);
querier.consume(indigo);
querier.consume(violet);
querier.consume(yellow);
querier.consume(green);
querier.consume(blue);
querier.consume(indigo);
querier.consume(violet);
Clip result = querier.getResult();
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 3);
Assert.assertFalse(records.stream().anyMatch(record -> record.typedGet("color").getValue().equals("red") || record.typedGet("color").getValue().equals("orange")));
Assert.assertTrue(records.stream().allMatch(record -> record.typedGet("count").getValue().equals(2L)));
Map<String, Object> metadata = result.getMeta().asMap();
Assert.assertTrue(metadata.containsKey("Inner Query"));
}
use of com.yahoo.bullet.query.aggregations.GroupBy in project bullet-core by yahoo.
the class QueryUtils method makeGroupByFilterQuery.
public static Query makeGroupByFilterQuery(Expression filter, int size, Map<String, String> fields, List<GroupOperation> operations) {
Query query = new Query(new Projection(), filter, new GroupBy(size, fields, new HashSet<>(operations)), null, new Window(), null);
query.configure(new BulletConfig());
return query;
}
Aggregations