Search in sources :

Example 36 with ValueExpression

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

the class SimpleEqualityPartitionerTest method testPartitioningForQueryWithNestedFields.

@Test
public void testPartitioningForQueryWithNestedFields() {
    SimpleEqualityPartitioner partitioner = createPartitioner("A", "B", "C", "D.e");
    Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression("quux"), Operation.EQUALS), new BinaryExpression(new FieldExpression("C"), new ValueExpression("qux"), Operation.EQUALS), new BinaryExpression(new FieldExpression("D", "e"), new ValueExpression("norf"), Operation.EQUALS));
    Assert.assertEquals(partitioner.getKeys(query), singleton("bar.-quux.-qux.-norf."));
}
Also used : Query(com.yahoo.bullet.query.Query) 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 37 with ValueExpression

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

the class HavingStrategyTest method testHaving.

@Test
public void testHaving() {
    List<BulletRecord> records = new ArrayList<>();
    records.add(RecordBox.get().add("a", 6).getRecord());
    records.add(RecordBox.get().add("a", 1).getRecord());
    records.add(RecordBox.get().add("a", 8).getRecord());
    records.add(RecordBox.get().add("a", 2).getRecord());
    records.add(RecordBox.get().add("b", 10).getRecord());
    records.add(RecordBox.get().add("a", 7).getRecord());
    Clip clip = new Clip();
    clip.add(records);
    // a > 5
    BinaryExpression expression = new BinaryExpression(new FieldExpression("a"), new ValueExpression(5), Operation.GREATER_THAN);
    HavingStrategy strategy = (HavingStrategy) new Having(expression).getPostStrategy();
    Clip result = strategy.execute(clip);
    Assert.assertEquals(result.getRecords().size(), 3);
    Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 6);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 8);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 7);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) ArrayList(java.util.ArrayList) Having(com.yahoo.bullet.query.postaggregations.Having) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 38 with ValueExpression

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

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

the class BinaryEvaluatorTest method testConstructor.

@Test
public void testConstructor() {
    BinaryExpression expression = new BinaryExpression(new ValueExpression(1), new ValueExpression(2), Operation.ADD);
    expression.setType(Type.INTEGER);
    BinaryEvaluator evaluator = new BinaryEvaluator(expression);
    Assert.assertTrue(evaluator.left instanceof ValueEvaluator);
    Assert.assertTrue(evaluator.right instanceof ValueEvaluator);
    Assert.assertEquals(evaluator.op, BINARY_OPERATORS.get(Operation.ADD));
    Assert.assertEquals(evaluator.evaluate(RecordBox.get().getRecord()), new TypedObject(Type.INTEGER, 3));
}
Also used : BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) TypedObject(com.yahoo.bullet.typesystem.TypedObject) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Test(org.testng.annotations.Test)

Example 40 with ValueExpression

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

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