Search in sources :

Example 6 with Field

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

the class QuerierTest method testComputationAndCulling.

@Test
public void testComputationAndCulling() {
    Projection projection = new Projection(Arrays.asList(new Field("a", new FieldExpression("a")), new Field("b", new FieldExpression("b"))), false);
    Expression filter = new UnaryExpression(new FieldExpression("a"), Operation.IS_NOT_NULL);
    Expression expression = new BinaryExpression(new FieldExpression("a"), new ValueExpression(2L), Operation.ADD);
    Computation computation = new Computation(Collections.singletonList(new Field("newName", expression)));
    Culling culling = new Culling(singleton("a"));
    Query query = new Query(projection, filter, new Raw(500), Arrays.asList(computation, culling), new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    IntStream.range(0, 4).forEach(i -> querier.consume(RecordBox.get().add("a", i).add("b", i).getRecord()));
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).typedGet("newName").getValue(), 2L);
    Assert.assertFalse(result.get(0).hasField("a"));
    Assert.assertEquals(result.get(0).typedGet("b").getValue(), 0);
    Assert.assertEquals(result.get(1).typedGet("newName").getValue(), 3L);
    Assert.assertFalse(result.get(1).hasField("a"));
    Assert.assertEquals(result.get(1).typedGet("b").getValue(), 1);
    Assert.assertEquals(result.get(2).typedGet("newName").getValue(), 4L);
    Assert.assertFalse(result.get(2).hasField("a"));
    Assert.assertEquals(result.get(2).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.get(3).typedGet("newName").getValue(), 5L);
    Assert.assertFalse(result.get(3).hasField("a"));
    Assert.assertEquals(result.get(3).typedGet("b").getValue(), 3);
}
Also used : Window(com.yahoo.bullet.query.Window) Query(com.yahoo.bullet.query.Query) 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) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) 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) Computation(com.yahoo.bullet.query.postaggregations.Computation) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Culling(com.yahoo.bullet.query.postaggregations.Culling) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 7 with Field

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

the class ComputationTest method testComputation.

@Test
public void testComputation() {
    Computation computation = new Computation(Collections.singletonList(new Field("abc", new ValueExpression(1))));
    Assert.assertEquals(computation.getFields(), Collections.singletonList(new Field("abc", new ValueExpression(1))));
    Assert.assertEquals(computation.getType(), PostAggregationType.COMPUTATION);
    Assert.assertEquals(computation.toString(), "{type: COMPUTATION, fields: [{name: abc, value: {value: 1, type: INTEGER}}]}");
    Assert.assertTrue(computation.getPostStrategy() instanceof ComputationStrategy);
}
Also used : Field(com.yahoo.bullet.query.Field) ComputationStrategy(com.yahoo.bullet.querying.postaggregations.ComputationStrategy) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Example 8 with Field

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

Field (com.yahoo.bullet.query.Field)8 Test (org.testng.annotations.Test)8 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)7 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)6 BulletRecord (com.yahoo.bullet.record.BulletRecord)6 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)5 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)5 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)4 Projection (com.yahoo.bullet.query.Projection)4 Query (com.yahoo.bullet.query.Query)4 Window (com.yahoo.bullet.query.Window)4 Raw (com.yahoo.bullet.query.aggregations.Raw)4 Expression (com.yahoo.bullet.query.expressions.Expression)3 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)3 BulletConfig (com.yahoo.bullet.common.BulletConfig)2 Computation (com.yahoo.bullet.query.postaggregations.Computation)2 RecordBox (com.yahoo.bullet.result.RecordBox)2 Culling (com.yahoo.bullet.query.postaggregations.Culling)1 Explode (com.yahoo.bullet.query.tablefunctions.Explode)1 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)1