use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithOR.
@Test
public void testDefaultPartitioningQueryWithOR() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new BinaryExpression(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression("baz"), Operation.EQUALS), Operation.OR));
Assert.assertEquals(partitioner.getKeys(query), singleton("*-*"));
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithNOT.
@Test
public void testDefaultPartitioningQueryWithNOT() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new UnaryExpression(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS), Operation.NOT));
Assert.assertEquals(partitioner.getKeys(query), singleton("*-*"));
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testNoPartitioningForQueryWithExpressionFields.
@Test
public void testNoPartitioningForQueryWithExpressionFields() {
FieldExpression fieldExpression = new FieldExpression("A", new ValueExpression("b"));
SimpleEqualityPartitioner partitioner = createPartitioner(fieldExpression.getName());
Query query = createQuery(new BinaryExpression(fieldExpression, new ValueExpression("bar"), Operation.EQUALS));
Assert.assertEquals(partitioner.getKeys(query), singleton("*"));
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testPartitioningForQueryWithMissingFields.
@Test
public void testPartitioningForQueryWithMissingFields() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression("bar"), Operation.EQUALS));
Assert.assertEquals(partitioner.getKeys(query), singleton("bar.-*"));
}
use of com.yahoo.bullet.query.expressions.BinaryExpression in project bullet-core by yahoo.
the class ComputationStrategyTest method testComputation.
@Test
public void testComputation() {
// Computations are done using the fields in the original record and then the new fields are written at the end.
// a = 2 * a + 5 * b
// b = a * b
List<Field> fields = new ArrayList<>();
fields.add(new Field("a", new BinaryExpression(new BinaryExpression(new ValueExpression(2), new FieldExpression("a"), Operation.MUL), new BinaryExpression(new ValueExpression(5), new FieldExpression("b"), Operation.MUL), Operation.ADD)));
fields.add(new Field("b", new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.MUL)));
List<BulletRecord> records = new ArrayList<>();
records.add(RecordBox.get().add("a", 5).add("b", 2).add("c", 0).getRecord());
records.add(RecordBox.get().add("a", 2).add("b", 4).add("c", 1).getRecord());
records.add(RecordBox.get().add("a", 1).add("b", 7).add("c", 2).getRecord());
Clip clip = new Clip();
clip.add(records);
ComputationStrategy strategy = (ComputationStrategy) new Computation(fields).getPostStrategy();
Clip result = strategy.execute(clip);
Assert.assertEquals(result.getRecords().size(), 3);
Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 20);
Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 10);
Assert.assertEquals(result.getRecords().get(0).typedGet("c").getValue(), 0);
Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 24);
Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 8);
Assert.assertEquals(result.getRecords().get(1).typedGet("c").getValue(), 1);
Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 37);
Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 7);
Assert.assertEquals(result.getRecords().get(2).typedGet("c").getValue(), 2);
}
Aggregations