Java Code Examples for org.apache.flink.core.memory.MemorySegment#putIntBigEndian()

The following examples show how to use org.apache.flink.core.memory.MemorySegment#putIntBigEndian() . 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: EnumComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(T iValue, MemorySegment target, int offset, int numBytes) {
	int value = iValue.ordinal() - Integer.MIN_VALUE;
	
	// see IntValue for an explanation of the logic
	if (numBytes == 4) {
		// default case, full normalized key
		target.putIntBigEndian(offset, value);
	}
	else if (numBytes <= 0) {
	}
	else if (numBytes < 4) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (value >>> ((3-i)<<3)));
		}
	}
	else {
		target.putLongBigEndian(offset, value);
		for (int i = 4; i < numBytes; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 2
Source File: TestData.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntPair record, MemorySegment target, int offset, int len) {
	// see IntValue for a documentation of the logic
	final int value = record.getKey() - Integer.MIN_VALUE;

	if (len == 4) {
		target.putIntBigEndian(offset, value);
	} else if (len <= 0) {
	} else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3 - i) << 3)) & 0xff));
		}
	} else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 3
Source File: EnumComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(T iValue, MemorySegment target, int offset, int numBytes) {
	int value = iValue.ordinal() - Integer.MIN_VALUE;
	
	// see IntValue for an explanation of the logic
	if (numBytes == 4) {
		// default case, full normalized key
		target.putIntBigEndian(offset, value);
	}
	else if (numBytes <= 0) {
	}
	else if (numBytes < 4) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (value >>> ((3-i)<<3)));
		}
	}
	else {
		target.putLongBigEndian(offset, value);
		for (int i = 4; i < numBytes; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 4
Source File: IntPairComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntPair record, MemorySegment target, int offset, int len) {
	// see IntValue for a documentation of the logic
	final int value = record.getKey() - Integer.MIN_VALUE;
	
	if (len == 4) {
		target.putIntBigEndian(offset, value);
	}
	else if (len <= 0) {
	}
	else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff));
		}
	}
	else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 5
Source File: IntListComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntList record, MemorySegment target, int offset, int len) {
	final int value = record.getKey() - Integer.MIN_VALUE;
	
	if (len == 4) {
		target.putIntBigEndian(offset, value);
	}
	else if (len <= 0) {
	}
	else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff));
		}
	}
	else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 6
Source File: IntPairComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntPair record, MemorySegment target, int offset, int len) {
	// see IntValue for a documentation of the logic
	final int value = record.getKey() - Integer.MIN_VALUE;
	
	if (len == 4) {
		target.putIntBigEndian(offset, value);
	}
	else if (len <= 0) {
	}
	else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff));
		}
	}
	else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 7
Source File: TestData.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntPair record, MemorySegment target, int offset, int len) {
	// see IntValue for a documentation of the logic
	final int value = record.getKey() - Integer.MIN_VALUE;

	if (len == 4) {
		target.putIntBigEndian(offset, value);
	} else if (len <= 0) {
	} else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3 - i) << 3)) & 0xff));
		}
	} else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 8
Source File: EnumComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(T iValue, MemorySegment target, int offset, int numBytes) {
	int value = iValue.ordinal() - Integer.MIN_VALUE;
	
	// see IntValue for an explanation of the logic
	if (numBytes == 4) {
		// default case, full normalized key
		target.putIntBigEndian(offset, value);
	}
	else if (numBytes <= 0) {
	}
	else if (numBytes < 4) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (value >>> ((3-i)<<3)));
		}
	}
	else {
		target.putLongBigEndian(offset, value);
		for (int i = 4; i < numBytes; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 9
Source File: NormalizedKeyUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public static void putUnsignedIntegerNormalizedKey(int value, MemorySegment target, int offset, int numBytes) {
	if (numBytes == 4) {
		// default case, full normalized key
		target.putIntBigEndian(offset, value);
	} else if (numBytes > 0) {
		if (numBytes < 4) {
			for (int i = 0; numBytes > 0; numBytes--, i++) {
				target.put(offset + i, (byte) (value >>> ((3 - i) << 3)));
			}
		} else {
			target.putIntBigEndian(offset, value);
			for (int i = 4; i < numBytes; i++) {
				target.put(offset + i, (byte) 0);
			}
		}
	}
}
 
Example 10
Source File: IntListComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntList record, MemorySegment target, int offset, int len) {
	final int value = record.getKey() - Integer.MIN_VALUE;
	
	if (len == 4) {
		target.putIntBigEndian(offset, value);
	}
	else if (len <= 0) {
	}
	else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff));
		}
	}
	else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 11
