Search in sources :

Example 31 with FieldExpression

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}]}");
}
Also used : FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) OrderByStrategy(com.yahoo.bullet.querying.postaggregations.OrderByStrategy) Test(org.testng.annotations.Test)

Example 32 with FieldExpression

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);
}
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 33 with FieldExpression

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;
}
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 34 with FieldExpression

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

Example 35 with FieldExpression

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

FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)63 Test (org.testng.annotations.Test)60 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)33 BulletRecord (com.yahoo.bullet.record.BulletRecord)33 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)30 Query (com.yahoo.bullet.query.Query)27 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)15 Explode (com.yahoo.bullet.query.tablefunctions.Explode)15 Clip (com.yahoo.bullet.result.Clip)13 ArrayList (java.util.ArrayList)13 Projection (com.yahoo.bullet.query.Projection)12 Window (com.yahoo.bullet.query.Window)12 Raw (com.yahoo.bullet.query.aggregations.Raw)12 Expression (com.yahoo.bullet.query.expressions.Expression)12 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)11 Field (com.yahoo.bullet.query.Field)9 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)7 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 RecordBox (com.yahoo.bullet.result.RecordBox)6