Java Code Examples for org.apache.flink.streaming.runtime.streamrecord.StreamRecord#getValue()

The following examples show how to use org.apache.flink.streaming.runtime.streamrecord.StreamRecord#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowOperatorTest.java    From flink with Apache License 2.0 7 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple3<String, Long, Long>> sr0 = (StreamRecord<Tuple3<String, Long, Long>>) o1;
		StreamRecord<Tuple3<String, Long, Long>> sr1 = (StreamRecord<Tuple3<String, Long, Long>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			comparison = (int) (sr0.getValue().f1 - sr1.getValue().f1);
			if (comparison != 0) {
				return comparison;
			}
			return (int) (sr0.getValue().f2 - sr1.getValue().f2);
		}
	}
}
 
Example 2
Source File: AbstractMapBundleOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(StreamRecord<IN> element) throws Exception {
	// get the key and value for the map bundle
	final IN input = element.getValue();
	final K bundleKey = getKey(input);
	final V bundleValue = bundle.get(bundleKey);

	// get a new value after adding this element to bundle
	final V newBundleValue = function.addInput(bundleValue, input);

	// update to map bundle
	bundle.put(bundleKey, newBundleValue);

	numOfElements++;
	bundleTrigger.onElement(input);
}
 
Example 3
Source File: AbstractMapBundleOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(StreamRecord<IN> element) throws Exception {
	// get the key and value for the map bundle
	final IN input = element.getValue();
	final K bundleKey = getKey(input);
	final V bundleValue = bundle.get(bundleKey);

	// get a new value after adding this element to bundle
	final V newBundleValue = function.addInput(bundleValue, input);

	// update to map bundle
	bundle.put(bundleKey, newBundleValue);

	numOfElements++;
	bundleTrigger.onElement(input);
}
 
Example 4
Source File: WindowOperatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
	if (o1 instanceof Watermark || o2 instanceof Watermark) {
		return 0;
	} else {
		StreamRecord<Tuple3<String, Long, Long>> sr0 = (StreamRecord<Tuple3<String, Long, Long>>) o1;
		StreamRecord<Tuple3<String, Long, Long>> sr1 = (StreamRecord<Tuple3<String, Long, Long>>) o2;
		if (sr0.getTimestamp() != sr1.getTimestamp()) {
			return (int) (sr0.getTimestamp() - sr1.getTimestamp());
		}
		int comparison = sr0.getValue().f0.compareTo(sr1.getValue().f0);
		if (comparison != 0) {
			return comparison;
		} else {
			comparison = (int) (sr0.getValue().f1 - sr1.getValue().f1);
			if (comparison != 0) {
				return comparison;
			}
			return (int) (sr0.getValue().f2 - sr1.getValue().f2);
		}
	}
}
 
Example 5
Source File: RankOperator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void processElement(StreamRecord<BaseRow> element) throws Exception {
	BaseRow input = element.getValue();
	// add 1 when meets a new row
	rowNum += 1L;
	if (lastInput == null || partitionByComp.compare(lastInput, input) != 0) {
		// reset rank value and row number value for new group
		rank = 1L;
		rowNum = 1L;
	} else if (orderByComp.compare(lastInput, input) != 0) {
		// set rank value as row number value if order-by value is change in a group
		rank = rowNum;
	}

	emitInternal(input);
	lastInput = inputSer.copy(input);
}
 
Example 6
Source File: RowTimeSortOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<RowData> element) throws Exception {
	RowData input = element.getValue();

	// timestamp of the processed row
	long rowTime = input.getLong(rowTimeIdx);

	Long lastTriggeringTs = lastTriggeringTsState.value();

	// check if the row is late and drop it if it is late
	if (lastTriggeringTs == null || rowTime > lastTriggeringTs) {
		// get list for timestamp
		List<RowData> rows = dataState.get(rowTime);
		if (null != rows) {
			rows.add(input);
			dataState.put(rowTime, rows);
		} else {
			List<RowData> newRows = new ArrayList<>();
			newRows.add(input);
			dataState.put(rowTime, newRows);

			// register event time timer
			timerService.registerEventTimeTimer(rowTime);
		}

	}
}
 
Example 7
Source File: CEPOperatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void verifyPattern(Object outputObject, Event start, SubEvent middle, Event end) {
	assertTrue(outputObject instanceof StreamRecord);

	StreamRecord<?> resultRecord = (StreamRecord<?>) outputObject;
	assertTrue(resultRecord.getValue() instanceof Map);

	@SuppressWarnings("unchecked")
	Map<String, List<Event>> patternMap = (Map<String, List<Event>>) resultRecord.getValue();
	assertEquals(start, patternMap.get("start").get(0));
	assertEquals(middle, patternMap.get("middle").get(0));
	assertEquals(end, patternMap.get("end").get(0));
}
 
Example 8
Source File: IngressRouterOperator.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<T> element) {
  final T value = element.getValue();
  for (Router<T> router : routers) {
    router.route(value, downstream);
  }
}
 
Example 9
Source File: SinkOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<RowData> element) throws Exception {
	sinkContext.element = element;
	RowData row = element.getValue();
	if (notNullCheck) {
		if (failOrFilterNullValues(row)) {
			return;
		}
	}
	userFunction.invoke(row, sinkContext);
}
 
Example 10
Source File: TemporalRowTimeJoinOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement2(StreamRecord<RowData> element) throws Exception {
	RowData row = element.getValue();
	checkNotRetraction(row);

	long rowTime = getRightTime(row);
	rightState.put(rowTime, row);
	registerSmallestTimer(rowTime); // Timer to clean up the state

	registerProcessingCleanupTimer();
}
 
