use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitioner method mapFieldsToValues.
private void mapFieldsToValues(Expression expression, Map<String, Set<Serializable>> mapping) {
if (!(expression instanceof BinaryExpression)) {
return;
}
BinaryExpression binary = (BinaryExpression) expression;
if (binary.getOp() == Operation.AND) {
mapFieldsToValues(binary.getLeft(), mapping);
mapFieldsToValues(binary.getRight(), mapping);
} else if (binary.getOp() == Operation.EQUALS) {
if (binary.getLeft() instanceof FieldExpression && binary.getRight() instanceof ValueExpression) {
addFieldToMapping((FieldExpression) binary.getLeft(), (ValueExpression) binary.getRight(), mapping);
} else if (binary.getRight() instanceof FieldExpression && binary.getLeft() instanceof ValueExpression) {
addFieldToMapping((FieldExpression) binary.getRight(), (ValueExpression) binary.getLeft(), mapping);
}
}
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class SimpleEqualityPartitionerTest method testDefaultPartitioningQueryWithNullEqualityFilters.
@Test
public void testDefaultPartitioningQueryWithNullEqualityFilters() {
SimpleEqualityPartitioner partitioner = createPartitioner("A", "B");
Query query = createQuery(new BinaryExpression(new FieldExpression("A"), new ValueExpression(null), Operation.EQUALS), new BinaryExpression(new FieldExpression("B"), new ValueExpression(null), Operation.EQUALS));
Assert.assertEquals(partitioner.getKeys(query), singleton("null-null"));
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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."));
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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."));
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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);
}
Aggregations