use of com.yahoo.bullet.query.postaggregations.Culling in project bullet-core by yahoo.
the class QuerierTest method testComputationAndCulling.
@Test
public void testComputationAndCulling() {
Projection projection = new Projection(Arrays.asList(new Field("a", new FieldExpression("a")), new Field("b", new FieldExpression("b"))), false);
Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
Expression expression = new BinaryExpression(new FieldExpression("a"), new ValueExpression(2L), Operation.ADD);
Computation computation = new Computation(Collections.singletonList(new Field("newName", expression)));
Culling culling = new Culling(singleton("a"));
Query query = new Query(projection, filter, new Raw(500), Arrays.asList(computation, culling), new Window(), null);
Querier querier = make(Querier.Mode.ALL, query);
IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", i).add("b", i).getRecord()));
List<BulletRecord> result = querier.getResult().getRecords();
Assert.assertEquals(result.size(), 4);
Assert.assertEquals(result.get(0).typedGet("newName").getValue(), 2L);
Assert.assertFalse(result.get(0).hasField("a"));
Assert.assertEquals(result.get(0).typedGet("b").getValue(), 0);
Assert.assertEquals(result.get(1).typedGet("newName").getValue(), 3L);
Assert.assertFalse(result.get(1).hasField("a"));
Assert.assertEquals(result.get(1).typedGet("b").getValue(), 1);
Assert.assertEquals(result.get(2).typedGet("newName").getValue(), 4L);
Assert.assertFalse(result.get(2).hasField("a"));
Assert.assertEquals(result.get(2).typedGet("b").getValue(), 2);
Assert.assertEquals(result.get(3).typedGet("newName").getValue(), 5L);
Assert.assertFalse(result.get(3).hasField("a"));
Assert.assertEquals(result.get(3).typedGet("b").getValue(), 3);
}
use of com.yahoo.bullet.query.postaggregations.Culling in project bullet-core by yahoo.
the class CullingStrategyTest method testCulling.
@Test
public void testCulling() {
List<BulletRecord> records = new ArrayList<>();
records.add(RecordBox.get().add("a", 1).add("b", 2).add("c", 3).getRecord());
records.add(RecordBox.get().add("a", 4).add("b", 5).add("c", 6).getRecord());
records.add(RecordBox.get().add("a", 7).add("b", 8).add("c", 9).getRecord());
Clip clip = new Clip();
clip.add(records);
Set<String> transientFields = new HashSet<>(Arrays.asList("a", "b"));
CullingStrategy strategy = (CullingStrategy) new Culling(transientFields).getPostStrategy();
Clip result = strategy.execute(clip);
Assert.assertEquals(result.getRecords().size(), 3);
Assert.assertTrue(result.getRecords().get(0).typedGet("a").isNull());
Assert.assertTrue(result.getRecords().get(0).typedGet("b").isNull());
Assert.assertEquals(result.getRecords().get(0).typedGet("c").getValue(), 3);
Assert.assertTrue(result.getRecords().get(1).typedGet("a").isNull());
Assert.assertTrue(result.getRecords().get(1).typedGet("b").isNull());
Assert.assertEquals(result.getRecords().get(1).typedGet("c").getValue(), 6);
Assert.assertTrue(result.getRecords().get(2).typedGet("a").isNull());
Assert.assertTrue(result.getRecords().get(2).typedGet("b").isNull());
Assert.assertEquals(result.getRecords().get(2).typedGet("c").getValue(), 9);
}
Aggregations