Search in sources :

Example 26 with BinaryExpression

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

the class SimpleEqualityPartitionerTest method testPartitioningForQueryWithAllFieldsOperandsFlipped.

@Test
public void testPartitioningForQueryWithAllFieldsOperandsFlipped() {
    SimpleEqualityPartitioner partitioner = createPartitioner("A", "B", "C");
    Query query = createQuery(new BinaryExpression(new ValueExpression("bar"), new FieldExpression("A"), Operation.EQUALS), new BinaryExpression(new ValueExpression("baz"), new FieldExpression("B"), Operation.EQUALS), new BinaryExpression(new ValueExpression("qux"), new FieldExpression("C"), Operation.EQUALS));
    Assert.assertEquals(partitioner.getKeys(query), singleton("bar.-baz.-qux."));
}
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 27 with BinaryExpression

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

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

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

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

the class SimpleEqualityPartitionerTest method testPartitioningForQueryWithAllFields.

@Test
public void testPartitioningForQueryWithAllFields() {
    SimpleEqualityPartitioner partitioner = createPartitioner("A", "B", "C");
    Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression("baz"), Operation.EQUALS), new BinaryExpression(new FieldExpression("C"), new ValueExpression("qux"), Operation.EQUALS));
    Assert.assertEquals(partitioner.getKeys(query), singleton("bar.-baz.-qux."));
}
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)

Aggregations

BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)31 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)30 Test (org.testng.annotations.Test)30 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)28 Query (com.yahoo.bullet.query.Query)22 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)11 BulletRecord (com.yahoo.bullet.record.BulletRecord)11 Projection (com.yahoo.bullet.query.Projection)9 Window (com.yahoo.bullet.query.Window)9 Raw (com.yahoo.bullet.query.aggregations.Raw)9 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)9 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)8 Expression (com.yahoo.bullet.query.expressions.Expression)8 Field (com.yahoo.bullet.query.Field)7 Clip (com.yahoo.bullet.result.Clip)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)4 Computation (com.yahoo.bullet.query.postaggregations.Computation)4 RecordBox (com.yahoo.bullet.result.RecordBox)4 Operation (com.yahoo.bullet.query.expressions.Operation)3 Culling (com.yahoo.bullet.query.postaggregations.Culling)3