Search in sources :

Example 1 with Explode

use of com.yahoo.bullet.query.tablefunctions.Explode 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 2 with Explode

use of com.yahoo.bullet.query.tablefunctions.Explode 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)

Example 3 with Explode

use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.

the class ExplodeFunctorTest method testApplyToNotList.

@Test
public void testApplyToNotList() {
    Explode explode = new Explode(new FieldExpression("mapA"), "foo", null, false);
    ExplodeFunctor functor = new ExplodeFunctor(explode);
    List<BulletRecord> 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) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 4 with Explode

use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.

the class ExplodeFunctorTest method testApplyToList.

@Test
public void testApplyToList() {
    Explode explode = new Explode(new FieldExpression("listA"), "foo", null, false);
    ExplodeFunctor functor = new ExplodeFunctor(explode);
    List<BulletRecord> records = functor.apply(record, provider);
    Assert.assertEquals(records.size(), 3);
    Assert.assertEquals(records.get(0).fieldCount(), 1);
    Assert.assertEquals(records.get(0).typedGet("foo").getValue(), 0);
    Assert.assertEquals(records.get(1).fieldCount(), 1);
    Assert.assertEquals(records.get(1).typedGet("foo").getValue(), 1);
    Assert.assertEquals(records.get(2).fieldCount(), 1);
    Assert.assertEquals(records.get(2).typedGet("foo").getValue(), 2);
}
Also used : Explode(com.yahoo.bullet.query.tablefunctions.Explode) BulletRecord(com.yahoo.bullet.record.BulletRecord) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 5 with Explode

use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.

the class ExplodeFunctorTest method testApplyToEmptyList.

@Test
public void testApplyToEmptyList() {
    Explode explode = new Explode(new FieldExpression("listB"), "foo", null, false);
    ExplodeFunctor functor = new ExplodeFunctor(explode);
    List<BulletRecord> 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) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

Explode (com.yahoo.bullet.query.tablefunctions.Explode)14 Test (org.testng.annotations.Test)14 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)13 BulletRecord (com.yahoo.bullet.record.BulletRecord)12 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)5 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)2 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)2 TableFunction (com.yahoo.bullet.query.tablefunctions.TableFunction)2 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)1 Field (com.yahoo.bullet.query.Field)1 Projection (com.yahoo.bullet.query.Projection)1 Query (com.yahoo.bullet.query.Query)1 Window (com.yahoo.bullet.query.Window)1 Raw (com.yahoo.bullet.query.aggregations.Raw)1 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)1 Expression (com.yahoo.bullet.query.expressions.Expression)1 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)1 FieldEvaluator (com.yahoo.bullet.querying.evaluators.FieldEvaluator)1 BulletRecordProvider (com.yahoo.bullet.record.BulletRecordProvider)1 TypedSimpleBulletRecordProvider (com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider)1