tkalkirill commented on code in PR #1179:
URL: https://github.com/apache/ignite-3/pull/1179#discussion_r991619972


##########
modules/storage-page-memory/src/main/java/org/apache/ignite/internal/storage/pagememory/index/InlineUtils.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.storage.pagememory.index;
+
+import static java.util.function.Predicate.not;
+import static 
org.apache.ignite.internal.pagememory.util.PartitionlessLinks.PARTITIONLESS_LINK_SIZE_BYTES;
+import static org.apache.ignite.internal.util.Constants.KiB;
+
+import java.util.List;
+import org.apache.ignite.internal.binarytuple.BinaryTupleCommon;
+import org.apache.ignite.internal.pagememory.tree.io.BplusInnerIo;
+import org.apache.ignite.internal.pagememory.tree.io.BplusLeafIo;
+import org.apache.ignite.internal.schema.BinaryTuple;
+import org.apache.ignite.internal.schema.NativeType;
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+import org.apache.ignite.internal.schema.VarlenNativeType;
+import org.apache.ignite.internal.storage.index.IndexDescriptor;
+import 
org.apache.ignite.internal.storage.index.IndexDescriptor.ColumnDescriptor;
+
+/**
+ * Helper class for index inlining.
+ */
+public class InlineUtils {
+    /** Maximum inline size for a {@link BinaryTuple}, in bytes. */
+    public static final int MAX_BINARY_TUPLE_INLINE_SIZE = 2 * KiB;
+
+    /**
+     * Calculates inline size for column.
+     *
+     * @param nativeType Column type.
+     * @param maxVarlenInlineSize Maximum inline size of variable length 
column in bytes.
+     * @return Inline size in bytes.
+     */
+    static int inlineSize(NativeType nativeType, int maxVarlenInlineSize) {
+        NativeTypeSpec spec = nativeType.spec();
+
+        if (spec.fixedLength()) {
+            return nativeType.sizeInBytes();
+        }
+
+        // Variable length columns.
+
+        switch (spec) {
+            case STRING:
+            case BYTES:
+                return Math.min(maxVarlenInlineSize, ((VarlenNativeType) 
nativeType).length());
+
+            case DECIMAL:
+                // It can be converted to float for greater or lesser 
comparisons.
+                return Float.BYTES;
+
+            case NUMBER:
+                // It can be converted to int for greater or lesser 
comparisons.
+                return Integer.BYTES;
+
+            default:
+                throw new IllegalArgumentException("Unknown type " + spec);
+        }
+    }
+
+    /**
+     * Calculates inline size for {@link BinaryTuple}, given its format.
+     *
+     * @param indexDescriptor Index descriptor.
+     * @param maxVarlenInlineSize Maximum inline size of variable length 
column in bytes.
+     * @return Inline size in bytes, not more than the {@link 
#MAX_BINARY_TUPLE_INLINE_SIZE}.
+     */
+    static int binaryTupleInlineSize(IndexDescriptor indexDescriptor, int 
maxVarlenInlineSize) {
+        List<? extends ColumnDescriptor> columns = indexDescriptor.columns();
+
+        boolean hasNullColumns = 
columns.stream().anyMatch(ColumnDescriptor::nullable);
+
+        // 2-byte size class covers most cases.
+        int sizeClass = 2;
+
+        if (columns.stream().allMatch(c -> c.type().spec().fixedLength())) {
+            int totalFixedColumnSize = columns.stream().mapToInt(c -> 
c.type().sizeInBytes()).sum();

Review Comment:
   fix it



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

Reply via email to