Example 11
Source File: TimestampedValue.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a TimestampedValue from given {@link StreamRecord}.
 *
 * @param streamRecord The StreamRecord object from which TimestampedValue is to be created.
    */
public static <T> TimestampedValue<T> from(StreamRecord<T> streamRecord) {
	if (streamRecord.hasTimestamp()) {
		return new TimestampedValue<>(streamRecord.getValue(), streamRecord.getTimestamp());
	} else {
		return new TimestampedValue<>(streamRecord.getValue());
	}
}
 
Example 12
Source File: TimestampITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (element.getTimestamp() != element.getValue()) {
		Assert.fail("Timestamps are not properly handled.");
	}
	output.collect(element);
}
 
Example 13
Source File: StreamOperatorSnapshotRestoreTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (verifyRestore) {
		// check restored managed keyed state
		long exp = element.getValue() + 1;
		long act = keyedState.value();
		Assert.assertEquals(exp, act);
	} else {
		// write managed keyed state that goes into snapshot
		keyedState.update(element.getValue() + 1);
		// write managed operator state that goes into snapshot
		opState.add(element.getValue());
	}
}
 
Example 14
Source File: TimestampITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Integer> element) throws Exception {
	if (timestampsEnabled) {
		if (element.getTimestamp() != element.getValue()) {
			Assert.fail("Timestamps are not properly handled.");
		}
	}
	output.collect(element);
}
 
Example 15
Source File: Kafka011ITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Long> element) throws Exception {
	elCount++;
	if (element.getValue() * 2 != element.getTimestamp()) {
		throw new RuntimeException("Invalid timestamp: " + element);
	}
}
 
Example 16
Source File: TimestampsAndWatermarksOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(final StreamRecord<T> element) throws Exception {
	final T event = element.getValue();
	final long previousTimestamp = element.hasTimestamp() ? element.getTimestamp() : Long.MIN_VALUE;
	final long newTimestamp = timestampAssigner.extractTimestamp(event, previousTimestamp);

	element.setTimestamp(newTimestamp);
	output.collect(element);
	watermarkGenerator.onEvent(event, newTimestamp, wmOutput);
}
 
Example 17
Source File: Kafka011ITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void processElement(StreamRecord<Long> element) throws Exception {
	elCount++;
	if (element.getValue() * 2 != element.getTimestamp()) {
		throw new RuntimeException("Invalid timestamp: " + element);
	}
}
 
Example 18
Source File: CEPRescalingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void verifyPattern(Object outputObject, Event start, SubEvent middle, Event end) {
	assertTrue(outputObject instanceof StreamRecord);

	StreamRecord<?> resultRecord = (StreamRecord<?>) outputObject;
	assertTrue(resultRecord.getValue() instanceof Map);

	@SuppressWarnings("unchecked")
	Map<String, List<Event>> patternMap = (Map<String, List<Event>>) resultRecord.getValue();
	assertEquals(start, patternMap.get("start").get(0));
	assertEquals(middle, patternMap.get("middle").get(0));
	assertEquals(end, patternMap.get("end").get(0));
}
 
Example 19
Source File: AddRouteOperator.java    From flink-siddhi with Apache License 2.0 4 votes vote down vote up
@Override
public void processElement(StreamRecord<Tuple2<StreamRoute, Object>> element) throws Exception {
    StreamRoute streamRoute = element.getValue().f0;
    Object value = element.getValue().f1;
    if (value instanceof ControlEvent) {
        streamRoute.setBroadCastPartitioning(true);
        if (value instanceof OperationControlEvent) {
            handleOperationControlEvent((OperationControlEvent)value);
        } else if (value instanceof MetadataControlEvent) {
            handleMetadataControlEvent((MetadataControlEvent)value);
        }

        output.collect(element);
    } else {
        String inputStreamId = streamRoute.getInputStreamId();
        if (!inputStreamToExecutionPlans.containsKey(inputStreamId)) {
            return;
        }

        for (String executionPlanId : inputStreamToExecutionPlans.get(inputStreamId)) {
            if (!executionPlanEnabled.get(executionPlanId)) {
                continue;
            }

            streamRoute.getExecutionPlanIds().clear();

            List<String> partitionKeys = executionPlanIdToPartitionKeys.get(executionPlanId);
            SiddhiStreamSchema<Object> schema = (SiddhiStreamSchema<Object>)dataStreamSchemas.get(inputStreamId);
            String[] fieldNames = schema.getFieldNames();
            Object[] row = schema.getStreamSerializer().getRow(value);
            streamRoute.setPartitionKey(-1);
            for (String partitionKey : partitionKeys) {
                long partitionValue = 0;
                for (int i = 0; i < fieldNames.length; ++i) {
                    if (partitionKey.equals(fieldNames[i])) {
                        partitionValue += row[i].hashCode();
                    }
                }
                streamRoute.setPartitionKey(Math.abs(partitionValue));
            }

            streamRoute.addExecutionPlanId(executionPlanId);
            output.collect(element);
        }
    }
}
 
Example 20
Source File: EventTimeInputBuilder.java    From flink-spector with Apache License 2.0 4 votes vote down vote up
private StreamRecord<T> copyRecord(StreamRecord<T> record, Long timestamp) {
    return new StreamRecord<T>(record.getValue(), timestamp);
}