use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class ExplodeFunctorTest method testApplyWithOuter.
@Test
public void testApplyWithOuter() {
Explode explode = new Explode(new FieldExpression("mapA"), "foo", "bar", true);
ExplodeFunctor functor = new ExplodeFunctor(explode);
List<BulletRecord> records = functor.apply(record, provider);
Assert.assertEquals(records.size(), 3);
Assert.assertEquals(records.get(0).fieldCount(), 2);
Assert.assertEquals(records.get(0).typedGet("foo").getValue(), "a");
Assert.assertEquals(records.get(0).typedGet("bar").getValue(), 0);
Assert.assertEquals(records.get(1).fieldCount(), 2);
Assert.assertEquals(records.get(1).typedGet("foo").getValue(), "b");
Assert.assertEquals(records.get(1).typedGet("bar").getValue(), 1);
Assert.assertEquals(records.get(2).fieldCount(), 2);
Assert.assertEquals(records.get(2).typedGet("foo").getValue(), "c");
Assert.assertEquals(records.get(2).typedGet("bar").getValue(), 2);
explode = new Explode(new FieldExpression("mapB"), "foo", "bar", true);
functor = new ExplodeFunctor(explode);
records = functor.apply(record, provider);
Assert.assertEquals(records.size(), 1);
Assert.assertEquals(records.get(0).fieldCount(), 0);
}
use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class ExplodeFunctorTest method testApplyToEmptyMap.
@Test
public void testApplyToEmptyMap() {
Explode explode = new Explode(new FieldExpression("mapB"), "foo", "bar", false);
ExplodeFunctor functor = new ExplodeFunctor(explode);
List<BulletRecord> records = functor.apply(record, provider);
Assert.assertEquals(records.size(), 0);
}
use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class LateralViewFunctorTest method testConstructor.
@Test
public void testConstructor() {
LateralView lateralView = new LateralView(new Explode(new FieldExpression("abc"), "foo", "bar", true));
LateralViewFunctor functor = new LateralViewFunctor(lateralView);
Assert.assertTrue(functor.tableFunctors.get(0) instanceof ExplodeFunctor);
}
use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class LateralViewFunctorTest method testApplyWithMultipleExplode.
@Test
public void testApplyWithMultipleExplode() {
List<TableFunction> tableFunctions = Arrays.asList(new Explode(new FieldExpression("mapC"), "foo", "bar", false), new Explode(new FieldExpression("bar"), "key", "value", false));
LateralView lateralView = new LateralView(tableFunctions);
LateralViewFunctor functor = new LateralViewFunctor(lateralView);
List<BulletRecord> records = functor.apply(record, provider);
Assert.assertEquals(records.size(), 4);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(0)).getBaseRecord()).getBaseRecord().fieldCount(), 5);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(0)).getBaseRecord()).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) records.get(0)).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(1)).getBaseRecord()).getBaseRecord().fieldCount(), 5);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(1)).getBaseRecord()).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) records.get(1)).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(2)).getBaseRecord()).getBaseRecord().fieldCount(), 5);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(2)).getBaseRecord()).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) records.get(2)).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(3)).getBaseRecord()).getBaseRecord().fieldCount(), 5);
Assert.assertEquals(((LateralViewBulletRecord) ((LateralViewBulletRecord) records.get(3)).getBaseRecord()).getTopRecord().fieldCount(), 2);
Assert.assertEquals(((LateralViewBulletRecord) records.get(3)).getTopRecord().fieldCount(), 2);
Assert.assertTrue(records.stream().anyMatch(r -> r.typedGet("foo").getValue().equals("mapD") && r.typedGet("bar").getValue().equals(mapD) && r.typedGet("key").getValue().equals("d") && r.typedGet("value").getValue().equals(3)));
Assert.assertTrue(records.stream().anyMatch(r -> r.typedGet("foo").getValue().equals("mapD") && r.typedGet("bar").getValue().equals(mapD) && r.typedGet("key").getValue().equals("e") && r.typedGet("value").getValue().equals(4)));
Assert.assertTrue(records.stream().anyMatch(r -> r.typedGet("foo").getValue().equals("mapE") && r.typedGet("bar").getValue().equals(mapE) && r.typedGet("key").getValue().equals("f") && r.typedGet("value").getValue().equals(5)));
Assert.assertTrue(records.stream().anyMatch(r -> r.typedGet("foo").getValue().equals("mapE") && r.typedGet("bar").getValue().equals(mapE) && r.typedGet("key").getValue().equals("g") && r.typedGet("value").getValue().equals(6)));
}
Aggregations