use of edu.iu.dsc.tws.api.tset.schema.KeyedSchema in project twister2 by DSC-SPIDAL.
the class SetSchemaExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
SourceTSet<Integer> src = env.createSource(new BaseSourceFunc<Integer>() {
private int i = 0;
@Override
public void prepare(TSetContext ctx) {
super.prepare(ctx);
LOG.info("schemas0: " + ctx.getInputSchema() + " -> " + ctx.getOutputSchema());
}
@Override
public boolean hasNext() {
return i == 0;
}
@Override
public Integer next() {
return ++i;
}
}, 2).setName("src");
src.direct().forEach(ii -> LOG.info("out0: " + ii));
src.withSchema(PrimitiveSchemas.INTEGER).direct().forEach(ii -> LOG.info("out1: " + ii));
ComputeTSet<String> map = src.allReduce(Integer::sum).map(new BaseMapFunc<Integer, String>() {
@Override
public void prepare(TSetContext ctx) {
super.prepare(ctx);
LOG.info("schemas1: " + ctx.getInputSchema() + " -> " + ctx.getOutputSchema());
}
@Override
public String map(Integer input) {
return input.toString();
}
});
map.direct().forEach(ii -> LOG.info("out2: " + ii));
map.withSchema(PrimitiveSchemas.STRING).direct().forEach(ii -> LOG.info("out3: " + ii));
KeyedTSet<String, Integer> keyed = map.mapToTuple(new BaseMapFunc<String, Tuple<String, Integer>>() {
@Override
public void prepare(TSetContext ctx) {
super.prepare(ctx);
LOG.info("schemas2: " + ctx.getInputSchema() + " -> " + ctx.getOutputSchema());
}
@Override
public Tuple<String, Integer> map(String input) {
return new Tuple<>(input, Integer.parseInt(input));
}
});
keyed.keyedDirect().forEach(ii -> LOG.info("out4: " + ii));
keyed.withSchema(new KeyedSchema(MessageTypes.STRING, MessageTypes.INTEGER)).keyedDirect().forEach(ii -> LOG.info("out5: " + ii));
}
Aggregations