You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/01/29 15:50:12 UTC
[incubator-streampipes-extensions] branch dev updated (ef2fe71 ->
10f6ca4)
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a change to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git.
from ef2fe71 Merge branch 'master' into dev
add 9a5ec2f Working on merge by time processor
new 1c7bc38 Finish merge by time processor
new 10f6ca4 Merge branch 'merge' into dev
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pom.xml | 1 -
.../processors/filters/jvm/FiltersJvmInit.java | 2 +
.../filters/jvm/processor/merge/MergeByTime.java | 109 +++++++++++++++++++++
.../MergeByTimeController.java} | 42 +++++---
.../MergeByTimeParameters.java} | 25 ++++-
.../filters/jvm/processor/merge/StreamBuffer.java | 63 ++++++++++++
.../documentation.md | 17 ++--
.../icon.png | Bin 0 -> 16947 bytes
.../merge_description.png | Bin 0 -> 68816 bytes
.../strings.en | 11 +++
10 files changed, 245 insertions(+), 25 deletions(-)
create mode 100644 streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTime.java
copy streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/{compose/ComposeController.java => merge/MergeByTimeController.java} (57%)
copy streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/{compose/ComposeParameters.java => merge/MergeByTimeParameters.java} (61%)
create mode 100644 streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/StreamBuffer.java
copy streampipes-processors-filters-jvm/src/main/resources/{org.apache.streampipes.processors.filters.jvm.compose => org.apache.streampipes.processors.filters.jvm.merge}/documentation.md (59%)
create mode 100644 streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/icon.png
create mode 100644 streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/merge_description.png
create mode 100644 streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/strings.en
[incubator-streampipes-extensions] 02/02: Merge branch 'merge' into
dev
Posted by ze...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
commit 10f6ca4ae5d6d5b7053785ac0b58850e92dff2a1
Merge: ef2fe71 1c7bc38
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Jan 29 16:49:52 2020 +0100
Merge branch 'merge' into dev
pom.xml | 1 -
.../processors/filters/jvm/FiltersJvmInit.java | 2 +
.../filters/jvm/processor/merge/MergeByTime.java | 109 +++++++++++++++++++++
.../jvm/processor/merge/MergeByTimeController.java | 80 +++++++++++++++
.../jvm/processor/merge/MergeByTimeParameters.java | 56 +++++++++++
.../filters/jvm/processor/merge/StreamBuffer.java | 63 ++++++++++++
.../documentation.md | 49 +++++++++
.../icon.png | Bin 0 -> 16947 bytes
.../merge_description.png | Bin 0 -> 68816 bytes
.../strings.en | 11 +++
10 files changed, 370 insertions(+), 1 deletion(-)
[incubator-streampipes-extensions] 01/02: Finish merge by time
processor
Posted by ze...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
commit 1c7bc3830b67bfbfdbb699cd4e9fc0cc396f977d
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Jan 29 16:43:53 2020 +0100
Finish merge by time processor
---
.../filters/jvm/processor/merge/MergeByTime.java | 96 +++++++++++----------
.../jvm/processor/merge/MergeByTimeController.java | 6 +-
.../filters/jvm/processor/merge/StreamBuffer.java | 62 +++++--------
.../documentation.md | 15 ++--
.../icon.png | Bin 1854 -> 16947 bytes
.../merge_description.png | Bin 0 -> 68816 bytes
6 files changed, 84 insertions(+), 95 deletions(-)
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTime.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTime.java
index 905d27a..c53cb1c 100644
--- a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTime.java
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTime.java
@@ -17,7 +17,6 @@
*/
package org.apache.streampipes.processors.filters.jvm.processor.merge;
-import org.apache.streampipes.model.constants.PropertySelectorConstants;
import org.apache.streampipes.model.runtime.Event;
import org.apache.streampipes.model.runtime.EventFactory;
import org.apache.streampipes.model.schema.EventSchema;
@@ -25,29 +24,30 @@ import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
import org.apache.streampipes.wrapper.routing.SpOutputCollector;
import org.apache.streampipes.wrapper.runtime.EventProcessor;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
public class MergeByTime implements EventProcessor<MergeByTimeParameters> {
- private Map<String, Event> lastEvents;
private EventSchema outputSchema;
private List<String> outputKeySelectors;
+ private String timestampFieldStream0;
private String timestampFieldStream1;
- private String timestampFieldStream2;
private Integer timeInterval;
+ private StreamBuffer streamBufferS0;
+ private StreamBuffer streamBufferS1;
+
@Override
public void onInvocation(MergeByTimeParameters composeParameters, SpOutputCollector spOutputCollector, EventProcessorRuntimeContext runtimeContext) {
this.outputSchema = composeParameters.getGraph().getOutputStream().getEventSchema();
this.outputKeySelectors = composeParameters.getOutputKeySelectors();
- this.timestampFieldStream1 = composeParameters.getTimestampFieldStream1();
- this.timestampFieldStream2 = composeParameters.getTimestampFieldStream2();
+ this.timestampFieldStream0 = composeParameters.getTimestampFieldStream1();
+ this.timestampFieldStream1 = composeParameters.getTimestampFieldStream2();
this.timeInterval = composeParameters.getTimeInterval();
- this.lastEvents = new HashMap<>();
+
+ this.streamBufferS0 = new StreamBuffer(this.timestampFieldStream0);
+ this.streamBufferS1 = new StreamBuffer(this.timestampFieldStream1);
}
@@ -55,51 +55,55 @@ public class MergeByTime implements EventProcessor<MergeByTimeParameters> {
public void onEvent(Event event, SpOutputCollector spOutputCollector) {
String streamId = event.getSourceInfo().getSelectorPrefix();
- if (streamId != null) {
-
+ // Decide to which buffer the event should be added
+ if ("s0".equals(streamId)) {
+ this.streamBufferS0.add(event);
} else {
- // TODO add event to last Events
+ this.streamBufferS1.add(event);
+ }
+
+ // Calculate matching events between data streams
+ for (Event e0 : this.streamBufferS0.getList()) {
+ long time0 = e0.getFieldBySelector(timestampFieldStream0).getAsPrimitive().getAsLong();
+ for (Event e1 : this.streamBufferS1.getList()) {
+ long time1 = e1.getFieldBySelector(timestampFieldStream1).getAsPrimitive().getAsLong();
+
+ if (time0 + timeInterval > time1 && time1 > time0 - timeInterval) {
+ Event resultingEvent = mergeEvents(e0, e1);
+ spOutputCollector.collect(resultingEvent);
+ this.streamBufferS0.removeOldEvents(time0);
+ this.streamBufferS1.removeOldEvents(time1);
+ }
+ }
+ }
+
+ // Clean up buffer if events do not match to avoid buffer overflow
+ if (this.streamBufferS0.getLength() > 0 && this.streamBufferS1.getLength() > 0) {
+ Event e0 = this.streamBufferS0.get(0);
+ Event e1 = this.streamBufferS1.get(0);
+
+ long time0 = e0.getFieldBySelector(this.timestampFieldStream0).getAsPrimitive().getAsLong();
+ long time1 = e1.getFieldBySelector(this.timestampFieldStream1).getAsPrimitive().getAsLong();
+
+ if (time0 > time1) {
+ this.streamBufferS0.removeOldEvents(time0);
+ this.streamBufferS1.removeOldEvents(time0);
+ } else {
+ this.streamBufferS0.removeOldEvents(time1);
+ this.streamBufferS1.removeOldEvents(time1);
+ }
}
- }
+ }
@Override
public void onDetach() {
+ this.streamBufferS0.reset();
+ this.streamBufferS1.reset();
}
- private String getOtherStreamId(String streamId) {
- Set<String> keys = this.lastEvents.keySet();
-
- if (keys.size() != 2) {
- return null;
- } else {
- return "ddd";
- }
-
+ private Event mergeEvents(Event e1, Event e2) {
+ return EventFactory.fromEvents(e1, e2, outputSchema).getSubset(outputKeySelectors);
}
-// @Override
-// public void onDetach() {
-// this.lastEvents.clear();
-// }
-//
-// @Override
-// public void onEvent(Event event, SpOutputCollector spOutputCollector) {
-// this.lastEvents.put(event.getSourceInfo().getSelectorPrefix(), event);
-// if (lastEvents.size() == 2) {
-// spOutputCollector.collect(buildOutEvent(event.getSourceInfo().getSelectorPrefix()));
-// }
-// }
-//
-// private Event buildOutEvent(String currentSelectorPrefix) {
-// return EventFactory.fromEvents(lastEvents.get(currentSelectorPrefix), lastEvents.get
-// (getOtherSelectorPrefix(currentSelectorPrefix)), outputSchema).getSubset(outputKeySelectors);
-// }
-//
-// private String getOtherSelectorPrefix(String currentSelectorPrefix) {
-// return currentSelectorPrefix.equals(PropertySelectorConstants.FIRST_STREAM_ID_PREFIX) ?
-// PropertySelectorConstants.SECOND_STREAM_ID_PREFIX : PropertySelectorConstants
-// .FIRST_STREAM_ID_PREFIX;
-// }
-
}
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTimeController.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTimeController.java
index fe6d824..b806591 100644
--- a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTimeController.java
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/MergeByTimeController.java
@@ -39,7 +39,7 @@ public class MergeByTimeController extends StandaloneEventProcessingDeclarer<Mer
private static final String TIMESTAMP_MAPPING_STREAM_1_KEY = "timestamp_mapping_stream_1";
private static final String TIMESTAMP_MAPPING_STREAM_2_KEY = "timestamp_mapping_stream_2";
- private static final String NUMBER_MAPPING = "number-mapping";
+ private static final String NUMBER_MAPPING = "number_mapping";
private static final String TIME_INTERVAL = "time-interval";
@Override
@@ -57,7 +57,7 @@ public class MergeByTimeController extends StandaloneEventProcessingDeclarer<Mer
EpRequirements.timestampReq(),
Labels.withId(TIMESTAMP_MAPPING_STREAM_2_KEY),
PropertyScope.NONE).build())
- .requiredFloatParameter(Labels.withId(TIME_INTERVAL), NUMBER_MAPPING)
+ .requiredIntegerParameter(Labels.withId(TIME_INTERVAL), NUMBER_MAPPING)
.outputStrategy(OutputStrategies.custom(true))
.build();
}
@@ -70,7 +70,7 @@ public class MergeByTimeController extends StandaloneEventProcessingDeclarer<Mer
String timestampFieldStream1 = extractor.mappingPropertyValue(TIMESTAMP_MAPPING_STREAM_1_KEY);
String timestampFieldStream2 = extractor.mappingPropertyValue(TIMESTAMP_MAPPING_STREAM_2_KEY);
- Integer timeInterval = extractor.singleValueParameter(NUMBER_MAPPING, Integer.class);
+ Integer timeInterval = extractor.singleValueParameter(TIME_INTERVAL, Integer.class);
MergeByTimeParameters staticParam = new MergeByTimeParameters(
graph, outputKeySelectors, timestampFieldStream1, timestampFieldStream2, timeInterval);
diff --git a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/StreamBuffer.java b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/StreamBuffer.java
index 632c3df..b471ff0 100644
--- a/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/StreamBuffer.java
+++ b/streampipes-processors-filters-jvm/src/main/java/org/apache/streampipes/processors/filters/jvm/processor/merge/StreamBuffer.java
@@ -18,66 +18,46 @@ package org.apache.streampipes.processors.filters.jvm.processor.merge;
import org.apache.streampipes.model.runtime.Event;
+import java.util.Iterator;
import java.util.LinkedList;
-import java.util.Queue;
+import java.util.List;
public class StreamBuffer {
private String timestampProperty;
- private Long timeInterval;
- private Queue<Event> buffer;
+ private List<Event> buffer;
- public StreamBuffer(String timestampProperty, long timeInterval) {
+ public StreamBuffer(String timestampProperty) {
buffer = new LinkedList<>();
this.timestampProperty = timestampProperty;
- this.timeInterval = timeInterval;
}
public void add(Event event) {
buffer.add(event);
}
- public Event getMatchingEvent(long eventTimestamp) {
- Event result = null;
-
- Long timestampOfHead = this.getHeadTimestamp();
-
- // TODO remove all events that are too old
-
- if (checkTimestamp(eventTimestamp, timestampOfHead)) {
- // search for last event in timewindow
- do {
- result = buffer.remove();
-
- timestampOfHead = this.getHeadTimestamp();
-
- } while (checkTimestamp(eventTimestamp, timestampOfHead));
-
- }
+ public int getLength(){
+ return buffer.size();
+ }
- return result;
+ public List<Event> getList() {
+ return this.buffer;
}
- /**
- * Check if timestamp of head is within time window
- * @param eventTimestamp
- * @param timestampOfHead
- * @return
- */
- private boolean checkTimestamp(long eventTimestamp, Long timestampOfHead) {
- if (timestampOfHead == null) {
- return false;
- } else {
- return eventTimestamp < timestampOfHead - timeInterval || eventTimestamp > timestampOfHead + timeInterval;
- }
+ public Event get(int i) {
+ return this.buffer.get(i);
}
- private Long getHeadTimestamp() {
- Event head = this.buffer.peek();
- if (head != null) {
- return head.getFieldBySelector(timestampProperty).getAsPrimitive().getAsLong();
- } else {
- return null;
+ public void removeOldEvents(long timestamp) {
+ Iterator itr = this.buffer.iterator();
+ while (itr.hasNext())
+ {
+ Event e = (Event) itr.next();
+ if (e.getFieldBySelector(timestampProperty).getAsPrimitive().getAsLong() <= timestamp)
+ itr.remove();
}
}
+ public void reset() {
+ this.buffer = new LinkedList<>();
+ }
}
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/documentation.md b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/documentation.md
index e8e724e..507138e 100644
--- a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/documentation.md
+++ b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/documentation.md
@@ -26,19 +26,24 @@
## Description
-Merges two event streams. Any time, a new input event arrives, it is merged with the last input event from the other
-event stream and forwarded.
+Merges two event streams by their timestamp.
+Two events of the different streams are merged when they occure to the same time
+The following figure shows how the events of the two data streams will be mergrged:
+
+<p align="center">
+ <img src="merge_description.png" class="pe-image-documentation"/>
+</p>
***
## Required input
-The Compose processor does not have any specific input requirements.
-
+Each of the data streams needs a timestamp.
***
## Configuration
-(no further configuration required)
+* For each stream a the timestamp property on which the merger is performed has to be selected
+* The Time Interval describes the maximum value between two events to decide whether they are a match. To be a valid match the following function must be true: | timestamp_stream_1 - timestamp_stream_2 | < interval
## Output
The compose processor has a configurable output that can be selected by the user at pipeline modeling time.
\ No newline at end of file
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/icon.png b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/icon.png
index 4b06333..e2929cc 100644
Binary files a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/icon.png and b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/icon.png differ
diff --git a/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/merge_description.png b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/merge_description.png
new file mode 100644
index 0000000..a08c6b1
Binary files /dev/null and b/streampipes-processors-filters-jvm/src/main/resources/org.apache.streampipes.processors.filters.jvm.merge/merge_description.png differ