Search in sources :

Example 1 with LateralView

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

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

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

the class QuerierTest method testTableFunction.

@Test
public void testTableFunction() {
    TableFunction tableFunction = new LateralView(new Explode(new FieldExpression("map"), "key", "value", true));
    Projection projection = new Projection(Arrays.asList(new Field("key", new FieldExpression("key")), new Field("value", new FieldExpression("value")), new Field("abc", new FieldExpression("abc"))), false);
    Expression filter = new UnaryExpression(new FieldExpression("map"), Operation.IS_NOT_NULL);
    Query query = new Query(tableFunction, projection, filter, new Raw(500), null, new Window(), null);
    Querier querier = make(Querier.Mode.ALL, query);
    querier.consume(RecordBox.get().addMap("map", Pair.of("a", 0), Pair.of("b", 1), Pair.of("c", 2)).add("abc", 1).getRecord());
    querier.consume(RecordBox.get().add("abc", 2).getRecord());
    querier.consume(RecordBox.get().add("abc", 3).add("map", new HashMap<>()).getRecord());
    List<BulletRecord> result = querier.getResult().getRecords();
    Assert.assertEquals(result.size(), 4);
    Assert.assertEquals(result.get(0).fieldCount(), 3);
    Assert.assertEquals(result.get(0).typedGet("key").getValue(), "a");
    Assert.assertEquals(result.get(0).typedGet("value").getValue(), 0);
    Assert.assertEquals(result.get(0).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(1).fieldCount(), 3);
    Assert.assertEquals(result.get(1).typedGet("key").getValue(), "b");
    Assert.assertEquals(result.get(1).typedGet("value").getValue(), 1);
    Assert.assertEquals(result.get(1).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(2).fieldCount(), 3);
    Assert.assertEquals(result.get(2).typedGet("key").getValue(), "c");
    Assert.assertEquals(result.get(2).typedGet("value").getValue(), 2);
    Assert.assertEquals(result.get(2).typedGet("abc").getValue(), 1);
    Assert.assertEquals(result.get(3).fieldCount(), 1);
    Assert.assertEquals(result.get(3).typedGet("abc").getValue(), 3);
}
Also used : Window(com.yahoo.bullet.query.Window) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) Query(com.yahoo.bullet.query.Query) Projection(com.yahoo.bullet.query.Projection) Raw(com.yahoo.bullet.query.aggregations.Raw) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Field(com.yahoo.bullet.query.Field) BulletRecord(com.yahoo.bullet.record.BulletRecord) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) ListExpression(com.yahoo.bullet.query.expressions.ListExpression) UnaryExpression(com.yahoo.bullet.query.expressions.UnaryExpression) BinaryExpression(com.yahoo.bullet.query.expressions.BinaryExpression) ValueExpression(com.yahoo.bullet.query.expressions.ValueExpression) Expression(com.yahoo.bullet.query.expressions.Expression) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) Test(org.testng.annotations.Test) BulletConfigTest(com.yahoo.bullet.common.BulletConfigTest)

Example 4 with LateralView

use of com.yahoo.bullet.query.tablefunctions.LateralView 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);
}
Also used : Explode(com.yahoo.bullet.query.tablefunctions.Explode) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Example 5 with LateralView

use of com.yahoo.bullet.query.tablefunctions.LateralView 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)));
}
Also used : Arrays(java.util.Arrays) BulletRecord(com.yahoo.bullet.record.BulletRecord) BeforeClass(org.testng.annotations.BeforeClass) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) TypedSimpleBulletRecordProvider(com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider) RecordBox(com.yahoo.bullet.result.RecordBox) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) List(java.util.List) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Map(java.util.Map) Explode(com.yahoo.bullet.query.tablefunctions.Explode) Explode(com.yahoo.bullet.query.tablefunctions.Explode) BulletRecord(com.yahoo.bullet.record.BulletRecord) LateralView(com.yahoo.bullet.query.tablefunctions.LateralView) TableFunction(com.yahoo.bullet.query.tablefunctions.TableFunction) FieldExpression(com.yahoo.bullet.query.expressions.FieldExpression) Test(org.testng.annotations.Test)

Aggregations

FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)5 Explode (com.yahoo.bullet.query.tablefunctions.Explode)5 LateralView (com.yahoo.bullet.query.tablefunctions.LateralView)5 Test (org.testng.annotations.Test)5 BulletRecord (com.yahoo.bullet.record.BulletRecord)4 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 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)1 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)1 BulletRecordProvider (com.yahoo.bullet.record.BulletRecordProvider)1 TypedSimpleBulletRecordProvider (com.yahoo.bullet.record.simple.TypedSimpleBulletRecordProvider)1 RecordBox (com.yahoo.bullet.result.RecordBox)1