korlov42 commented on code in PR #2728:
URL: https://github.com/apache/ignite-3/pull/2728#discussion_r1370149962
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryTuplePrefix.java:
##########
@@ -73,6 +97,102 @@ public static BinaryTuplePrefix fromBinaryTuple(BinaryTuple
tuple) {
return new BinaryTuplePrefix(tuple.elementCount(), prefixBuffer);
}
+ private static BinaryTuplePrefix expandTuple(int size, BinaryTuple tuple) {
+ assert size > tuple.elementCount();
+
+ var stats = new Sink() {
+ int dataBeginOffset = 0;
+ int dataEndOffset = 0;
+
+ @Override
+ public void nextElement(int index, int begin, int end) {
+ if (index == 0) {
+ dataBeginOffset = begin;
+ }
+
+ dataEndOffset = end;
+ }
+ };
+
+ tuple.parse(stats);
+
+ ByteBuffer tupleBuffer = tuple.byteBuffer();
+
+ byte flags = tupleBuffer.get(0);
+ int entrySize = BinaryTupleCommon.flagsToEntrySize(flags);
+
+ ByteBuffer prefixBuffer = ByteBuffer.allocate(
+ tupleBuffer.remaining()
+ + (entrySize * (size - tuple.elementCount()))
+ + Integer.BYTES)
+ .order(ORDER)
+ .put(tupleBuffer.slice().limit(stats.dataBeginOffset)); //
header
+
+ int payloadEndPosition = stats.dataEndOffset - stats.dataBeginOffset;
+ for (int idx = tuple.elementCount(); idx < size; idx++) {
+ switch (entrySize) {
+ case Byte.BYTES:
+ prefixBuffer.put((byte) payloadEndPosition);
+ break;
+ case Short.BYTES:
+ prefixBuffer.putShort((short) payloadEndPosition);
+ break;
+ case Integer.BYTES:
+ prefixBuffer.putInt(payloadEndPosition);
+ break;
+ default:
+ assert false;
+ }
+ }
+
+ prefixBuffer
+
.put(tupleBuffer.slice().position(stats.dataBeginOffset).limit(stats.dataEndOffset))
// payload
+ .putInt(tuple.elementCount())
+ .flip();
+
+ prefixBuffer.put(0, (byte) (flags | PREFIX_FLAG));
+
+ return new BinaryTuplePrefix(size, prefixBuffer);
+ }
+
+ private static BinaryTuplePrefix truncateTuple(int size, BinaryTuple
tuple) {
+ assert size < tuple.elementCount();
+
+ var stats = new Sink() {
+ int dataBeginOffset = 0;
+ int dataEndOffset = 0;
+
+ @Override
+ public void nextElement(int index, int begin, int end) {
+ if (index == 0) {
+ dataBeginOffset = begin;
+ }
+
+ if (index < size) {
+ dataEndOffset = end;
+ }
+ }
+ };
+
+ tuple.parse(stats);
Review Comment:
> A more straightforward API can be both faster and easier to use
I agree with this, but not sure how such API may look like. Primary cases I
interested in are `entireTuple` and `expandTuple`. I think, former is already
good enough. But how to handle `expandTuple`? We basically need to have an
ability to append arbitrary amount of null elements to the existing tuple.
Beside, we have to reserve additional 4 bytes to append actual number of
elements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]