Search in sources :

Example 1 with KeyHashValPair

use of org.apache.apex.malhar.lib.util.KeyHashValPair in project apex-malhar by apache.

the class Application method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration entries) {
    /* Generate random key-value pairs */
    RandomKeysGenerator randGen = dag.addOperator("randomgen", new RandomKeysGenerator());
    /* Initialize with three partition to start with */
    // UniqueCount1 uniqCount = dag.addOperator("uniqevalue", new UniqueCount1());
    UniqueCounter<Integer> uniqCount = dag.addOperator("uniqevalue", new UniqueCounter<Integer>());
    MapToKeyHashValuePairConverter<Integer, Integer> converter = dag.addOperator("converter", new MapToKeyHashValuePairConverter());
    uniqCount.setCumulative(false);
    dag.setAttribute(uniqCount, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<UniqueCounter<Integer>>(3));
    CountVerifier<Integer> verifier = dag.addOperator("verifier", new CountVerifier<Integer>());
    StreamDuplicater<KeyHashValPair<Integer, Integer>> dup = dag.addOperator("dup", new StreamDuplicater<KeyHashValPair<Integer, Integer>>());
    ConsoleOutputOperator output = dag.addOperator("output", new ConsoleOutputOperator());
    ConsoleOutputOperator successOutput = dag.addOperator("successoutput", new ConsoleOutputOperator());
    successOutput.setStringFormat("Success %d");
    ConsoleOutputOperator failureOutput = dag.addOperator("failureoutput", new ConsoleOutputOperator());
    failureOutput.setStringFormat("Failure %d");
    // success and failure counters.
    Counter successcounter = dag.addOperator("successcounter", new Counter());
    Counter failurecounter = dag.addOperator("failurecounter", new Counter());
    dag.addStream("datain", randGen.outPort, uniqCount.data);
    dag.addStream("dataverification0", randGen.verificationPort, verifier.in1);
    dag.addStream("convert", uniqCount.count, converter.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("split", converter.output, dup.data);
    dag.addStream("consoutput", dup.out1, output.input);
    dag.addStream("dataverification1", dup.out2, verifier.in2);
    dag.addStream("successc", verifier.successPort, successcounter.input);
    dag.addStream("failurec", verifier.failurePort, failurecounter.input);
    dag.addStream("succconsoutput", successcounter.output, successOutput.input);
    dag.addStream("failconsoutput", failurecounter.output, failureOutput.input);
}
Also used : UniqueCounter(org.apache.apex.malhar.lib.algo.UniqueCounter) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) Counter(org.apache.apex.malhar.lib.stream.Counter) UniqueCounter(org.apache.apex.malhar.lib.algo.UniqueCounter) MapToKeyHashValuePairConverter(org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter) KeyHashValPair(org.apache.apex.malhar.lib.util.KeyHashValPair)

Aggregations

UniqueCounter (org.apache.apex.malhar.lib.algo.UniqueCounter)1 MapToKeyHashValuePairConverter (org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter)1 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)1 Counter (org.apache.apex.malhar.lib.stream.Counter)1 KeyHashValPair (org.apache.apex.malhar.lib.util.KeyHashValPair)1