Search in sources :

Example 6 with UnaryExpression

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

Example 7 with UnaryExpression

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

the class ExplodeFunctorTest method testApplyWithBadEvaluator.

@Test
public void testApplyWithBadEvaluator() {
    Explode explode = new Explode(new UnaryExpression(new ValueExpression(5), Operation.SIZE_OF), "foo", "bar", false);
    ExplodeFunctor functor = new ExplodeFunctor(explode);
    List<BulletRecord> records = functor.apply(record, provider);
    Assert.assertEquals(records.size(), 0);
}
Also used : Explode(com.yahoo.bullet.query.tablefunctions.Explode) BulletRecord(com.yahoo.bullet.record.BulletRecord) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) Test(org.testng.annotations.Test)

Example 8 with UnaryExpression

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

the class OrderByStrategyTest method testOrderByComputationWithMissingField.

@Test
public void testOrderByComputationWithMissingField() {
    OrderByStrategy orderByStrategy = makeOrderBy(Collections.singletonList(new OrderBy.SortItem(new UnaryExpression(new FieldExpression("a"), Operation.SIZE_OF), OrderBy.Direction.ASC)));
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", "hello").getRecord());
    records.add(RecordBox.get().add("a", "").getRecord());
    records.add(RecordBox.get().add("a", "foobar").getRecord());
    records.add(RecordBox.get().getRecord());
    records.add(RecordBox.get().add("a", "world").getRecord());
    Clip clip = new Clip();
    clip.add(records);
    Clip result = orderByStrategy.execute(clip);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), null);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), "");
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), "hello");
    Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), "world");
    Assert.assertEquals(result.getRecords().get(4).typedGet("a").getValue(), "foobar");
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 9 with UnaryExpression

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

the class OrderByStrategyTest method testOrderByComputationWithBadComputation.

@Test
public void testOrderByComputationWithBadComputation() {
    OrderByStrategy orderByStrategy = makeOrderBy(Collections.singletonList(new OrderBy.SortItem(new UnaryExpression(new FieldExpression("a"), Operation.SIZE_OF), OrderBy.Direction.ASC)));
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 1).getRecord());
    records.add(RecordBox.get().add("a", 3).getRecord());
    records.add(RecordBox.get().add("a", 2).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    Clip result = orderByStrategy.execute(clip);
    // Order should not change
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 1);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 3);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 10 with UnaryExpression

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

the class UnaryEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    UnaryExpression expression = new UnaryExpression(new ValueExpression(1), Operation.IS_NOT_NULL);
    expression.setType(Type.BOOLEAN);
    UnaryEvaluator evaluator = new UnaryEvaluator(expression);
    Assert.assertTrue(evaluator.operand instanceof ValueEvaluator);
    Assert.assertEquals(evaluator.op, UNARY_OPERATORS.get(Operation.IS_NOT_NULL));
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), new TypedObject(Type.BOOLEAN, true));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) Test(org.testng.annotations.Test)

Aggregations

UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 Test (org.testng.annotations.Test)10 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)8 BulletRecord (com.yahoo.bullet.record.BulletRecord)8 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)6 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)6 Field (com.yahoo.bullet.query.Field)4 Query (com.yahoo.bullet.query.Query)4 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)3 Projection (com.yahoo.bullet.query.Projection)3 Window (com.yahoo.bullet.query.Window)3 Raw (com.yahoo.bullet.query.aggregations.Raw)3 Expression (com.yahoo.bullet.query.expressions.Expression)3 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)3 Explode (com.yahoo.bullet.query.tablefunctions.Explode)2 Clip (com.yahoo.bullet.result.Clip)2 ArrayList (java.util.ArrayList)2 Computation (com.yahoo.bullet.query.postaggregations.Computation)1 Culling (com.yahoo.bullet.query.postaggregations.Culling)1 OrderBy (com.yahoo.bullet.query.postaggregations.OrderBy)1