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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations