Search in sources :

Example 1 with Having

use of com.yahoo.bullet.query.postaggregations.Having in project bullet-core by yahoo.

the class HavingStrategyTest method testHaving.

@Test
public void testHaving() {
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 6).getRecord());
    records.add(RecordBox.get().add("a", 1).getRecord());
    records.add(RecordBox.get().add("a", 8).getRecord());
    records.add(RecordBox.get().add("a", 2).getRecord());
    records.add(RecordBox.get().add("b", 10).getRecord());
    records.add(RecordBox.get().add("a", 7).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    // a > 5
    BinaryExpression expression = new BinaryExpression(new FieldExpression("a"), new ValueExpression(5), Operation.GREATER_THAN);
    HavingStrategy strategy = (HavingStrategy) new Having(expression).getPostStrategy();
    Clip result = strategy.execute(clip);
    Assert.assertEquals(result.getRecords().size(), 3);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 6);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 7);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) ArrayList(java.util.ArrayList) Having(com.yahoo.bullet.query.postaggregations.Having) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)1 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)1 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)1 Having (com.yahoo.bullet.query.postaggregations.Having)1 BulletRecord (com.yahoo.bullet.record.BulletRecord)1 Clip (com.yahoo.bullet.result.Clip)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1