Search in sources :

Example 51 with Query

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

the class RunningQueryTest method testStartTime.

@Test
public void testStartTime() {
    long start = System.currentTimeMillis();
    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, null));
    long end = System.currentTimeMillis();
    Assert.assertTrue(runningQuery.getStartTime() >= start);
    Assert.assertTrue(runningQuery.getStartTime() <= end);
    Assert.assertFalse(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 52 with Query

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

the class ByteArrayPubSubMessageSerDeTest method testLazyMessage.

@Test
public void testLazyMessage() {
    ByteArrayPubSubMessageSerDe serDe = new ByteArrayPubSubMessageSerDe(null);
    Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), 1L);
    PubSubMessage converted = serDe.toMessage("id", query, "foo");
    PubSubMessage reverted = serDe.fromMessage(converted);
    Assert.assertSame(reverted, converted);
    // Starts off as byte[]
    Assert.assertEquals(reverted.getContent(), SerializerDeserializer.toBytes(query));
    // Payload is now made a Query
    Query revertedQuery = reverted.getContentAsQuery();
    Assert.assertEquals(revertedQuery.getProjection().getType(), Projection.Type.PASS_THROUGH);
    Assert.assertEquals(revertedQuery.getAggregation().getType(), AggregationType.RAW);
    Assert.assertEquals((long) revertedQuery.getAggregation().getSize(), 1L);
    Assert.assertEquals((long) revertedQuery.getDuration(), 1L);
    Assert.assertSame(reverted.getContent(), revertedQuery);
    // Payload is now made a byte[]
    byte[] revertedByteArray = reverted.getContentAsByteArray();
    Assert.assertEquals(revertedByteArray, SerializerDeserializer.toBytes(query));
    Assert.assertSame(reverted.getContent(), revertedByteArray);
}
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)

Example 53 with Query

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

the class ByteArrayPubSubMessageSerDeTest method testConvertingQuery.

@Test
public void testConvertingQuery() {
    ByteArrayPubSubMessageSerDe serDe = new ByteArrayPubSubMessageSerDe(null);
    Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), 1L);
    PubSubMessage actual = serDe.toMessage("id", query, "foo");
    Assert.assertEquals(actual.getId(), "id");
    Assert.assertEquals(actual.getContent(), SerializerDeserializer.toBytes(query));
    Assert.assertEquals(actual.getMetadata().getContent(), "foo");
}
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)

Example 54 with Query

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

the class Querier method start.

// ********************************* Monoidal Interface Overrides *********************************
/**
 * Starts the query.
 */
private void start() {
    // Is an empty map if metadata was disabled
    metaKeys = (Map<String, String>) config.getAs(BulletConfig.RESULT_METADATA_METRICS, Map.class);
    boolean isRateLimitEnabled = config.getAs(BulletConfig.RATE_LIMIT_ENABLE, Boolean.class);
    if (isRateLimitEnabled) {
        int maxEmit = config.getAs(BulletConfig.RATE_LIMIT_MAX_EMIT_COUNT, Integer.class);
        int timeInterval = config.getAs(BulletConfig.RATE_LIMIT_TIME_INTERVAL, Integer.class);
        rateLimit = new RateLimiter(maxEmit, timeInterval);
    }
    Query query = runningQuery.getQuery();
    Expression filter = query.getFilter();
    if (filter != null) {
        this.filter = new Filter(filter);
    }
    TableFunction tableFunction = query.getTableFunction();
    if (tableFunction != null) {
        tableFunctor = tableFunction.getTableFunctor();
    }
    com.yahoo.bullet.query.Projection projection = query.getProjection();
    if (projection.getType() != PASS_THROUGH) {
        this.projection = new Projection(projection.getFields());
    }
    // Aggregation and Strategy are guaranteed to not be null.
    Strategy strategy = query.getAggregation().getStrategy(config);
    List<PostAggregation> postAggregations = query.getPostAggregations();
    if (postAggregations != null && !postAggregations.isEmpty()) {
        postStrategies = postAggregations.stream().map(PostAggregation::getPostStrategy).collect(Collectors.toList());
    }
    // Scheme is guaranteed to not be null. It is constructed in its "start" state.
    window = query.getWindow().getScheme(strategy, config);
}
Also used : Query(com.yahoo.bullet.query.Query) PostAggregation(com.yahoo.bullet.query.postaggregations.PostAggregation) Expression(com.yahoo.bullet.query.expressions.Expression) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) Strategy(com.yahoo.bullet.querying.aggregations.Strategy) PostStrategy(com.yahoo.bullet.querying.postaggregations.PostStrategy)

Example 55 with Query

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

the class QueryManager method removeAndGetQuery.

/**
 * Removes and returns a {@link Querier} from the manager. The manager does not have any information pertaining to
 * the query any longer.
 *
 * @param id The query ID to remove.
 * @return The removed {@link Querier} instance.
 */
public Querier removeAndGetQuery(String id) {
    Querier querier = queries.remove(id);
    if (querier != null) {
        Query query = querier.getQuery();
        Set<String> keys = partitioner.getKeys(query);
        for (String key : keys) {
            Set<String> partition = partitioning.get(key);
            partition.remove(id);
            if (partition.isEmpty()) {
                log.debug("Partition: {} is empty. Removing...", key);
                partitioning.remove(key);
            }
            log.debug("Removed query: {} from partition: {}", id, key);
        }
    }
    return querier;
}
Also used : Query(com.yahoo.bullet.query.Query)

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