richardstartin commented on code in PR #10044:
URL: https://github.com/apache/pinot/pull/10044#discussion_r1061263198


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/util/ValueReaderComparisons.java:
##########
@@ -0,0 +1,174 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.segment.local.io.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+
+public class ValueReaderComparisons {
+
+    private ValueReaderComparisons() {
+    }
+
+    private static int mismatch(PinotDataBuffer dataBuffer, long startOffset, 
int length, ByteBuffer buffer) {
+        boolean littleEndian = dataBuffer.order() == ByteOrder.LITTLE_ENDIAN;
+        if (littleEndian) {
+            buffer.order(ByteOrder.LITTLE_ENDIAN);
+        }
+        int limit = Math.min(length, buffer.limit());
+        int loopBound = limit & ~0x3F;
+        int i = 0;
+        for (; i < loopBound; i += 8) {
+            long ours = dataBuffer.getLong(startOffset + i);
+            long theirs = buffer.getLong(i);
+            if (ours != theirs) {
+                long difference = ours ^ theirs;
+                return i + ((littleEndian
+                        ? Long.numberOfTrailingZeros(difference)
+                        : Long.numberOfLeadingZeros(difference)) >>> 3);
+            }
+        }
+        for (; i < limit; i++) {
+            byte ours = dataBuffer.getByte(startOffset + i);
+            byte theirs = buffer.get(i);
+            if (ours != theirs) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    static int compareUtf8Bytes(PinotDataBuffer dataBuffer, long startOffset, 
int length, boolean padded,
+                           byte[] bytes) {
+        // can use MethodHandles.byteArrayViewVarHandle here after dropping 
JDK8
+        ByteBuffer buffer = ByteBuffer.wrap(bytes);
+        int mismatchPosition = mismatch(dataBuffer, startOffset, length, 
buffer);
+        if (mismatchPosition == -1) {
+            // need to figure out whether the unpadded string is longer than 
the parameter or not
+            if (padded && bytes.length < length) {
+                if (bytes.length == 0) {

Review Comment:
   I thought so too, but there are pre-existing test cases for this, e.g. 
`LoaderTest.testPadding` so I added this logic to pass those tests.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to