Search in sources :

Example 11 with Raw

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

the class QuerierTest method testRestarting.

@Test
public void testRestarting() throws Exception {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RESULT_METADATA_ENABLE, true);
    config.validate();
    Query query = new Query(new Projection(), null, new Raw(null), null, WindowUtils.makeTumblingWindow(1), null);
    query.configure(config);
    Querier querier = new Querier(Querier.Mode.ALL, makeRunningQuery("", query), config);
    querier.consume(RecordBox.get().getRecord());
    Assert.assertEquals(querier.getRecords().size(), 1);
    long timeNow = System.currentTimeMillis();
    Meta meta = querier.getMetadata();
    Map<String, String> mapping = BulletConfigTest.allMetadataAsMap();
    Map<String, Object> queryMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.QUERY_METADATA.getName()));
    Map<String, Object> windowMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.WINDOW_METADATA.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 1L);
    long startTime = (Long) queryMeta.get(mapping.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()));
    long windowEmitTime = (Long) windowMeta.get(mapping.get(Meta.Concept.WINDOW_EMIT_TIME.getName()));
    Assert.assertTrue(startTime <= timeNow);
    Assert.assertTrue(windowEmitTime >= timeNow);
    Thread.sleep(1);
    querier.restart();
    Assert.assertEquals(querier.getRecords().size(), 1);
    meta = querier.getMetadata();
    queryMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.QUERY_METADATA.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 1L);
    long newStartTime = (Long) queryMeta.get(mapping.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()));
    // Querier#restart() no longer updates the query's start time
    Assert.assertEquals(newStartTime, startTime);
    querier.reset();
    meta = querier.getMetadata();
    windowMeta = (Map<String, Object>) meta.asMap().get(mapping.get(Meta.Concept.WINDOW_METADATA.getName()));
    long newEmitTime = (Long) windowMeta.get(mapping.get(Meta.Concept.WINDOW_EMIT_TIME.getName()));
    Assert.assertEquals(windowMeta.get(mapping.get(Meta.Concept.WINDOW_NUMBER.getName())), 2L);
    Assert.assertTrue(newEmitTime > windowEmitTime);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 12 with Raw

use of com.yahoo.bullet.query.aggregations.Raw 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 13 with Raw

use of com.yahoo.bullet.query.aggregations.Raw 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 14 with Raw

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

the class QueryManagerTest method getQuery.

@SafeVarargs
private static Query getQuery(Pair<String, Serializable>... equalities) {
    BinaryExpression expression = null;
    if (equalities != null && equalities.length > 0) {
        if (equalities.length == 1) {
            expression = new BinaryExpression(new FieldExpression(equalities[0].getLeft()), new ValueExpression(equalities[0].getRight()), Operation.EQUALS);
            expression.setType(Type.BOOLEAN);
            expression.getLeft().setType(expression.getRight().getType());
        } else {
            expression = Arrays.stream(equalities).reduce(null, (a, b) -> {
                BinaryExpression equals = new BinaryExpression(new FieldExpression(b.getLeft()), new ValueExpression(b.getRight()), Operation.EQUALS);
                equals.setType(Type.BOOLEAN);
                equals.getLeft().setType(equals.getRight().getType());
                if (a == null) {
                    return equals;
                }
                BinaryExpression and = new BinaryExpression(a, equals, Operation.AND);
                and.setType(Type.BOOLEAN);
                return and;
            }, (left, right) -> {
                BinaryExpression and = new BinaryExpression(left, right, Operation.AND);
                and.setType(Type.BOOLEAN);
                return and;
            });
        }
    }
    Query query = new Query(new Projection(), expression, new Raw(null), null, new Window(), null);
    query.configure(new BulletConfig());
    return query;
}
Also used : Query(com.yahoo.bullet.query.Query) Arrays(java.util.Arrays) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) Operation(com.yahoo.bullet.query.expressions.Operation) HashSet(java.util.HashSet) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Raw(com.yahoo.bullet.query.aggregations.Raw) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) LinkedHashSet(java.util.LinkedHashSet) Window(com.yahoo.bullet.query.Window) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) BulletRecord(com.yahoo.bullet.record.BulletRecord) SimpleEqualityPartitioner(com.yahoo.bullet.querying.partitioning.SimpleEqualityPartitioner) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Serializable(java.io.Serializable) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Projection(com.yahoo.bullet.query.Projection) BulletConfig(com.yahoo.bullet.common.BulletConfig) Type(com.yahoo.bullet.typesystem.Type) Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression)

Example 15 with Raw

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

the class QueryUtils method makeFilterQuery.

public static Query makeFilterQuery(Expression filter, Integer size) {
    Query query = new Query(new Projection(), filter, new Raw(size), null, new Window(), null);
    query.configure(new BulletConfig());
    return query;
}
Also used : Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig)

Aggregations

Raw (com.yahoo.bullet.query.aggregations.Raw)40 Test (org.testng.annotations.Test)33 Projection (com.yahoo.bullet.query.Projection)27 Query (com.yahoo.bullet.query.Query)27 Window (com.yahoo.bullet.query.Window)26 BulletConfig (com.yahoo.bullet.common.BulletConfig)21 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)17 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 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 Operation (com.yahoo.bullet.query.expressions.Operation)3 Computation (com.yahoo.bullet.query.postaggregations.Computation)3 Culling (com.yahoo.bullet.query.postaggregations.Culling)3