use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class QuerierTest method testLogicFilterOr.
@Test
public void testLogicFilterOr() {
// 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.OR);
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.assertTrue(querier.hasNewData());
querier.consume(RecordBox.get().add("field", "abc").add("id", "1").getRecord());
Assert.assertTrue(querier.hasNewData());
}
use of com.yahoo.bullet.query.expressions.BinaryExpression 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.BinaryExpression in project bullet-core by yahoo.
the class ProjectionTest method testProjectNewRecord.
@Test
public void testProjectNewRecord() {
BulletRecord record = RecordBox.get().add("a", 2).add("b", 4).add("c", 6).getRecord();
List<Field> fields = Arrays.asList(new Field("d", new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.ADD)), new Field("e", new BinaryExpression(new FieldExpression("b"), new FieldExpression("c"), Operation.MUL)), new Field("f", new BinaryExpression(new FieldExpression("d"), new FieldExpression("e"), Operation.ADD)), new Field("g", new FieldExpression("g")), new Field("h", new UnaryExpression(new FieldExpression("a"), Operation.SIZE_OF)));
Projection projection = new Projection(fields);
BulletRecord newRecord = projection.project(record, new TypedAvroBulletRecordProvider());
Assert.assertEquals(newRecord.fieldCount(), 2);
Assert.assertEquals(newRecord.typedGet("d").getValue(), 6);
Assert.assertEquals(newRecord.typedGet("e").getValue(), 24);
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitioner method mapFieldsToValues.
private void mapFieldsToValues(Expression expression, Map<String, Set<Serializable>> mapping) {
if (!(expression instanceof BinaryExpression)) {
return;
}
BinaryExpression binary = (BinaryExpression) expression;
if (binary.getOp() == Operation.AND) {
mapFieldsToValues(binary.getLeft(), mapping);
mapFieldsToValues(binary.getRight(), mapping);
} else if (binary.getOp() == Operation.EQUALS) {
if (binary.getLeft() instanceof FieldExpression && binary.getRight() instanceof ValueExpression) {
addFieldToMapping((FieldExpression) binary.getLeft(), (ValueExpression) binary.getRight(), mapping);
} else if (binary.getRight() instanceof FieldExpression && binary.getLeft() instanceof ValueExpression) {
addFieldToMapping((FieldExpression) binary.getRight(), (ValueExpression) binary.getLeft(), mapping);
}
}
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithNullEqualityFilters.
@Test
public void testDefaultPartitioningQueryWithNullEqualityFilters() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression(null), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression(null), Operation.EQUALS));
Assert.assertEquals(partitioner.getKeys(query), singleton("null-null"));
}
Aggregations