Search in sources :

Example 16 with ValueExpression

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

the class HavingTest method testHaving.

@Test
public void testHaving() {
    Having having = new Having(new ValueExpression(true));
    Assert.assertEquals(having.getExpression(), new ValueExpression(true));
    Assert.assertEquals(having.getType(), PostAggregationType.HAVING);
    Assert.assertEquals(having.toString(), "{type: HAVING, expression: {value: true, type: BOOLEAN}}");
    Assert.assertTrue(having.getPostStrategy() instanceof HavingStrategy);
}
Also used : ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) HavingStrategy(com.yahoo.bullet.querying.postaggregations.HavingStrategy) Test(org.testng.annotations.Test)

Example 17 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression 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 18 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression 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 19 with ValueExpression

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

the class ProjectionTest method testProjectionNoCopy.

@Test
public void testProjectionNoCopy() {
    Projection projection = new Projection(Arrays.asList(new Field("foo", new ValueExpression(5))), false);
    Assert.assertEquals(projection.getFields(), Collections.singletonList(new Field("foo", new ValueExpression(5))));
    Assert.assertEquals(projection.getType(), Projection.Type.NO_COPY);
    Assert.assertEquals(projection.toString(), "{fields: [{name: foo, value: {value: 5, type: INTEGER}}], type: NO_COPY}");
}
Also used : ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Example 20 with ValueExpression

use of com.yahoo.bullet.query.expressions.ValueExpression 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

ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)42 Test (org.testng.annotations.Test)40 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)29 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)28 Query (com.yahoo.bullet.query.Query)23 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)10 Projection (com.yahoo.bullet.query.Projection)9 Window (com.yahoo.bullet.query.Window)9 Raw (com.yahoo.bullet.query.aggregations.Raw)9 Expression (com.yahoo.bullet.query.expressions.Expression)9 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)8 TypedObject (com.yahoo.bullet.typesystem.TypedObject)7 Field (com.yahoo.bullet.query.Field)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)5 Clip (com.yahoo.bullet.result.Clip)5 Operation (com.yahoo.bullet.query.expressions.Operation)4 Computation (com.yahoo.bullet.query.postaggregations.Computation)4 RecordBox (com.yahoo.bullet.result.RecordBox)4