use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.
the class QuerierTest method testFilteringProjection.
@Test
public void testFilteringProjection() {
Projection projection = new Projection(Collections.singletonList(new Field("mid", new FieldExpression("map_field", "id"))), false);
Expression filter = new BinaryExpression(new FieldExpression("map_field", "id"), new ListExpression(Arrays.asList(new ValueExpression("1"), new ValueExpression("23"))), Operation.EQUALS_ANY);
Query query = new Query(projection, filter, new Raw(null), null, new Window(), null);
BulletConfig config = new BulletConfig();
query.configure(config);
Querier querier = new Querier(makeRunningQuery("", query), config);
RecordBox boxA = RecordBox.get().addMap("map_field", Pair.of("id", "3"));
querier.consume(boxA.getRecord());
Assert.assertFalse(querier.isClosed());
Assert.assertNull(querier.getData());
RecordBox boxB = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
RecordBox expected = RecordBox.get().add("mid", "23");
querier.consume(boxB.getRecord());
Assert.assertFalse(querier.isClosed());
Assert.assertEquals(querier.getData(), getListBytes(expected.getRecord()));
}
use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.
the class QuerierTest method testLogicFilterNot.
@Test
public void testLogicFilterNot() {
// legacy test
Expression filter = new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.NOT_EQUALS);
Query query = new Query(new Projection(), filter, new Raw(null), null, new Window(), null);
Querier querier = make(Querier.Mode.PARTITION, query);
querier.consume(RecordBox.get().add("field", "abc").getRecord());
Assert.assertFalse(querier.hasNewData());
querier.consume(RecordBox.get().add("field", "ddd").getRecord());
Assert.assertTrue(querier.hasNewData());
}
use of com.yahoo.bullet.query.expressions.ValueExpression in project bullet-core by yahoo.
the class QuerierTest method testBasicWindowMaximumEmittedWithNonMatchingRecords.
@Test
public void testBasicWindowMaximumEmittedWithNonMatchingRecords() {
Expression filter = new BinaryExpression(new FieldExpression("mid"), new ListExpression(Arrays.asList(new ValueExpression("1"), new ValueExpression("23"))), Operation.EQUALS_ANY);
Query query = new Query(new Projection(), filter, new Raw(2), null, new Window(), null);
Querier querier = make(Querier.Mode.PARTITION, query);
byte[] expected = getListBytes(RecordBox.get().add("mid", "23").getRecord());
byte[] expectedTwice = getListBytes(RecordBox.get().add("mid", "23").getRecord(), RecordBox.get().add("mid", "23").getRecord());
querier.consume(RecordBox.get().add("mid", "23").getRecord());
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.isDone());
Assert.assertTrue(querier.hasNewData());
Assert.assertEquals(querier.getData(), expected);
// Doesn't match
querier.consume(RecordBox.get().add("mid", "42").getRecord());
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.isDone());
Assert.assertTrue(querier.hasNewData());
Assert.assertEquals(querier.getData(), expected);
querier.consume(RecordBox.get().add("mid", "23").getRecord());
Assert.assertTrue(querier.isClosed());
Assert.assertTrue(querier.isDone());
Assert.assertTrue(querier.hasNewData());
Assert.assertEquals(querier.getData(), expectedTwice);
// Nothing else is consumed because RAW is closed
IntStream.range(0, 10).mapToObj(i -> RecordBox.get().add("mid", "23").getRecord()).forEach(querier::consume);
Assert.assertTrue(querier.isClosed());
Assert.assertTrue(querier.isDone());
Assert.assertTrue(querier.hasNewData());
Assert.assertEquals(querier.getData(), expectedTwice);
querier.reset();
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.isDone());
Assert.assertFalse(querier.hasNewData());
Assert.assertNull(querier.getData());
}
use of com.yahoo.bullet.query.expressions.ValueExpression 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.expressions.ValueExpression 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"));
}
Aggregations