Source File: IntListComparator.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntList record, MemorySegment target, int offset, int len) {
	final int value = record.getKey() - Integer.MIN_VALUE;
	
	if (len == 4) {
		target.putIntBigEndian(offset, value);
	}
	else if (len <= 0) {
	}
	else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3-i)<<3)) & 0xff));
		}
	}
	else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 12
Source File: TestData.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(IntPair record, MemorySegment target, int offset, int len) {
	// see IntValue for a documentation of the logic
	final int value = record.getKey() - Integer.MIN_VALUE;

	if (len == 4) {
		target.putIntBigEndian(offset, value);
	} else if (len <= 0) {
	} else if (len < 4) {
		for (int i = 0; len > 0; len--, i++) {
			target.put(offset + i, (byte) ((value >>> ((3 - i) << 3)) & 0xff));
		}
	} else {
		target.putIntBigEndian(offset, value);
		for (int i = 4; i < len; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 13
Source File: IntComparator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void putNormalizedKey(Integer iValue, MemorySegment target, int offset, int numBytes) {
	int value = iValue.intValue() - Integer.MIN_VALUE;
	
	// see IntValue for an explanation of the logic
	if (numBytes == 4) {
		// default case, full normalized key
		target.putIntBigEndian(offset, value);
	}
	else if (numBytes <= 0) {
	}
	else if (numBytes < 4) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (value >>> ((3-i)<<3)));
		}
	}
	else {
		target.putLongBigEndian(offset, value);
		for (int i = 4; i < numBytes; i++) {
			target.put(offset + i, (byte) 0);
		}
	}
}
 
Example 14
Source File: InstantComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void putNormalizedKey(Instant record, MemorySegment target, int offset, int numBytes) {
	final int secondsBytes = InstantSerializer.SECONDS_BYTES;
	final long normalizedSeconds = record.getEpochSecond() - SECONDS_MIN_VALUE;
	if (numBytes >= secondsBytes) {
		target.putLongBigEndian(offset, normalizedSeconds);
		offset += secondsBytes;
		numBytes -= secondsBytes;

		final int nanosBytes = InstantSerializer.NANOS_BYTES;
		if (numBytes >= nanosBytes) {
			target.putIntBigEndian(offset, record.getNano());
			offset += nanosBytes;
			numBytes -= nanosBytes;
			for (int i = 0; i < numBytes; i++) {
				target.put(offset + i, (byte) 0);
			}
		} else {
			final int nanos = record.getNano();
			for (int i = 0; i < numBytes;  i++) {
				target.put(offset + i, (byte) (nanos >>> ((3 - i) << 3)));
			}
		}
	} else {
		for (int i = 0; i < numBytes; i++) {
			target.put(offset + i, (byte) (normalizedSeconds >>> ((7 - i) << 3)));
		}
	}
}
 
