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);
}
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());
}
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);
}
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);
}
Aggregations