Java Code Examples for org.apache.flink.core.memory.MemorySegment#putLongBigEndian()
The following examples show how to use
org.apache.flink.core.memory.MemorySegment#putLongBigEndian() .
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: LongComparator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public void putNormalizedKey(Long lValue, MemorySegment target, int offset, int numBytes) { long value = lValue.longValue() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes <= 0) { } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
Example 2
Source File: EnumComparator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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 3
Source File: DateComparator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
Example 4
Source File: IntComparator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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 5
Source File: NormalizedKeyUtil.java From flink with Apache License 2.0 | 6 votes |
public static void putUnsignedLongNormalizedKey(long value, MemorySegment target, int offset, int numBytes) { if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes > 0) { if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7 - i) << 3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } }
Example 6
Source File: EnumComparator.java From flink with Apache License 2.0 | 6 votes |
@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 7
Source File: DateComparator.java From flink with Apache License 2.0 | 6 votes |
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
Example 8
Source File: BoundedBlockingSubpartitionWriteReadTest.java From flink with Apache License 2.0 | 6 votes |
private static void writeLongs(BoundedBlockingSubpartition partition, long nums) throws IOException { final MemorySegment memory = MemorySegmentFactory.allocateUnpooledSegment(BUFFER_SIZE); long l = 0; while (nums > 0) { int pos = 0; for (; nums > 0 && pos <= memory.size() - 8; pos += 8) { memory.putLongBigEndian(pos, l++); nums--; } partition.add(new BufferConsumer(memory, (ignored) -> {}, pos, true)); // we need to flush after every buffer as long as the add() contract is that // buffer are immediately added and can be filled further after that (for low latency // streaming data exchanges) partition.flush(); } }
Example 9
Source File: NormalizedKeyUtil.java From flink with Apache License 2.0 | 6 votes |
public static void putUnsignedLongNormalizedKey(long value, MemorySegment target, int offset, int numBytes) { if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes > 0) { if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7 - i) << 3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } } }
Example 10
Source File: EnumComparator.java From flink with Apache License 2.0 | 6 votes |
@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 11
Source File: DateComparator.java From flink with Apache License 2.0 | 6 votes |
public static void putNormalizedKeyDate(Date record, MemorySegment target, int offset, int numBytes) { final long value = record.getTime() - Long.MIN_VALUE; // see IntValue for an explanation of the logic if (numBytes == 8) { // default case, full normalized key target.putLongBigEndian(offset, value); } else if (numBytes < 8) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (value >>> ((7-i)<<3))); } } else { target.putLongBigEndian(offset, value); for (int i = 8; i < numBytes; i++) { target.put(offset + i, (byte) 0); } } }
Example 12
Source File: BoundedBlockingSubpartitionWriteReadTest.java From flink with Apache License 2.0 | 6 votes |
private static void writeLongs(BoundedBlockingSubpartition partition, long nums) throws IOException { final MemorySegment memory = MemorySegmentFactory.allocateUnpooledSegment(BUFFER_SIZE); long l = 0; while (nums > 0) { int pos = 0; for (; nums > 0 && pos <= memory.size() - 8; pos += 8) { memory.putLongBigEndian(pos, l++); nums--; } partition.add(new BufferConsumer(memory, (ignored) -> {}, pos, Buffer.DataType.DATA_BUFFER)); // we need to flush after every buffer as long as the add() contract is that // buffer are immediately added and can be filled further after that (for low latency // streaming data exchanges) partition.flush(); } }
Example 13
Source File: InstantComparator.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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 14
Source File: InstantComparator.java From flink with Apache License 2.0 | 5 votes |
@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: InstantComparator.java From flink with Apache License 2.0 | 5 votes |
@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))); } } }