Search in sources :

Example 16 with Projection

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

the class QuerierTest method testBasicWindowMaximumEmitted.

@Test
public void testBasicWindowMaximumEmitted() {
    Query query = new Query(new Projection(), null, new Raw(2), null, new Window(), null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    byte[] expected = getListBytes(RecordBox.get().getRecord());
    byte[] expectedTwice = getListBytes(RecordBox.get().getRecord(), RecordBox.get().getRecord());
    querier.consume(RecordBox.get().getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expected);
    querier.consume(RecordBox.get().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
    makeStream(10).forEach(querier::consume);
    Assert.assertTrue(querier.isClosed());
    Assert.assertTrue(querier.isDone());
    Assert.assertTrue(querier.hasNewData());
    Assert.assertEquals(querier.getData(), expectedTwice);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 17 with Projection

use of com.yahoo.bullet.query.Projection 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);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) Computation(com.yahoo.bullet.query.postaggregations.Computation) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Culling(com.yahoo.bullet.query.postaggregations.Culling) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 18 with Projection

use of com.yahoo.bullet.query.Projection 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"));
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Arrays(java.util.Arrays) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) BulletError(com.yahoo.bullet.common.BulletError) Strategy(com.yahoo.bullet.querying.aggregations.Strategy) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) TestHelpers.getListBytes(com.yahoo.bullet.TestHelpers.getListBytes) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) Pair(org.apache.commons.lang3.tuple.Pair) Collections.singleton(java.util.Collections.singleton) Computation(com.yahoo.bullet.query.postaggregations.Computation) Raw(com.yahoo.bullet.query.aggregations.Raw) Map(java.util.Map) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Metadata(com.yahoo.bullet.pubsub.Metadata) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest) Culling(com.yahoo.bullet.query.postaggregations.Culling) BulletRecord(com.yahoo.bullet.record.BulletRecord) Scheme(com.yahoo.bullet.windowing.Scheme) AdditiveTumbling(com.yahoo.bullet.windowing.AdditiveTumbling) AdditionalAnswers(org.mockito.AdditionalAnswers) WindowUtils(com.yahoo.bullet.query.WindowUtils) List(java.util.List) Field(com.yahoo.bullet.query.Field) Stream(java.util.stream.Stream) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) BulletConfig(com.yahoo.bullet.common.BulletConfig) IntStream(java.util.stream.IntStream) AggregationType(com.yahoo.bullet.query.aggregations.AggregationType) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Operation(com.yahoo.bullet.query.expressions.Operation) Clip(com.yahoo.bullet.result.Clip) Assert(org.testng.Assert) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) GroupAll(com.yahoo.bullet.query.aggregations.GroupAll) Collections.singletonMap(java.util.Collections.singletonMap) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Basic(com.yahoo.bullet.windowing.Basic) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Window(com.yahoo.bullet.query.Window) Meta(com.yahoo.bullet.result.Meta) Tumbling(com.yahoo.bullet.windowing.Tumbling) Expression(com.yahoo.bullet.query.expressions.Expression) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Mockito(org.mockito.Mockito) Projection(com.yahoo.bullet.query.Projection) CountDistinct(com.yahoo.bullet.query.aggregations.CountDistinct) OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Collections(java.util.Collections) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 19 with Projection

use of com.yahoo.bullet.query.Projection 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);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 20 with Projection

use of com.yahoo.bullet.query.Projection 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());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Aggregations

Projection (com.yahoo.bullet.query.Projection)29 Query (com.yahoo.bullet.query.Query)29 Window (com.yahoo.bullet.query.Window)28 Raw (com.yahoo.bullet.query.aggregations.Raw)27 Test (org.testng.annotations.Test)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)18 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 BulletConfig (com.yahoo.bullet.common.BulletConfig)11 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)11 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)11 Expression (com.yahoo.bullet.query.expressions.Expression)10 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3 Operation (com.yahoo.bullet.query.expressions.Operation)3