Search in sources :

Example 26 with Query

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

the class QueryManagerTest method testCategorizingAll.

@Test
public void testCategorizingAll() {
    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);
    QueryCategorizer categorizer = manager.categorize();
    Assert.assertEquals(categorizer.getDone().size(), 0);
    Assert.assertEquals(categorizer.getClosed().size(), 0);
    Assert.assertEquals(categorizer.getRateLimited().size(), 0);
    verify(querierA, times(1)).isDone();
    verify(querierA, times(1)).isClosed();
    verify(querierA, times(1)).isExceedingRateLimit();
    verify(querierB, times(1)).isDone();
    verify(querierB, times(1)).isClosed();
    verify(querierB, times(1)).isExceedingRateLimit();
}
Also used : Query(com.yahoo.bullet.query.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 27 with Query

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

the class RunningQueryTest method testCreatingWithQuery.

@Test
public void testCreatingWithQuery() {
    BulletConfig config = new BulletConfig();
    Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), null);
    query.configure(config);
    RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, "bar"));
    Assert.assertEquals(runningQuery.getId(), "foo");
    Assert.assertNotNull(runningQuery.getQuery());
    Assert.assertEquals(runningQuery.getQueryString(), "bar");
    Assert.assertEquals(runningQuery.toString(), query.toString());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Metadata(com.yahoo.bullet.pubsub.Metadata) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 28 with Query

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

the class RunningQueryTest method testTimingOut.

@Test
public void testTimingOut() throws Exception {
    BulletConfig config = new BulletConfig();
    Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), 1L);
    query.configure(config);
    RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, null));
    // Sleep to make sure it's 1 ms
    Thread.sleep(1);
    Assert.assertTrue(runningQuery.isTimedOut());
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) Metadata(com.yahoo.bullet.pubsub.Metadata) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 29 with Query

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

the class QueryManagerTest method testPartitioning.

@Test
public void testPartitioning() {
    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").getRecord();
    BulletRecord recordB = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
    BulletRecord recordC = RecordBox.get().getRecord();
    Map<String, Querier> partitionA = manager.partition(recordA);
    Map<String, Querier> partitionB = manager.partition(recordB);
    Map<String, Querier> partitionC = manager.partition(recordC);
    Assert.assertEquals(partitionA.size(), 2);
    Assert.assertSame(partitionA.get("idA"), querierA);
    Assert.assertSame(partitionA.get("idC"), querierC);
    Assert.assertEquals(partitionB.size(), 3);
    Assert.assertSame(partitionB.get("idA"), querierA);
    Assert.assertSame(partitionB.get("idB"), querierB);
    Assert.assertSame(partitionB.get("idC"), querierC);
    Assert.assertEquals(partitionC.size(), 1);
    Assert.assertSame(partitionC.get("idC"), querierC);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) Test(org.testng.annotations.Test)

Example 30 with Query

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

the class QueryManagerTest method testAddingAndRemovingQueries.

@Test
public void testAddingAndRemovingQueries() {
    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"));
    Querier querierA = getQuerier(queryA);
    Querier querierB = getQuerier(queryB);
    Querier querierC = getQuerier(queryA);
    Querier querierD = getQuerier(queryA);
    Querier querierE = getQuerier(queryB);
    manager.addQuery("idA", querierA);
    manager.addQuery("idB", querierB);
    manager.addQuery("idC", querierC);
    manager.addQuery("idD", querierD);
    manager.addQuery("idE", querierE);
    Assert.assertSame(manager.getQuery("idA"), querierA);
    Assert.assertSame(manager.getQuery("idC"), querierC);
    Assert.assertSame(manager.getQuery("idD"), querierD);
    Assert.assertSame(manager.getQuery("idB"), querierB);
    Assert.assertSame(manager.getQuery("idE"), querierE);
    Assert.assertTrue(manager.hasQuery("idA"));
    Assert.assertFalse(manager.hasQuery("foo"));
    Assert.assertEquals(manager.size(), 5);
    Assert.assertNull(manager.removeAndGetQuery("fake"));
    Assert.assertSame(manager.removeAndGetQuery("idC"), querierC);
    Assert.assertEquals(manager.size(), 4);
    List<Querier> removed = manager.removeAndGetQueries(new LinkedHashSet<>(asList("idE", "idB", "idC")));
    Assert.assertEquals(removed.size(), 2);
    Assert.assertSame(removed.get(0), querierE);
    Assert.assertSame(removed.get(1), querierB);
    Assert.assertEquals(manager.size(), 2);
    Assert.assertNotNull(manager.getQuery("idA"));
    Assert.assertNotNull(manager.getQuery("idD"));
    Assert.assertNull(manager.getQuery("idB"));
    Assert.assertNull(manager.getQuery("idC"));
    Assert.assertNull(manager.getQuery("idE"));
    Assert.assertEquals(manager.size(), 2);
    manager.removeQueries(new HashSet<>(asList("idD", "idA")));
    Assert.assertNull(manager.getQuery("idA"));
    Assert.assertNull(manager.getQuery("idD"));
    Assert.assertFalse(manager.hasQuery("idA"));
    Assert.assertEquals(manager.size(), 0);
}
Also used : Query(com.yahoo.bullet.query.Query) 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