mFieldMap = Collections.unmodifiableMap(mFieldMap);
}
@Override
public void takeEvent(EventWrapper e) throws IOException, InterruptedException {
Event event = e.getEvent();
// Determine which stream the event is from; this determines which map we
// place the event in, and which map we check for candidate join matches.
String streamName = e.getAttr(STREAM_NAME_ATTR);
if (null == streamName) {
// We don't know which stream this came from. Don't process it.
LOG.warn("Got event with no " + STREAM_NAME_ATTR + " attribute!");
return;
}
WindowedHashMap<Object, EventWrapper, Long> insertMap; // Map where we insert this event.
WindowedHashMap<Object, EventWrapper, Long> joinMap; // Map we pull join candidates from.
TypedField keyField; // The field to grab from the event wrapper.
boolean isLeft;
if (streamName.equals(mLeftName)) {
insertMap = mLeftMap;
joinMap = mRightMap;
keyField = mLeftKey;
isLeft = true;
} else if (streamName.equals(mRightName)) {
insertMap = mRightMap;
joinMap = mLeftMap;
keyField = mRightKey;
isLeft = false;
} else {
// Not from either stream?
LOG.warn("Got event with unexpected " + STREAM_NAME_ATTR + "=" + streamName);
return; // Don't know what to do with this.
}
// Look up elements from the opposite map to determine what joins we can perform.
Object key = e.getField(keyField);
if (null == key) {
// The key field is null; this will not match to anything in an inner join.
return;
}
assert mTimeSpan.isRelative;
long curTime = event.getTimestamp();
Long lo;
Long hi;
if (isLeft) {
// If this event is from the left stream, calculate the relative time interval normally.
lo = curTime + mTimeSpan.lo;
hi = curTime + mTimeSpan.hi;
} else {
// If this event is from the right stream, use the "mirror image" of the timespan.
// "RANGE INTERVAL 10 MINUTES PRECEDING" actually means, join with the /next/ 10
// minutes of data from this perspective.
lo = curTime - mTimeSpan.hi;
hi = curTime - mTimeSpan.lo;
}
LOG.debug("Working on key: " + key + ", isLeft=" + isLeft);
LOG.debug("Timestamp=" + curTime + ", interval=" + lo + ", " + hi);
// Join with all the events in the window.
List<EventWrapper> joinEvents = joinMap.getRange(key, lo, hi, isLeft, !isLeft);
for (EventWrapper joinWrapper : joinEvents) {
CompositeEvent outEvent = new CompositeEvent(mFieldMap,
event.getPriority(), event.getTimestamp(), event.getNanos(), event.getHost());
CompositeEventWrapper outWrapper = new CompositeEventWrapper();
if (isLeft) {
outEvent.add(e);
outEvent.add(joinWrapper);
} else {