Search in sources :

Example 11 with BinaryExpression

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

the class SimpleEqualityPartitionerTest method testDefaultPartitioningForQueryWithMultipleValues.

@Test
public void testDefaultPartitioningForQueryWithMultipleValues() {
    SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
    Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression("foo"), Operation.EQUALS), new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression("baz"), Operation.EQUALS));
    Assert.assertEquals(partitioner.getKeys(query), singleton("*-*"));
}
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)

Example 12 with BinaryExpression

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

the class FilterTest method testFilterMatch.

@Test
public void testFilterMatch() {
    Filter filter = new Filter(new BinaryExpression(new FieldExpression("abc"), new ValueExpression(0), Operation.GREATER_THAN));
    BulletRecord recordA = RecordBox.get().add("abc", 1).getRecord();
    BulletRecord recordB = RecordBox.get().add("abc", 0).getRecord();
    BulletRecord recordC = RecordBox.get().getRecord();
    Assert.assertTrue(filter.match(recordA));
    Assert.assertFalse(filter.match(recordB));
    Assert.assertFalse(filter.match(recordC));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) 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)

Example 13 with BinaryExpression

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

Example 14 with BinaryExpression

use of com.yahoo.bullet.query.expressions.BinaryExpression 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;
}
Also used : Query(com.yahoo.bullet.query.Query) Arrays(java.util.Arrays) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) Operation(com.yahoo.bullet.query.expressions.Operation) HashSet(java.util.HashSet) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Raw(com.yahoo.bullet.query.aggregations.Raw) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) LinkedHashSet(java.util.LinkedHashSet) Window(com.yahoo.bullet.query.Window) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) BulletRecord(com.yahoo.bullet.record.BulletRecord) SimpleEqualityPartitioner(com.yahoo.bullet.querying.partitioning.SimpleEqualityPartitioner) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Serializable(java.io.Serializable) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Projection(com.yahoo.bullet.query.Projection) BulletConfig(com.yahoo.bullet.common.BulletConfig) Type(com.yahoo.bullet.typesystem.Type) Window(com.yahoo.bullet.query.Window) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) Query(com.yahoo.bullet.query.Query) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) BulletConfig(com.yahoo.bullet.common.BulletConfig) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression)

Example 15 with BinaryExpression

use of com.yahoo.bullet.query.expressions.BinaryExpression 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());
}
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)

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