You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2021/05/21 13:47:33 UTC

[ignite-3] 02/02: Fix wrong offset calculation.

This is an automated email from the ASF dual-hosted git repository.

amashenkov pushed a commit to branch ignite-14759
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit c3905d2468dc034844f5557bdd1159cfa285c6ae
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Fri May 21 16:43:52 2021 +0300

    Fix wrong offset calculation.
---
 .../org/apache/ignite/internal/schema/Row.java     | 42 +++++++++++++---------
 .../org/apache/ignite/internal/schema/RowTest.java |  4 +--
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/Row.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/Row.java
index 9d967d3..bed6afc 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/Row.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/Row.java
@@ -492,33 +492,43 @@ public class Row implements BinaryRow {
      * @return Encoded offset (from the row start) of the requested fixlen column.
      */
     int fixlenColumnOffset(Columns cols, int baseOff, int idx, boolean hasVarTbl, boolean hasNullMap) {
-        int off = 0;
+        int colOff = 0;
 
         int payloadOff = baseOff + CHUNK_LEN_FIELD_SIZE;
 
-        if (hasNullMap) {
-            payloadOff += cols.nullMapSize();
-
-            int nullMapOff = nullMapOffset(baseOff);
-
-            int nullMapIdx = idx / 8;
-
-            // Fold offset based on the whole map bytes in the schema
-            for (int i = 0; i < nullMapIdx; i++)
-                off += cols.foldFixedLength(i, readByte(nullMapOff + i));
+        // Calculate fixlen column offset.
+        {
+            int colByteIdx = idx / 8;
 
             // Set bits starting from posInByte, inclusive, up to either the end of the byte or the last column index, inclusive
             int startBit = idx % 8;
-            int endBit = nullMapIdx == cols.nullMapSize() - 1 ? ((cols.numberOfFixsizeColumns() - 1) % 8) : 7;
+            int endBit = colByteIdx == (cols.length() + 7) / 8 - 1 ? ((cols.numberOfFixsizeColumns() - 1) % 8) : 7;
             int mask = (0xFF >> (7 - endBit)) & (0xFF << startBit);
 
-            off += cols.foldFixedLength(nullMapIdx, readByte(nullMapOff + nullMapIdx) | mask);
+            if (hasNullMap) {
+                payloadOff += cols.nullMapSize();
+
+                // Fold offset based on the whole map bytes in the schema
+                for (int i = 0; i < colByteIdx; i++)
+                    colOff += cols.foldFixedLength(i, readByte(nullMapOffset(baseOff) + i));
+
+                colOff += cols.foldFixedLength(colByteIdx, readByte(nullMapOffset(baseOff) + colByteIdx) | mask);
+            }
+            else {
+                for (int i = 0; i < colByteIdx; i++)
+                    colOff += cols.foldFixedLength(i, 0);
+
+                colOff += cols.foldFixedLength(colByteIdx,  mask);
+            }
         }
 
-        if (hasVarTbl)
-            payloadOff += varlenItemOffset(readShort(payloadOff));
+        if (hasVarTbl) {
+            short verlenItems = readShort(payloadOff);
+
+            payloadOff += varlenItemOffset(verlenItems);
+        }
 
-        return payloadOff + off;
+        return payloadOff + colOff;
     }
 
     /**
diff --git a/modules/schema/src/test/java/org/apache/ignite/internal/schema/RowTest.java b/modules/schema/src/test/java/org/apache/ignite/internal/schema/RowTest.java
index 08ef37f..659dd5f 100644
--- a/modules/schema/src/test/java/org/apache/ignite/internal/schema/RowTest.java
+++ b/modules/schema/src/test/java/org/apache/ignite/internal/schema/RowTest.java
@@ -251,7 +251,7 @@ public class RowTest {
     }
 
     /**
-     * Validates row values after serialization-deserialization.
+     * Validates row values after serialization-then-deserialization.
      *
      * @param schema Row schema.
      * @param vals Row values.
@@ -371,7 +371,7 @@ public class RowTest {
     }
 
     /**
-     * Suffle columns.
+     * Shuffle columns.
      */
     private void shuffle(Column[] cols) {
         Collections.shuffle(Arrays.asList(cols));