Example 15
Source File: LocalDateComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void putNormalizedKeyLocalDate(LocalDate record, MemorySegment target, int offset, int numBytes) {
	int year = record.getYear();
	int unsignedYear = year - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedYear);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedYear >>> ((3 - i) << 3)));
		}
		return;
	}

	int month = record.getMonthValue();
	if (numBytes > 0) {
		target.put(offset, (byte) (month & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int day = record.getDayOfMonth();
	if (numBytes > 0) {
		target.put(offset, (byte) (day & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
Example 16
Source File: LocalTimeComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void putNormalizedKeyLocalTime(LocalTime record, MemorySegment target, int offset, int numBytes) {
	int hour = record.getHour();
	if (numBytes > 0) {
		target.put(offset, (byte) (hour & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int minute = record.getMinute();
	if (numBytes > 0) {
		target.put(offset, (byte) (minute & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int second = record.getSecond();
	if (numBytes > 0) {
		target.put(offset, (byte) (second & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int nano = record.getNano();
	int unsignedNano = nano - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedNano);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedNano >>> ((3 - i) << 3)));
		}
		return;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
Example 17
Source File: InstantComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void putNormalizedKey(Instant record, MemorySegment target, int offset, int numBytes) {
	final int secondsBytes = InstantSerializer.SECONDS_BYTES;
	final long normalizedSeconds = record.getEpochSecond() - SECONDS_MIN_VALUE;
	if (numBytes >= secondsBytes) {
		target.putLongBigEndian(offset, normalizedSeconds);
		offset += secondsBytes;
		numBytes -= secondsBytes;

		final int nanosBytes = InstantSerializer.NANOS_BYTES;
		if (numBytes >= nanosBytes) {
			target.putIntBigEndian(offset, record.getNano());
			offset += nanosBytes;
			numBytes -= nanosBytes;
			for (int i = 0; i < numBytes; i++) {
				target.put(offset + i, (byte) 0);
			}
		} else {
			final int nanos = record.getNano();
			for (int i = 0; i < numBytes;  i++) {
				target.put(offset + i, (byte) (nanos >>> ((3 - i) << 3)));
			}
		}
	} else {
		for (int i = 0; i < numBytes; i++) {
			target.put(offset + i, (byte) (normalizedSeconds >>> ((7 - i) << 3)));
		}
	}
}
 
Example 18
Source File: LocalDateComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void putNormalizedKeyLocalDate(LocalDate record, MemorySegment target, int offset, int numBytes) {
	int year = record.getYear();
	int unsignedYear = year - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedYear);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedYear >>> ((3 - i) << 3)));
		}
		return;
	}

	int month = record.getMonthValue();
	if (numBytes > 0) {
		target.put(offset, (byte) (month & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int day = record.getDayOfMonth();
	if (numBytes > 0) {
		target.put(offset, (byte) (day & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
Example 19
Source File: LocalTimeComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
public static void putNormalizedKeyLocalTime(LocalTime record, MemorySegment target, int offset, int numBytes) {
	int hour = record.getHour();
	if (numBytes > 0) {
		target.put(offset, (byte) (hour & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int minute = record.getMinute();
	if (numBytes > 0) {
		target.put(offset, (byte) (minute & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int second = record.getSecond();
	if (numBytes > 0) {
		target.put(offset, (byte) (second & 0xff - Byte.MIN_VALUE));
		numBytes -= 1;
		offset += 1;
	}

	int nano = record.getNano();
	int unsignedNano = nano - Integer.MIN_VALUE;
	if (numBytes >= 4) {
		target.putIntBigEndian(offset, unsignedNano);
		numBytes -= 4;
		offset += 4;
	} else if (numBytes > 0) {
		for (int i = 0; numBytes > 0; numBytes--, i++) {
			target.put(offset + i, (byte) (unsignedNano >>> ((3 - i) << 3)));
		}
		return;
	}

	for (int i = 0; i < numBytes; i++) {
		target.put(offset + i, (byte) 0);
	}
}
 
Example 20
Source File: InstantComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void putNormalizedKey(Instant record, MemorySegment target, int offset, int numBytes) {
	final int secondsBytes = InstantSerializer.SECONDS_BYTES;
	final long normalizedSeconds = record.getEpochSecond() - SECONDS_MIN_VALUE;
	if (numBytes >= secondsBytes) {
		target.putLongBigEndian(offset, normalizedSeconds);
		offset += secondsBytes;
		numBytes -= secondsBytes;

		final int nanosBytes = InstantSerializer.NANOS_BYTES;
		if (numBytes >= nanosBytes) {
			target.putIntBigEndian(offset, record.getNano());
			offset += nanosBytes;
			numBytes -= nanosBytes;
			for (int i = 0; i < numBytes; i++) {
				target.put(offset + i, (byte) 0);
			}
		} else {
			final int nanos = record.getNano();
			for (int i = 0; i < numBytes;  i++) {
				target.put(offset + i, (byte) (nanos >>> ((3 - i) << 3)));
			}
		}
	} else {
		for (int i = 0; i < numBytes; i++) {
			target.put(offset + i, (byte) (normalizedSeconds >>> ((7 - i) << 3)));
		}
	}
}