Search in sources :

Example 11 with FieldExpression

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

the class OrderByStrategyTest method testOrderByAscendingWithDifferentType.

@Test
public void testOrderByAscendingWithDifferentType() {
    OrderByStrategy orderByStrategy = makeOrderBy(Arrays.asList(new OrderBy.SortItem(new FieldExpression("a"), OrderBy.Direction.ASC), new OrderBy.SortItem(new FieldExpression("b"), 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(), 2.0);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 4);
    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 12 with FieldExpression

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

the class OrderByStrategyTest method testOrderByComputationWithMultipleFields.

@Test
public void testOrderByComputationWithMultipleFields() {
    OrderByStrategy orderByStrategy = makeOrderBy(Collections.singletonList(new OrderBy.SortItem(new BinaryExpression(new FieldExpression("a"), new FieldExpression("b"), Operation.ADD), 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(), 1);
    Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 7);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 5);
    Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 4);
    Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 2);
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 13 with FieldExpression

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

the class OrderByStrategyTest method testOrderByAscendingWithSomeMissingField.

@Test
public void testOrderByAscendingWithSomeMissingField() {
    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).getRecord());
    records.add(RecordBox.get().add("a", 2).add("b", 4).getRecord());
    records.add(RecordBox.get().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(), null);
    Assert.assertEquals(result.getRecords().get(0).typedGet("b").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(1).typedGet("a").getValue(), 1);
    Assert.assertEquals(result.getRecords().get(1).typedGet("b").getValue(), 7);
    Assert.assertEquals(result.getRecords().get(2).typedGet("a").getValue(), 2);
    Assert.assertEquals(result.getRecords().get(2).typedGet("b").getValue(), 4);
    Assert.assertEquals(result.getRecords().get(3).typedGet("a").getValue(), 5);
    Assert.assertEquals(result.getRecords().get(3).typedGet("b").getValue(), 2);
}
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 14 with FieldExpression

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

the class LateralViewFunctorTest method testApplyWithExplode.

@Test
public void testApplyWithExplode() {
    LateralView lateralView = new LateralView(new Explode(new FieldExpression("mapA"), "foo", "bar", false));
    LateralViewFunctor functor = new LateralViewFunctor(lateralView);
    List<BulletRecord> records = functor.apply(record, provider);
    Assert.assertEquals(records.size(), 3);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(0)).getBaseRecord().fieldCount(), 5);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(0)).getTopRecord().fieldCount(), 2);
    Assert.assertEquals(records.get(0).typedGet("foo").getValue(), "a");
    Assert.assertEquals(records.get(0).typedGet("bar").getValue(), 0);
    Assert.assertFalse(records.get(0).typedGet("listA").isNull());
    Assert.assertFalse(records.get(0).typedGet("listB").isNull());
    Assert.assertFalse(records.get(0).typedGet("mapA").isNull());
    Assert.assertFalse(records.get(0).typedGet("mapB").isNull());
    Assert.assertEquals(((LateralViewBulletRecord) records.get(1)).getBaseRecord().fieldCount(), 5);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(1)).getTopRecord().fieldCount(), 2);
    Assert.assertEquals(records.get(1).typedGet("foo").getValue(), "b");
    Assert.assertEquals(records.get(1).typedGet("bar").getValue(), 1);
    Assert.assertFalse(records.get(1).typedGet("listA").isNull());
    Assert.assertFalse(records.get(1).typedGet("listB").isNull());
    Assert.assertFalse(records.get(1).typedGet("mapA").isNull());
    Assert.assertFalse(records.get(1).typedGet("mapB").isNull());
    Assert.assertEquals(((LateralViewBulletRecord) records.get(2)).getBaseRecord().fieldCount(), 5);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(2)).getTopRecord().fieldCount(), 2);
    Assert.assertEquals(records.get(2).typedGet("foo").getValue(), "c");
    Assert.assertEquals(records.get(2).typedGet("bar").getValue(), 2);
    Assert.assertFalse(records.get(2).typedGet("listA").isNull());
    Assert.assertFalse(records.get(2).typedGet("listB").isNull());
    Assert.assertFalse(records.get(2).typedGet("mapA").isNull());
    Assert.assertFalse(records.get(2).typedGet("mapB").isNull());
    lateralView = new LateralView(new Explode(new FieldExpression("mapB"), "foo", "bar", false));
    functor = new LateralViewFunctor(lateralView);
    records = functor.apply(record, provider);
    Assert.assertEquals(records.size(), 0);
}
Also used : Explode(com.yahoo.bullet.query.tablefunctions.Explode) BulletRecord(com.yahoo.bullet.record.BulletRecord) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 15 with FieldExpression

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

the class LateralViewFunctorTest method testApplyWithOuterExplode.

@Test
public void testApplyWithOuterExplode() {
    LateralView lateralView = new LateralView(new Explode(new FieldExpression("mapB"), "foo", "bar", true));
    LateralViewFunctor functor = new LateralViewFunctor(lateralView);
    List<BulletRecord> records = functor.apply(record, provider);
    Assert.assertEquals(records.size(), 1);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(0)).getBaseRecord().fieldCount(), 5);
    Assert.assertEquals(((LateralViewBulletRecord) records.get(0)).getTopRecord().fieldCount(), 0);
    Assert.assertFalse(records.get(0).typedGet("listA").isNull());
    Assert.assertFalse(records.get(0).typedGet("listB").isNull());
    Assert.assertFalse(records.get(0).typedGet("mapA").isNull());
    Assert.assertFalse(records.get(0).typedGet("mapB").isNull());
}
Also used : Explode(com.yahoo.bullet.query.tablefunctions.Explode) BulletRecord(com.yahoo.bullet.record.BulletRecord) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) 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