use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class OrderByTest method testOrderBy.
@Test
public void testOrderBy() {
OrderBy orderBy = new OrderBy(Arrays.asList(new OrderBy.SortItem(new FieldExpression("1"), OrderBy.Direction.ASC), new OrderBy.SortItem(new FieldExpression("2"), OrderBy.Direction.DESC)));
Assert.assertEquals(orderBy.getFields().size(), 2);
Assert.assertEquals(orderBy.getType(), PostAggregationType.ORDER_BY);
Assert.assertTrue(orderBy.getPostStrategy() instanceof OrderByStrategy);
Assert.assertEquals(orderBy.toString(), "{type: ORDER_BY, fields: [{expression: {field: 1, type: null}, direction: ASC}, {expression: {field: 2, type: null}, direction: DESC}]}");
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class ProjectionTest method testProjectOldRecord.
@Test
public void testProjectOldRecord() {
BulletRecord record = RecordBox.get().add("a", 2).add("b", 4).add("c", 6).getRecord();
List<Field> fields = Arrays.asList(new Field("a", new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.MUL)), new Field("b", new BinaryExpression(new FieldExpression("b"), new FieldExpression("c"), Operation.MUL)), new Field("d", new BinaryExpression(new FieldExpression("b"), new FieldExpression("c"), Operation.ADD)), new Field("e", new BinaryExpression(new FieldExpression("e"), new FieldExpression("f"), Operation.SUB)), new Field("f", new FieldExpression("f")), new Field("h", new UnaryExpression(new FieldExpression("a"), Operation.SIZE_OF)));
Projection projection = new Projection(fields);
BulletRecord oldRecord = projection.project(record);
Assert.assertEquals(oldRecord.fieldCount(), 4);
Assert.assertEquals(oldRecord.typedGet("a").getValue(), 8);
Assert.assertEquals(oldRecord.typedGet("b").getValue(), 24);
Assert.assertEquals(oldRecord.typedGet("c").getValue(), 6);
Assert.assertEquals(oldRecord.typedGet("d").getValue(), 10);
Assert.assertEquals(oldRecord, record);
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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;
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class FilterTest method testFilterMatchException.
@Test
public void testFilterMatchException() {
Filter filter = new Filter(new FieldExpression("abc"));
Assert.assertFalse(filter.match(null));
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class QuerierTest method testLogicFilterAnd.
@Test
public void testLogicFilterAnd() {
// legacy test
Expression filter = new BinaryExpression(new BinaryExpression(new FieldExpression("field"), new ValueExpression("abc"), Operation.EQUALS), new BinaryExpression(new FieldExpression("id"), new ValueExpression("1"), Operation.EQUALS), Operation.AND);
Query query = new Query(new Projection(), filter, new Raw(null), null, new Window(), null);
Querier querier = make(Querier.Mode.PARTITION, query);
querier.consume(RecordBox.get().add("field", "abc").add("id", "2").getRecord());
Assert.assertFalse(querier.hasNewData());
querier.consume(RecordBox.get().add("field", "abc").add("id", "1").getRecord());
Assert.assertTrue(querier.hasNewData());
}
Aggregations