Search in sources :

Example 41 with FieldExpression

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

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

the class QuerierTest method testOrderBy.

@Test
public void testOrderBy() {
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    OrderBy orderBy = new OrderBy(Collections.singletonList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC)));
    Query query = new Query(new Projection(), filter, new Raw(500), Collections.singletonList(orderBy), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", 10 - i).add("b", i + 10).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("a").getValue(), 10);
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 10);
    Assert.assertEquals(result.get(1).typedGet("a").getValue(), 9);
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 11);
    Assert.assertEquals(result.get(2).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 12);
    Assert.assertEquals(result.get(3).typedGet("a").getValue(), 7);
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 13);
}
Also used : OrderBy(com.yahoo.bullet.query.postaggregations.OrderBy) Window(com.yahoo.bullet.query.Window) BulletRecord(com.yahoo.bullet.record.BulletRecord) 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) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 43 with FieldExpression

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

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

the class LateralViewTest method testLateralViewTableFunction.

@Test
public void testLateralViewTableFunction() {
    Explode explode = new Explode(new FieldExpression("abc"), "foo", "bar", true);
    LateralView tableFunction = new LateralView(explode);
    Assert.assertEquals(tableFunction.getType(), TableFunctionType.LATERAL_VIEW);
    Assert.assertEquals(tableFunction.getTableFunctions().get(0), explode);
    Assert.assertTrue(tableFunction.getTableFunctor() instanceof LateralViewFunctor);
}
Also used : LateralViewFunctor(com.yahoo.bullet.querying.tablefunctors.LateralViewFunctor) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 45 with FieldExpression

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

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