use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class ExplodeFunctorTest method testApplyToNotMap.
@Test
public void testApplyToNotMap() {
Explode explode = new Explode(new FieldExpression("listA"), "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 ExplodeFunctorTest method testApplyToMap.
@Test
public void testApplyToMap() {
Explode explode = new Explode(new FieldExpression("mapA"), "foo", "bar", false);
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);
}
use of com.yahoo.bullet.query.tablefunctions.Explode 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);
}
use of com.yahoo.bullet.query.tablefunctions.Explode in project bullet-core by yahoo.
the class ExplodeFunctorTest method testApplyWithBadEvaluator.
@Test
public void testApplyWithBadEvaluator() {
Explode explode = new Explode(new UnaryExpression(new ValueExpression(5), Operation.SIZE_OF), "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 ExplodeFunctorTest method testConstructor.
@Test
public void testConstructor() {
Explode explode = new Explode(new FieldExpression("abc"), "foo", "bar", true);
ExplodeFunctor functor = new ExplodeFunctor(explode);
Assert.assertTrue(functor.field instanceof FieldEvaluator);
Assert.assertEquals(functor.keyAlias, "foo");
Assert.assertEquals(functor.valueAlias, "bar");
Assert.assertTrue(functor.outer);
}
Aggregations