use of org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration configuration) {
WordGenerator inputOperator = new WordGenerator();
KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> windowedOperator = new KeyedWindowedOperatorImpl<>();
Accumulation<Long, MutableLong, Long> sum = new SumAccumulation();
windowedOperator.setAccumulation(sum);
windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableLong>());
windowedOperator.setRetractionStorage(new InMemoryWindowedKeyedStorage<String, Long>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1)));
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingAndRetractingFiredPanes());
// windowedOperator.setAllowedLateness(Duration.millis(14000));
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
use of org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration conf) {
dag.setAttribute(DAG.STREAMING_WINDOW_SIZE_MILLIS, 1000);
NycTaxiDataReader inputOperator = new NycTaxiDataReader();
inputOperator.setDirectory("/user/" + System.getProperty("user.name") + "/nyctaxidata");
inputOperator.getScanner().setFilePatternRegexp(".*\\.csv$");
dag.addOperator("NycTaxiDataReader", inputOperator);
NycTaxiCsvParser parser = dag.addOperator("NycTaxiCsvParser", new NycTaxiCsvParser());
NycTaxiZipFareExtractor extractor = dag.addOperator("NycTaxiZipFareExtractor", new NycTaxiZipFareExtractor());
KeyedWindowedOperatorImpl<String, Double, MutableDouble, Double> windowedOperator = new KeyedWindowedOperatorImpl<>();
// 5-minute windows slide by 1 minute
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(5)).slideBy(Duration.standardMinutes(1)));
// Because we only care about the last 5 minutes, and the watermark is set at t-1 minutes, lateness horizon is set to 4 minutes.
windowedOperator.setAllowedLateness(Duration.standardMinutes(4));
windowedOperator.setAccumulation(new SumDouble());
windowedOperator.setTriggerOption(TriggerOption.AtWatermark());
windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableDouble>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
dag.addOperator("WindowedOperator", windowedOperator);
NycTaxiDataServer dataServer = dag.addOperator("NycTaxiDataServer", new NycTaxiDataServer());
ConsoleOutputOperator console = dag.addOperator("console", new ConsoleOutputOperator());
dag.addStream("input_to_parser", inputOperator.output, parser.input);
dag.addStream("parser_to_extractor", parser.output, extractor.input);
dag.addStream("extractor_to_windowed", extractor.output, windowedOperator.input);
dag.addStream("extractor_watermark", extractor.watermarkOutput, windowedOperator.controlInput);
dag.addStream("windowed_to_console", windowedOperator.output, dataServer.input, console.input);
PubSubWebSocketAppDataQuery wsQuery = new PubSubWebSocketAppDataQuery();
wsQuery.enableEmbeddedMode();
wsQuery.setTopic("nyctaxi.query");
try {
wsQuery.setUri(new URI("ws://" + java.net.InetAddress.getLocalHost().getHostName() + ":8890/pubsub"));
} catch (URISyntaxException | UnknownHostException ex) {
throw Throwables.propagate(ex);
}
dataServer.setEmbeddableQueryInfoProvider(wsQuery);
PubSubWebSocketAppDataResult wsResult = dag.addOperator("QueryResult", new PubSubWebSocketAppDataResult());
wsResult.setTopic("nyctaxi.result");
try {
wsResult.setUri(new URI("ws://" + java.net.InetAddress.getLocalHost().getHostName() + ":8890/pubsub"));
} catch (URISyntaxException | UnknownHostException ex) {
throw Throwables.propagate(ex);
}
dag.addStream("server_to_query_output", dataServer.queryResult, wsResult.input);
}
use of org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl in project apex-malhar by apache.
the class WindowedOperatorTest method createDefaultKeyedWindowedOperator.
private KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> createDefaultKeyedWindowedOperator(boolean forSession) {
KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> windowedOperator = new KeyedWindowedOperatorImpl<>();
if (useSpillable) {
sccImpl = new SpillableComplexComponentImpl(testMeta.timeStore);
// TODO: We don't yet support Spillable data structures for window state storage because SpillableMapImpl does not yet support iterating over all keys.
windowStateStorage = new InMemoryWindowedStorage<>();
if (forSession) {
SpillableSessionWindowedStorage<String, MutableLong> sws = new SpillableSessionWindowedStorage<>();
sws.setSpillableComplexComponent(sccImpl);
keyedDataStorage = sws;
} else {
SpillableWindowedKeyedStorage<String, MutableLong> kds = new SpillableWindowedKeyedStorage<>();
kds.setSpillableComplexComponent(sccImpl);
keyedDataStorage = kds;
}
SpillableWindowedKeyedStorage<String, Long> krs = new SpillableWindowedKeyedStorage<>();
krs.setSpillableComplexComponent(sccImpl);
keyedRetractionStorage = krs;
windowedOperator.addComponent("SpillableComplexComponent", sccImpl);
} else {
windowStateStorage = new InMemoryWindowedStorage<>();
if (forSession) {
keyedDataStorage = new InMemorySessionWindowedStorage<>();
} else {
keyedDataStorage = new InMemoryWindowedKeyedStorage<>();
}
keyedRetractionStorage = new InMemoryWindowedKeyedStorage<>();
}
windowedOperator.setDataStorage(keyedDataStorage);
windowedOperator.setRetractionStorage(keyedRetractionStorage);
windowedOperator.setWindowStateStorage(windowStateStorage);
windowedOperator.setAccumulation(new SumAccumulation());
return windowedOperator;
}
Aggregations