Search in sources :

Example 26 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class TwitterTopCounterApplication method consoleOutput.

public static void consoleOutput(DAG dag, String operatorName, OutputPort<List<Map<String, Object>>> topCount, String schemaFile, String alias) {
    if (PubSubHelper.isGatewayConfigured(dag)) {
        URI uri = PubSubHelper.getURI(dag);
        AppDataSnapshotServerMap snapshotServer = dag.addOperator("SnapshotServer", new AppDataSnapshotServerMap());
        Map<String, String> conversionMap = Maps.newHashMap();
        conversionMap.put(alias, WindowedTopCounter.FIELD_TYPE);
        String snapshotServerJSON = SchemaUtils.jarResourceFileToString(schemaFile);
        snapshotServer.setSnapshotSchemaJSON(snapshotServerJSON);
        snapshotServer.setTableFieldToMapField(conversionMap);
        PubSubWebSocketAppDataQuery wsQuery = new PubSubWebSocketAppDataQuery();
        wsQuery.setUri(uri);
        snapshotServer.setEmbeddableQueryInfoProvider(wsQuery);
        PubSubWebSocketAppDataResult wsResult = dag.addOperator("QueryResult", new PubSubWebSocketAppDataResult());
        wsResult.setUri(uri);
        Operator.InputPort<String> queryResultPort = wsResult.input;
        dag.addStream("MapProvider", topCount, snapshotServer.input);
        dag.addStream("Result", snapshotServer.queryResult, queryResultPort);
    } else {
        ConsoleOutputOperator operator = dag.addOperator(operatorName, new ConsoleOutputOperator());
        operator.setStringFormat(operatorName + ": %s");
        dag.addStream("MapProvider", topCount, operator.input);
    }
}
Also used : Operator(com.datatorrent.api.Operator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) PubSubWebSocketAppDataResult(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult) AppDataSnapshotServerMap(org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap) PubSubWebSocketAppDataQuery(org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery) URI(java.net.URI)

Example 27 with ConsoleOutputOperator

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

Example 28 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class Application method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    WordCountInputOperator input = dag.addOperator("wordinput", new WordCountInputOperator());
    UniqueCounter<String> wordCount = dag.addOperator("count", new UniqueCounter<String>());
    dag.addStream("wordinput-count", input.outputPort, wordCount.data);
    ConsoleOutputOperator consoleOperator = dag.addOperator("console", new ConsoleOutputOperator());
    dag.addStream("count-console", wordCount.count, consoleOperator.input);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator)

Example 29 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class Application method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    RandomEventGenerator rand = dag.addOperator("rand", new RandomEventGenerator());
    PiCalculateOperator calc = dag.addOperator("picalc", new PiCalculateOperator());
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    dag.addStream("rand_calc", rand.integer_data, calc.input).setLocality(locality);
    dag.addStream("rand_console", calc.output, console.input).setLocality(locality);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator)

Example 30 with ConsoleOutputOperator

use of org.apache.apex.malhar.lib.io.ConsoleOutputOperator in project apex-malhar by apache.

the class ApplicationWithScript method populateDAG.

@Override
public void populateDAG(DAG dag, Configuration conf) {
    int maxValue = 30000;
    RandomEventGenerator rand = dag.addOperator("rand", new RandomEventGenerator());
    rand.setMinvalue(0);
    rand.setMaxvalue(maxValue);
    RoundRobinHashMap<String, Object> rrhm = dag.addOperator("rrhm", new RoundRobinHashMap<String, Object>());
    rrhm.setKeys(new String[] { "x", "y" });
    JavaScriptOperator calc = dag.addOperator("picalc", new JavaScriptOperator());
    calc.setPassThru(false);
    calc.put("i", 0);
    calc.put("count", 0);
    calc.addSetupScript("function pi() { if (x*x+y*y <= " + maxValue * maxValue + ") { i++; } count++; return i / count * 4; }");
    calc.setInvoke("pi");
    dag.addStream("rand_rrhm", rand.integer_data, rrhm.data);
    dag.addStream("rrhm_calc", rrhm.map, calc.inBindings);
    ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
    dag.addStream("rand_console", calc.result, console.input);
}
Also used : ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) RandomEventGenerator(org.apache.apex.malhar.lib.testbench.RandomEventGenerator) JavaScriptOperator(org.apache.apex.malhar.lib.script.JavaScriptOperator)

Aggregations

ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)36 RandomEventGenerator (org.apache.apex.malhar.lib.testbench.RandomEventGenerator)6 Operator (com.datatorrent.api.Operator)5 Counter (org.apache.apex.malhar.lib.stream.Counter)5 PubSubWebSocketAppDataQuery (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery)4 PubSubWebSocketAppDataResult (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult)4 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)4 URI (java.net.URI)3 UniqueCounter (org.apache.apex.malhar.lib.algo.UniqueCounter)3 AppDataSnapshotServerMap (org.apache.apex.malhar.lib.appdata.snapshot.AppDataSnapshotServerMap)3 MapToKeyHashValuePairConverter (org.apache.apex.malhar.lib.converter.MapToKeyHashValuePairConverter)3 WindowState (org.apache.apex.malhar.lib.window.WindowState)3 List (java.util.List)2 FunctionOperator (org.apache.apex.malhar.lib.function.FunctionOperator)2 ApacheLogParseMapOutputOperator (org.apache.apex.malhar.lib.logs.ApacheLogParseMapOutputOperator)2 DimensionObject (org.apache.apex.malhar.lib.logs.DimensionObject)2 JsonByteArrayOperator (org.apache.apex.malhar.lib.stream.JsonByteArrayOperator)2 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)2 FSWindowDataManager (org.apache.apex.malhar.lib.wal.FSWindowDataManager)2 TriggerOption (org.apache.apex.malhar.lib.window.TriggerOption)2