Search in sources :

Example 1 with MapToKeyHashValuePairConverter

use of org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter 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)

Example 2 with MapToKeyHashValuePairConverter

use of org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter in project apex-malhar by apache.

the class UniqueValueCountBenchmarkApplication method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration entries) {
    dag.setAttribute(dag.APPLICATION_NAME, "UniqueValueCountDemo");
    dag.setAttribute(dag.DEBUG, true);
    /* Generate random key-value pairs */
    RandomEventGenerator randGen = dag.addOperator("randomgen", new RandomEventGenerator());
    randGen.setMaxvalue(999999);
    randGen.setTuplesBlastIntervalMillis(50);
    dag.setAttribute(randGen, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<RandomEventGenerator>(3));
    /* Initialize with three partition to start with */
    UniqueCounter<Integer> uniqCount = dag.addOperator("uniqevalue", new UniqueCounter<Integer>());
    MapToKeyHashValuePairConverter<Integer, Integer> converter = dag.addOperator("converter", new MapToKeyHashValuePairConverter());
    dag.setAttribute(uniqCount, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<UniqueCounter<Integer>>(3));
    dag.setInputPortAttribute(uniqCount.data, Context.PortContext.PARTITION_PARALLEL, true);
    uniqCount.setCumulative(false);
    Counter counter = dag.addOperator("count", new Counter());
    ConsoleOutputOperator output = dag.addOperator("output", new ConsoleOutputOperator());
    dag.addStream("datain", randGen.integer_data, uniqCount.data);
    dag.addStream("convert", uniqCount.count, converter.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("consoutput", converter.output, counter.input);
    dag.addStream("final", counter.output, output.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) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator)

Example 3 with MapToKeyHashValuePairConverter

use of org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter in project apex-malhar by apache.

the class UniqueKeyValCountExample method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration entries) {
    /* Generate random key-value pairs */
    RandomDataGenerator randGen = dag.addOperator("randomgen", new RandomDataGenerator());
    /* Initialize with three partition to start with */
    UniqueCounter<KeyValPair<String, Object>> uniqCount = dag.addOperator("uniqevalue", new UniqueCounter<KeyValPair<String, Object>>());
    MapToKeyHashValuePairConverter<KeyValPair<String, Object>, Integer> converter = dag.addOperator("converter", new MapToKeyHashValuePairConverter());
    uniqCount.setCumulative(false);
    dag.setAttribute(randGen, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<UniqueCounter<KeyValPair<String, Object>>>(3));
    ConsoleOutputOperator output = dag.addOperator("output", new ConsoleOutputOperator());
    dag.addStream("datain", randGen.outPort, uniqCount.data);
    dag.addStream("convert", uniqCount.count, converter.input).setLocality(Locality.THREAD_LOCAL);
    dag.addStream("consoutput", converter.output, output.input);
}
Also used : UniqueCounter(org.apache.apex.malhar.lib.algo.UniqueCounter) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) MapToKeyHashValuePairConverter(org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair)

Aggregations

UniqueCounter (org.apache.apex.malhar.lib.algo.UniqueCounter)3 MapToKeyHashValuePairConverter (org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter)3 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)3 Counter (org.apache.apex.malhar.lib.stream.Counter)2 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)1 KeyHashValPair (org.apache.apex.malhar.lib.util.KeyHashValPair)1 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)1