use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QuerierTest method testMerging.
@Test
public void testMerging() {
Query query = new Query(new Projection(), null, new Raw(2), null, new Window(), null);
Querier querierA = make(Querier.Mode.PARTITION, query);
Querier querierB = make(Querier.Mode.PARTITION, query);
byte[] expected = getListBytes(RecordBox.get().getRecord());
byte[] expectedTwice = getListBytes(RecordBox.get().getRecord(), RecordBox.get().getRecord());
querierA.consume(RecordBox.get().getRecord());
Assert.assertFalse(querierA.isClosed());
Assert.assertFalse(querierA.isDone());
Assert.assertTrue(querierA.hasNewData());
Assert.assertEquals(querierA.getData(), expected);
querierB.consume(RecordBox.get().getRecord());
Assert.assertFalse(querierB.isClosed());
Assert.assertFalse(querierB.isDone());
Assert.assertTrue(querierB.hasNewData());
Assert.assertEquals(querierB.getData(), expected);
Querier querierC = make(Querier.Mode.ALL, query);
querierC.merge(querierA);
querierC.merge(querierB);
Assert.assertTrue(querierC.isClosed());
Assert.assertTrue(querierC.isDone());
Assert.assertTrue(querierC.hasNewData());
Assert.assertEquals(querierC.getData(), expectedTwice);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QuerierTest method testDefaults.
@Test
public void testDefaults() {
Querier querier = make(Querier.Mode.ALL, new Query(new Projection(), null, new Raw(null), null, new Window(), null));
RunningQuery runningQuery = querier.getRunningQuery();
Query query = querier.getQuery();
Assert.assertSame(runningQuery.getQuery(), query);
Assert.assertEquals(query.getAggregation().getSize(), (Integer) BulletConfig.DEFAULT_AGGREGATION_SIZE);
Assert.assertEquals(query.getAggregation().getType(), AggregationType.RAW);
Assert.assertFalse(querier.isClosed());
Assert.assertFalse(querier.isDone());
Assert.assertFalse(querier.isExceedingRateLimit());
Assert.assertNull(querier.getRateLimitError());
// RAW query without window should buffer
Assert.assertTrue(querier.shouldBuffer());
Assert.assertEquals(querier.getResult().getRecords(), Collections.emptyList());
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QuerierTest method testLogicFilterOr.
@Test
public void testLogicFilterOr() {
// legacy test
Expression filter = new BinaryExpression(new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.EQUALS), new BinaryExpression(new FieldExpression("id"), new ValueExpression("1"), Operation.EQUALS), Operation.OR);
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").add("id", "2").getRecord());
Assert.assertTrue(querier.hasNewData());
querier.consume(RecordBox.get().add("field", "abc").add("id", "1").getRecord());
Assert.assertTrue(querier.hasNewData());
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QuerierTest method testOrderBy.
@Test
public void testOrderBy() {
Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
OrderBy orderBy = new OrderBy(Collections.singletonList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC)));
Query query = new Query(new Projection(), filter, new Raw(500), Collections.singletonList(orderBy), new Window(), null);
Querier querier = make(Querier.Mode.ALL, query);
IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", 10 - i).add("b", i + 10).getRecord()));
List<BulletRecord> result = querier.getResult().getRecords();
Assert.assertEquals(result.size(), 4);
Assert.assertEquals(result.get(0).typedGet("a").getValue(), 10);
Assert.assertEquals(result.get(0).typedGet("b").getValue(), 10);
Assert.assertEquals(result.get(1).typedGet("a").getValue(), 9);
Assert.assertEquals(result.get(1).typedGet("b").getValue(), 11);
Assert.assertEquals(result.get(2).typedGet("a").getValue(), 8);
Assert.assertEquals(result.get(2).typedGet("b").getValue(), 12);
Assert.assertEquals(result.get(3).typedGet("a").getValue(), 7);
Assert.assertEquals(result.get(3).typedGet("b").getValue(), 13);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QuerierTest method testFiltering.
@Test
public void testFiltering() {
Expression filter = new BinaryExpression(new FieldExpression("field"), new ListExpression(Arrays.asList(new ValueExpression("foo"), new ValueExpression("bar"))), Operation.EQUALS_ANY);
Window window = WindowUtils.makeSlidingWindow(1);
Query query = new Query(new Projection(), filter, new Raw(null), null, window, null);
Querier querier = make(Querier.Mode.PARTITION, query);
querier.consume(RecordBox.get().add("field", "foo").getRecord());
Assert.assertTrue(querier.isClosed());
querier.reset();
querier.consume(RecordBox.get().add("field", "bar").getRecord());
Assert.assertTrue(querier.isClosed());
querier.reset();
querier.consume(RecordBox.get().add("field", "baz").getRecord());
Assert.assertFalse(querier.isClosed());
}
Aggregations