Java Code Examples for org.apache.flink.types.IntValue#setValue()

The following examples show how to use org.apache.flink.types.IntValue#setValue() . 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: ChainedAllReduceDriverTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Record reduce(Record value1, Record value2) throws Exception {
	IntValue v1 = value1.getField(0, IntValue.class);
	IntValue v2 = value2.getField(0, IntValue.class);

	// set value and force update of record; this updates and returns
	// value1 in order to test ChainedAllReduceDriver.collect() when
	// object reuse is enabled
	v1.setValue(v1.getValue() + v2.getValue());
	value1.setField(0, v1);
	value1.updateBinaryRepresenation();
	return value1;
}
 
Example 2
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Record reduce(Record value1, Record value2) throws Exception {
	IntValue v1 = value1.getField(0, IntValue.class);
	IntValue v2 = value2.getField(0, IntValue.class);

	// set value and force update of record; this updates and returns
	// value1 in order to test ChainedAllReduceDriver.collect() when
	// object reuse is enabled
	v1.setValue(v1.getValue() + v2.getValue());
	value1.setField(0, v1);
	value1.updateBinaryRepresenation();
	return value1;
}
 
Example 3
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Record reduce(Record value1, Record value2) throws Exception {
	IntValue v1 = value1.getField(0, IntValue.class);
	IntValue v2 = value2.getField(0, IntValue.class);

	// set value and force update of record; this updates and returns
	// value1 in order to test ChainedAllReduceDriver.collect() when
	// object reuse is enabled
	v1.setValue(v1.getValue() + v2.getValue());
	value1.setField(0, v1);
	value1.updateBinaryRepresenation();
	return value1;
}
 
Example 4
Source File: IntValueSerializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public IntValue copy(IntValue from, IntValue reuse) {
	reuse.setValue(from.getValue());
	return reuse;
}
 
Example 5
Source File: IntValueParser.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, IntValue reusable) {

	if (startPos == limit) {
		setErrorState(ParseErrorState.EMPTY_COLUMN);
		return -1;
	}

	long val = 0;
	boolean neg = false;

	final int delimLimit = limit - delimiter.length + 1;

	this.result = reusable;

	if (bytes[startPos] == '-') {
		neg = true;
		startPos++;
		
		// check for empty field with only the sign
		if (startPos == limit || (startPos < delimLimit && delimiterNext(bytes, startPos, delimiter))) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ORPHAN_SIGN);
			return -1;
		}
	}
	
	for (int i = startPos; i < limit; i++) {
		if (i < delimLimit && delimiterNext(bytes, i, delimiter)) {
			if (i == startPos) {
				setErrorState(ParseErrorState.EMPTY_COLUMN);
				return -1;
			}
			reusable.setValue((int) (neg ? -val : val));
			return i + delimiter.length;
		}
		if (bytes[i] < 48 || bytes[i] > 57) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
			return -1;
		}
		val *= 10;
		val += bytes[i] - 48;
		
		if (val > OVERFLOW_BOUND && (!neg || val > UNDERFLOW_BOUND)) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
			return -1;
		}
	}

	reusable.setValue((int) (neg ? -val : val));
	return limit;
}
 
Example 6
Source File: IntValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public IntValue copy(IntValue from, IntValue reuse) {
	reuse.setValue(from.getValue());
	return reuse;
}
 
Example 7
Source File: IntValueParser.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, IntValue reusable) {

	if (startPos == limit) {
		setErrorState(ParseErrorState.EMPTY_COLUMN);
		return -1;
	}

	long val = 0;
	boolean neg = false;

	final int delimLimit = limit - delimiter.length + 1;

	this.result = reusable;

	if (bytes[startPos] == '-') {
		neg = true;
		startPos++;
		
		// check for empty field with only the sign
		if (startPos == limit || (startPos < delimLimit && delimiterNext(bytes, startPos, delimiter))) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ORPHAN_SIGN);
			return -1;
		}
	}
	
	for (int i = startPos; i < limit; i++) {
		if (i < delimLimit && delimiterNext(bytes, i, delimiter)) {
			if (i == startPos) {
				setErrorState(ParseErrorState.EMPTY_COLUMN);
				return -1;
			}
			reusable.setValue((int) (neg ? -val : val));
			return i + delimiter.length;
		}
		if (bytes[i] < 48 || bytes[i] > 57) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
			return -1;
		}
		val *= 10;
		val += bytes[i] - 48;
		
		if (val > OVERFLOW_BOUND && (!neg || val > UNDERFLOW_BOUND)) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
			return -1;
		}
	}

	reusable.setValue((int) (neg ? -val : val));
	return limit;
}
 
Example 8
Source File: IntValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public IntValue copy(IntValue from, IntValue reuse) {
	reuse.setValue(from.getValue());
	return reuse;
}
 
Example 9
Source File: IntValueParser.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, IntValue reusable) {

	if (startPos == limit) {
		setErrorState(ParseErrorState.EMPTY_COLUMN);
		return -1;
	}

	long val = 0;
	boolean neg = false;

	final int delimLimit = limit - delimiter.length + 1;

	this.result = reusable;

	if (bytes[startPos] == '-') {
		neg = true;
		startPos++;
		
		// check for empty field with only the sign
		if (startPos == limit || (startPos < delimLimit && delimiterNext(bytes, startPos, delimiter))) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ORPHAN_SIGN);
			return -1;
		}
	}
	
	for (int i = startPos; i < limit; i++) {
		if (i < delimLimit && delimiterNext(bytes, i, delimiter)) {
			if (i == startPos) {
				setErrorState(ParseErrorState.EMPTY_COLUMN);
				return -1;
			}
			reusable.setValue((int) (neg ? -val : val));
			return i + delimiter.length;
		}
		if (bytes[i] < 48 || bytes[i] > 57) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
			return -1;
		}
		val *= 10;
		val += bytes[i] - 48;
		
		if (val > OVERFLOW_BOUND && (!neg || val > UNDERFLOW_BOUND)) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
			return -1;
		}
	}

	reusable.setValue((int) (neg ? -val : val));
	return limit;
}