vldpyatkov commented on code in PR #5686: URL: https://github.com/apache/ignite-3/pull/5686#discussion_r2075960927
########## modules/schema/src/main/java/org/apache/ignite/internal/schema/PartialBinaryTupleMatcher.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.ignite.internal.schema; + +import static org.apache.ignite.internal.binarytuple.BinaryTupleCommon.PREFIX_FLAG; +import static org.apache.ignite.internal.schema.BinaryTupleComparatorUtils.compareAsString; +import static org.apache.ignite.internal.schema.BinaryTupleComparatorUtils.compareFieldValue; +import static org.apache.ignite.internal.schema.BinaryTupleComparatorUtils.equalityFlag; +import static org.apache.ignite.internal.schema.BinaryTupleComparatorUtils.isFlagSet; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.Arrays; +import java.util.List; +import org.apache.ignite.internal.binarytuple.BinaryTupleParser.Readability; +import org.apache.ignite.internal.binarytuple.BinaryTupleReader; +import org.apache.ignite.internal.catalog.descriptors.CatalogColumnCollation; +import org.apache.ignite.internal.type.NativeType; +import org.apache.ignite.internal.type.NativeTypeSpec; +import org.apache.ignite.internal.util.ByteUtils; + +/** + * Matcher for comparing {@link BinaryTuple}s on a per-column basis. + * + * <p>This comparator is used to compare BinaryTuples. The first tuple has to be an ordinal tuple that is gotten from persistent. + * The second tuple can be {@link BinaryTuplePrefix}. The mather assumes that the first tuple may have been written in the + * buffer partially. If the length of the tuple buffer is not enough to do a comparison, the comparator returns {@code 0}. + */ +@SuppressWarnings("ComparatorNotSerializable") +public class PartialBinaryTupleMatcher { + private final List<CatalogColumnCollation> columnCollations; + private final List<NativeType> columnTypes; + + /** + * Creates BinaryTuple comparator. + * + * @param columnCollations Columns collations. + * @param columnTypes Column types in order, which is defined in BinaryTuple schema. + */ + public PartialBinaryTupleMatcher( + List<CatalogColumnCollation> columnCollations, + List<NativeType> columnTypes + ) { + this.columnCollations = columnCollations; + this.columnTypes = columnTypes; + } + + /** + * Compares two binary tuples represented as ByteBuffers to determine their relative ordering. + * <p> + * The method takes into account tuple prefixes (the prefix writing structure is available for second buffer only), column types, and + * other configurations to compare the tuples up to the number of elements specified in the schema. If one of the tuples is a prefix, + * specific comparison rules leveraging the equality flag are applied. + * + * @param buffer1 The first ByteBuffer to compare must be in LITTLE_ENDIAN byte order. + * @param buffer2 The second ByteBuffer to compare must be in LITTLE_ENDIAN byte order and can contain a prefix {@see PREFIX_FLAG}. + * @return A positive integer if the first buffer is greater than the second one, zero if the first buffer equals the second one or its + * bytes are not enough to compare, and a negative integer in other cases. + */ + public int match(ByteBuffer buffer1, ByteBuffer buffer2) { + assert buffer1.order() == ByteOrder.LITTLE_ENDIAN; + assert buffer2.order() == ByteOrder.LITTLE_ENDIAN; + + boolean isBuffer1Prefix = isFlagSet(buffer1, PREFIX_FLAG); + boolean isBuffer2Prefix = isFlagSet(buffer2, PREFIX_FLAG); + + int numElements = columnTypes.size(); + + assert !isBuffer1Prefix : "An inline tuple must not contain a prefix."; Review Comment: The first tuple is gotten from persistent storage and cannot be in a prefix format. -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org