use of com.yahoo.bullet.query.tablefunctions.TableFunction 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.TableFunction in project bullet-core by yahoo.
the class Querier method start.
// ********************************* Monoidal Interface Overrides *********************************
/**
* Starts the query.
*/
private void start() {
// Is an empty map if metadata was disabled
metaKeys = (Map<String, String>) config.getAs(BulletConfig.RESULT_METADATA_METRICS, Map.class);
boolean isRateLimitEnabled = config.getAs(BulletConfig.RATE_LIMIT_ENABLE, Boolean.class);
if (isRateLimitEnabled) {
int maxEmit = config.getAs(BulletConfig.RATE_LIMIT_MAX_EMIT_COUNT, Integer.class);
int timeInterval = config.getAs(BulletConfig.RATE_LIMIT_TIME_INTERVAL, Integer.class);
rateLimit = new RateLimiter(maxEmit, timeInterval);
}
Query query = runningQuery.getQuery();
Expression filter = query.getFilter();
if (filter != null) {
this.filter = new Filter(filter);
}
TableFunction tableFunction = query.getTableFunction();
if (tableFunction != null) {
tableFunctor = tableFunction.getTableFunctor();
}
com.yahoo.bullet.query.Projection projection = query.getProjection();
if (projection.getType() != PASS_THROUGH) {
this.projection = new Projection(projection.getFields());
}
// Aggregation and Strategy are guaranteed to not be null.
Strategy strategy = query.getAggregation().getStrategy(config);
List<PostAggregation> postAggregations = query.getPostAggregations();
if (postAggregations != null && !postAggregations.isEmpty()) {
postStrategies = postAggregations.stream().map(PostAggregation::getPostStrategy).collect(Collectors.toList());
}
// Scheme is guaranteed to not be null. It is constructed in its "start" state.
window = query.getWindow().getScheme(strategy, config);
}
use of com.yahoo.bullet.query.tablefunctions.TableFunction 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