Search in sources :

Example 11 with Expression

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

the class QuerierTest method testOrderBy.

@Test
public void testOrderBy() {
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    OrderBy orderBy = new OrderBy(Collections.singletonList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC)));
    Query query = new Query(new Projection(), filter, new Raw(500), Collections.singletonList(orderBy), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", 10 - i).add("b", i + 10).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("a").getValue(), 10);
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 10);
    Assert.assertEquals(result.get(1).typedGet("a").getValue(), 9);
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 11);
    Assert.assertEquals(result.get(2).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 12);
    Assert.assertEquals(result.get(3).typedGet("a").getValue(), 7);
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 13);
}
Also used : OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Window(com.yahoo.bullet.query.Window) BulletRecord(com.yahoo.bullet.record.BulletRecord) Query(com.yahoo.bullet.query.Query) 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) 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) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 12 with Expression

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

the class QuerierTest method testFiltering.

@Test
public void testFiltering() {
    Expression filter = new BinaryExpression(new FieldExpression("field"), new ListExpression(Arrays.asList(new ValueExpression("foo"), new ValueExpression("bar"))), Operation.EQUALS_ANY);
    Window window = WindowUtils.makeSlidingWindow(1);
    Query query = new Query(new Projection(), filter, new Raw(null), null, window, null);
    Querier querier = make(Querier.Mode.PARTITION, query);
    querier.consume(RecordBox.get().add("field", "foo").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "bar").getRecord());
    Assert.assertTrue(querier.isClosed());
    querier.reset();
    querier.consume(RecordBox.get().add("field", "baz").getRecord());
    Assert.assertFalse(querier.isClosed());
}
Also used : Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) 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) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 13 with Expression

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

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

the class SimpleEqualityPartitioner method getKeys.

/**
 * {@inheritDoc}
 *
 * This partitioner ensures that queries are not stored in duplicate by returning only key for a query (the list
 * that is returned is of size 1).
 *
 * @param query {@inheritDoc}
 * @return {@inheritDoc}
 */
@Override
public Set<String> getKeys(Query query) {
    Objects.requireNonNull(query);
    Expression filter = query.getFilter();
    // If no filter, default partition
    if (filter == null) {
        return defaultKeys;
    }
    // Map each field to the values that it is checked for equality against
    Map<String, Set<Serializable>> equalityClauses = new HashMap<>();
    mapFieldsToValues(filter, equalityClauses);
    // If not exactly one equality per field, default partition
    if (equalityClauses.values().stream().anyMatch(set -> set.size() != 1)) {
        return defaultKeys;
    }
    // Generate key in fields order and pad with NO_FIELD if no mapping present
    String key = fields.stream().map(equalityClauses::get).map(this::getFilterValue).collect(Collectors.joining(delimiter));
    // For the SimpleEqualityPartitioner, the query is mapped to exactly one key only.
    return Collections.singleton(key);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) HashMap(java.util.HashMap)

Aggregations

Expression (com.yahoo.bullet.query.expressions.Expression)14 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)13 Query (com.yahoo.bullet.query.Query)12 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)12 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)12 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)10 Projection (com.yahoo.bullet.query.Projection)10 Window (com.yahoo.bullet.query.Window)10 Raw (com.yahoo.bullet.query.aggregations.Raw)10 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 Test (org.testng.annotations.Test)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Field (com.yahoo.bullet.query.Field)5 BulletConfig (com.yahoo.bullet.common.BulletConfig)4 TableFunction (com.yahoo.bullet.query.tablefunctions.TableFunction)4 HashMap (java.util.HashMap)4 Operation (com.yahoo.bullet.query.expressions.Operation)3 Computation (com.yahoo.bullet.query.postaggregations.Computation)3 Culling (com.yahoo.bullet.query.postaggregations.Culling)3