Search in sources :

Example 21 with BinaryExpression

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());
}
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) 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 22 with BinaryExpression

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());
}
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 23 with BinaryExpression

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);
}
Also used : Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) TypedAvroBulletRecordProvider(com.yahoo.bullet.record.avro.TypedAvroBulletRecordProvider) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 24 with BinaryExpression

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);
        }
    }
}
Also used : BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression)

Example 25 with BinaryExpression

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"));
}
Also used : Query(com.yahoo.bullet.query.Query) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)31 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)30 Test (org.testng.annotations.Test)30 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)28 Query (com.yahoo.bullet.query.Query)22 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 BulletRecord (com.yahoo.bullet.record.BulletRecord)11 Projection (com.yahoo.bullet.query.Projection)9 Window (com.yahoo.bullet.query.Window)9 Raw (com.yahoo.bullet.query.aggregations.Raw)9 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)9 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)8 Expression (com.yahoo.bullet.query.expressions.Expression)8 Field (com.yahoo.bullet.query.Field)7 Clip (com.yahoo.bullet.result.Clip)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)4 Computation (com.yahoo.bullet.query.postaggregations.Computation)4 RecordBox (com.yahoo.bullet.result.RecordBox)4 Operation (com.yahoo.bullet.query.expressions.Operation)3 Culling (com.yahoo.bullet.query.postaggregations.Culling)3