use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class OrderByStrategyTest method testOrderByDescending.
@Test
public void testOrderByDescending() {
OrderByStrategy orderByStrategy = makeOrderBy(Arrays.asList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.DESC), new OrderBy.SortItem(new FieldExpression("b"), OrderBy.Direction.DESC)));
List<BulletRecord> records = new ArrayList<>();
records.add(RecordBox.get().add("a", 5).add("b", 2).getRecord());
records.add(RecordBox.get().add("a", 2).add("b", 4).getRecord());
records.add(RecordBox.get().add("a", 2).add("b", 2).getRecord());
records.add(RecordBox.get().add("a", 1).add("b", 7).getRecord());
Clip clip = new Clip();
clip.add(records);
Clip result = orderByStrategy.execute(clip);
Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 5);
Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 2);
Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 2);
Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 4);
Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 2);
Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 1);
Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 7);
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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");
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class OrderByStrategyTest method testOrderByAscendingWithNonExistingField.
@Test
public void testOrderByAscendingWithNonExistingField() {
OrderByStrategy orderByStrategy = makeOrderBy(Arrays.asList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.ASC), new OrderBy.SortItem(new FieldExpression("c"), OrderBy.Direction.ASC)));
List<BulletRecord> records = new ArrayList<>();
records.add(RecordBox.get().add("a", 5).add("b", 2.0).getRecord());
records.add(RecordBox.get().add("a", 2).add("b", 4).getRecord());
records.add(RecordBox.get().add("a", 2).add("b", 2.0).getRecord());
records.add(RecordBox.get().add("a", 1).add("b", 7).getRecord());
Clip clip = new Clip();
clip.add(records);
Clip result = orderByStrategy.execute(clip);
Assert.assertEquals(result.getRecords().get(0).typedGet("a").getValue(), 1);
Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 7);
Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 2);
Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 4);
Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 2.0);
Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 5);
Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 2.0);
}
use of com.yahoo.bullet.query.expressions.FieldExpression 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);
}
use of com.yahoo.bullet.query.expressions.FieldExpression in project bullet-core by yahoo.
the class FieldEvaluatorTest method testEvaluateWithExpressionsMixedIn.
@Test
public void testEvaluateWithExpressionsMixedIn() {
FieldEvaluator evaluator = new FieldEvaluator(new FieldExpression("abc", new FieldExpression("a")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP, map));
evaluator = new FieldEvaluator(new FieldExpression("abc", new FieldExpression("a"), new FieldExpression("c")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
evaluator = new FieldEvaluator(new FieldExpression("abc", 0, new FieldExpression("c")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
evaluator = new FieldEvaluator(new FieldExpression("abc", new FieldExpression("a"), "def"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
evaluator = new FieldEvaluator(new FieldExpression("aaa", new FieldExpression("b")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER_MAP, map));
evaluator = new FieldEvaluator(new FieldExpression("aaa", new FieldExpression("b"), new FieldExpression("c")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
evaluator = new FieldEvaluator(new FieldExpression("aaa", "abc", new FieldExpression("c")));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
evaluator = new FieldEvaluator(new FieldExpression("aaa", new FieldExpression("b"), "def"));
Assert.assertEquals(evaluator.evaluate(record), new TypedObject(Type.INTEGER, 5));
}
Aggregations