Search in sources :

Example 46 with Query

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

the class QueryManagerTest method testQuerySeeingStatistics.

@Test
public void testQuerySeeingStatistics() {
    QueryManager manager = new QueryManager(getEqualityPartitionerConfig("A", "B"));
    Query queryA = getQuery(ImmutablePair.of("A", "foo"));
    Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
    Query queryC = getQuery();
    Querier querierA = getQuerier(queryA);
    Querier querierB = getQuerier(queryB);
    Querier querierC = getQuerier(queryC);
    manager.addQuery("idA", querierA);
    manager.addQuery("idB", querierB);
    manager.addQuery("idC", querierC);
    BulletRecord recordA = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
    BulletRecord recordB = RecordBox.get().add("A", "foo").getRecord();
    BulletRecord recordC = RecordBox.get().getRecord();
    Map<QueryManager.PartitionStat, Object> stats;
    manager.categorize(recordA);
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 3L);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 3L);
    manager.categorize(recordB);
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 5L);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 6L);
    manager.categorize(recordC);
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 6L);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 9L);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) Test(org.testng.annotations.Test)

Example 47 with Query

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

the class QueryManagerTest method testCategorizingNoPartitioning.

@Test
public void testCategorizingNoPartitioning() {
    QueryManager manager = new QueryManager(new BulletConfig());
    Query queryA = getQuery(ImmutablePair.of("A", "foo"));
    Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
    Querier querierA = getQuerier(queryA);
    Querier querierB = getQuerier(queryB);
    manager.addQuery("idA", querierA);
    manager.addQuery("idB", querierB);
    BulletRecord recordA = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
    BulletRecord recordB = RecordBox.get().add("A", "foo").getRecord();
    QueryCategorizer categorizer = manager.categorize(recordA);
    Assert.assertEquals(categorizer.getDone().size(), 0);
    Assert.assertEquals(categorizer.getClosed().size(), 0);
    Assert.assertEquals(categorizer.getRateLimited().size(), 0);
    verify(querierA, times(1)).consume(recordA);
    verify(querierB, times(1)).consume(recordA);
    categorizer = manager.categorize(recordB);
    Assert.assertEquals(categorizer.getDone().size(), 0);
    Assert.assertEquals(categorizer.getClosed().size(), 0);
    Assert.assertEquals(categorizer.getRateLimited().size(), 0);
    verify(querierA, times(1)).consume(recordB);
    verify(querierB, times(1)).consume(recordB);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 48 with Query

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

the class QueryManagerTest method addQuerier.

private static void addQuerier(QueryManager manager, int i, int j, Map<String, Querier> queriers) {
    String value = String.valueOf(i);
    String id = String.valueOf((i * 100) + j);
    Query query = getQuery(ImmutablePair.of("A", value));
    Querier querier = getQuerier(query);
    queriers.put(id, querier);
    manager.addQuery(id, querier);
}
Also used : Query(com.yahoo.bullet.query.Query)

Example 49 with Query

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

the class QueryManagerTest method testPartitionRemoval.

@Test
public void testPartitionRemoval() {
    QueryManager manager = new QueryManager(getEqualityPartitionerConfig("A", "B"));
    Query queryA = getQuery(ImmutablePair.of("A", "foo"));
    Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
    Query queryC = getQuery();
    manager.addQuery("idA", getQuerier(queryA));
    manager.addQuery("idB", getQuerier(queryB));
    manager.addQuery("idC", getQuerier(queryC));
    manager.addQuery("idD", getQuerier(queryC));
    Map<QueryManager.PartitionStat, Object> stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 4);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 3);
    manager.removeAndGetQuery("idA");
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 3);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 2);
    manager.removeAndGetQuery("idB");
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 2);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 1);
    manager.removeAndGetQuery("idD");
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 1);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 1);
    manager.removeAndGetQuery("idC");
    stats = manager.getStats();
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 0);
    Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 0);
}
Also used : Query(com.yahoo.bullet.query.Query) Test(org.testng.annotations.Test)

Example 50 with Query

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

the class PubSubMessageTest method testReadingDataAsDifferentTypes.

@Test
public void testReadingDataAsDifferentTypes() {
    String string = getRandomString();
    byte[] bytes = getRandomBytes();
    Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), Long.MAX_VALUE);
    PubSubMessage message;
    message = new PubSubMessage("foo", string);
    Assert.assertEquals(message.getContent(), string);
    Assert.assertEquals(message.getContentAsString(), string);
    message = new PubSubMessage("foo", bytes);
    Assert.assertEquals(message.getContent(), bytes);
    Assert.assertEquals(message.getContentAsByteArray(), bytes);
    message = new PubSubMessage("foo", query);
    Assert.assertSame(message.getContent(), query);
    Assert.assertSame(message.getContentAsQuery(), query);
}
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)

Aggregations

Query (com.yahoo.bullet.query.Query)62 Test (org.testng.annotations.Test)55 Projection (com.yahoo.bullet.query.Projection)29 Window (com.yahoo.bullet.query.Window)28 Raw (com.yahoo.bullet.query.aggregations.Raw)27 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)25 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)24 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)24 BulletConfig (com.yahoo.bullet.common.BulletConfig)22 BulletRecord (com.yahoo.bullet.record.BulletRecord)13 Expression (com.yahoo.bullet.query.expressions.Expression)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)11 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 TableFunction (com.yahoo.bullet.query.tablefunctions.TableFunction)4 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3