Search in sources :

Example 56 with FieldExpression

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);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 57 with FieldExpression

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");
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 58 with FieldExpression

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);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 59 with FieldExpression

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);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 60 with FieldExpression

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));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)63 Test (org.testng.annotations.Test)60 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)33 BulletRecord (com.yahoo.bullet.record.BulletRecord)33 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)30 Query (com.yahoo.bullet.query.Query)27 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)15 Explode (com.yahoo.bullet.query.tablefunctions.Explode)15 Clip (com.yahoo.bullet.result.Clip)13 ArrayList (java.util.ArrayList)13 Projection (com.yahoo.bullet.query.Projection)12 Window (com.yahoo.bullet.query.Window)12 Raw (com.yahoo.bullet.query.aggregations.Raw)12 Expression (com.yahoo.bullet.query.expressions.Expression)12 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)11 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)11 Field (com.yahoo.bullet.query.Field)9 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)7 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 RecordBox (com.yahoo.bullet.result.RecordBox)6