sashapolo commented on code in PR #2728:
URL: https://github.com/apache/ignite-3/pull/2728#discussion_r1370114023


##########
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:
   About new API: I meant this not only in terms of performance but also in 
terms of readability. Using `fetch` to find the boundaries of a subarray looks 
like a battle against the current API. A more straightforward API can be both 
faster and easier to use



-- 
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]

Reply via email to