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/04/21 23:05:58 UTC

[ignite-3] 01/02: Minor refactoring.

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

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

commit 6f838eb89529c6a17ab109e59304971d5f625279
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Apr 21 23:24:06 2021 +0300

    Minor refactoring.
---
 .../org/apache/ignite/internal/schema/BinaryRow.java | 10 +++++-----
 .../apache/ignite/internal/schema/ByteBufferRow.java |  2 +-
 .../java/org/apache/ignite/internal/schema/Row.java  | 20 ++++++++++++++------
 .../apache/ignite/internal/schema/RowAssembler.java  | 17 ++++++++++-------
 4 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryRow.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryRow.java
index 577f50b..835b1d1 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryRow.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/BinaryRow.java
@@ -134,19 +134,19 @@ public interface BinaryRow {
      */
     final class RowFlags {
         /** Flag indicated is row has no value chunk. */
-        public static final int NO_VALUE = 1;
+        public static final int NO_VALUE_FLAG = 1;
 
         /** Flag indicates key chunk omits null map. */
-        public static final int NO_KEY_NULL_MAP = 1 << 1;
+        public static final int OMIT_KEY_NULL_MAP_FLAG = 1 << 1;
 
         /** Flag indicates value chunk omits null map. */
-        public static final int NO_VALUE_NULL_MAP = 1 << 2;
+        public static final int OMIT_VAL_NULL_MAP_FLAG = 1 << 2;
 
         /** Flag indicates key chunk omits varlen table. */
-        public static final int NO_VARLEN_KEY_COL = 1 << 3;
+        public static final int OMIT_KEY_VARTBL_FLAG = 1 << 3;
 
         /** Flag indicates value chunk omits varlen table. */
-        public static final int NO_VARLEN_VALUE_COL = 1 << 4;
+        public static final int OMIT_VAL_VARTBL_FLAG = 1 << 4;
 
         /** Stub. */
         private RowFlags() {
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/ByteBufferRow.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/ByteBufferRow.java
index 8b86bc7..a2ed1a5 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/ByteBufferRow.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/ByteBufferRow.java
@@ -57,7 +57,7 @@ public class ByteBufferRow implements BinaryRow {
     @Override public boolean hasValue() {
         short flags = readShort(FLAGS_FIELD_OFFSET);
 
-        return (flags & RowFlags.NO_VALUE) == 0;
+        return (flags & RowFlags.NO_VALUE_FLAG) == 0;
     }
 
     /** {@inheritDoc} */
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 b9cf9cd..e970f3d 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
@@ -25,7 +25,7 @@ import java.util.UUID;
 
 /**
  * Schema-aware row.
- *
+ * <p>
  * The class contains non-generic methods to read boxed and unboxed primitives based on the schema column types.
  * Any type conversions and coercions should be implemented outside the row by the key-value or query runtime.
  * When a non-boxed primitive is read from a null column value, it is converted to the primitive type default value.
@@ -38,6 +38,14 @@ public class Row implements BinaryRow {
     private final BinaryRow row;
 
     /**
+     * @param itemIdx Varlen table item index.
+     * @return Varlen item offset.
+     */
+    public static int varlenItemOffset(int itemIdx) {
+        return VARLEN_TABLE_SIZE_FIELD_SIZE + itemIdx * VARLEN_COLUMN_OFFSET_FIELD_SIZE;
+    }
+
+    /**
      * Constructor.
      *
      * @param schema Schema.
@@ -431,15 +439,15 @@ public class Row implements BinaryRow {
         idx -= cols.numberOfFixsizeColumns() + numNullsBefore;
         int vartableSize = readShort(vartableOffset(baseOff, cols));
 
-        int vartableOff = vartableOffset(baseOff, cols) + VARLEN_TABLE_SIZE_FIELD_SIZE;
+        int vartableOff = vartableOffset(baseOff, cols);
         // Offset of idx-th column is from base offset.
-        int resOff = readShort(vartableOff + VARLEN_COLUMN_OFFSET_FIELD_SIZE * idx);
+        int resOff = readShort(vartableOff + varlenItemOffset(idx));
 
         long len = idx == vartableSize - 1 ?
             // totalLength - columnStartOffset
             readInteger(baseOff) - resOff :
             // nextColumnStartOffset - columnStartOffset
-            readShort(vartableOff + VARLEN_COLUMN_OFFSET_FIELD_SIZE * (idx + 1)) - resOff;
+            readShort(vartableOff + varlenItemOffset(idx + 1)) - resOff;
 
         return (len << 32) | (resOff + baseOff);
     }
@@ -470,9 +478,9 @@ public class Row implements BinaryRow {
 
         off += cols.foldFixedLength(nullMapIdx, readByte(nullMapOff + nullMapIdx) | mask);
 
-        final int vartableOffset = vartableOffset(baseOff, cols);
+        int vartableOffset = vartableOffset(baseOff, cols);
 
-        int vartableLen = VARLEN_TABLE_SIZE_FIELD_SIZE + readShort(vartableOffset) * VARLEN_COLUMN_OFFSET_FIELD_SIZE;
+        int vartableLen = varlenItemOffset(readShort(vartableOffset));
 
         return vartableOffset + vartableLen + off;
     }
diff --git a/modules/schema/src/main/java/org/apache/ignite/internal/schema/RowAssembler.java b/modules/schema/src/main/java/org/apache/ignite/internal/schema/RowAssembler.java
index 1d589d5..e5b139e 100644
--- a/modules/schema/src/main/java/org/apache/ignite/internal/schema/RowAssembler.java
+++ b/modules/schema/src/main/java/org/apache/ignite/internal/schema/RowAssembler.java
@@ -24,6 +24,9 @@ import java.util.BitSet;
 import java.util.UUID;
 import org.apache.ignite.internal.schema.BinaryRow.RowFlags;
 
+import static org.apache.ignite.internal.schema.BinaryRow.VARLEN_COLUMN_OFFSET_FIELD_SIZE;
+import static org.apache.ignite.internal.schema.BinaryRow.VARLEN_TABLE_SIZE_FIELD_SIZE;
+
 /**
  * Utility class to build rows using column appending pattern. The external user of this class must consult
  * with the schema and provide the columns in strict internal column sort order during the row construction.
@@ -77,7 +80,7 @@ public class RowAssembler {
      * @return Total size of the varlen table.
      */
     public static int varlenTableSize(int nonNullVarlenCols) {
-        return nonNullVarlenCols * BinaryRow.VARLEN_COLUMN_OFFSET_FIELD_SIZE;
+        return VARLEN_TABLE_SIZE_FIELD_SIZE + nonNullVarlenCols * VARLEN_COLUMN_OFFSET_FIELD_SIZE;
     }
 
     /**
@@ -138,7 +141,7 @@ public class RowAssembler {
      */
     static int rowChunkSize(Columns cols, int nonNullVarlenCols, int nonNullVarlenSize) {
         int size = BinaryRow.CHUNK_LEN_FIELD_SIZE + cols.nullMapSize() +
-            BinaryRow.VARLEN_TABLE_SIZE_FIELD_SIZE + varlenTableSize(nonNullVarlenCols);
+            varlenTableSize(nonNullVarlenCols);
 
         for (int i = 0; i < cols.numberOfFixsizeColumns(); i++)
             size += cols.column(i).type().length();
@@ -350,7 +353,7 @@ public class RowAssembler {
             throw new AssemblyException("Key column missed: colIdx=" + curCol);
         else {
             if (curCol == 0)
-                flags |= RowFlags.NO_VALUE;
+                flags |= RowFlags.NO_VALUE_FLAG;
             else if (schema.valueColumns().length() != curCol)
                 throw new AssemblyException("Value column missed: colIdx=" + curCol);
         }
@@ -377,9 +380,9 @@ public class RowAssembler {
      * @param off Offset to write.
      */
     private void writeOffset(int tblEntryIdx, int off) {
-        assert (flags & (baseOff == BinaryRow.KEY_CHUNK_OFFSET ? RowFlags.NO_VARLEN_KEY_COL : RowFlags.NO_VARLEN_VALUE_COL)) == 0;
+        assert (flags & (baseOff == BinaryRow.KEY_CHUNK_OFFSET ? RowFlags.OMIT_KEY_VARTBL_FLAG : RowFlags.OMIT_VAL_VARTBL_FLAG)) == 0;
 
-        buf.putShort(varlenTblOff + BinaryRow.VARLEN_COLUMN_OFFSET_FIELD_SIZE * tblEntryIdx, (short)off);
+        buf.putShort(varlenTblOff + Row.varlenItemOffset(tblEntryIdx), (short)off);
     }
 
     /**
@@ -410,7 +413,7 @@ public class RowAssembler {
      * @param colIdx Column index.
      */
     private void setNull(int colIdx) {
-        assert (flags & (baseOff == BinaryRow.KEY_CHUNK_OFFSET ? RowFlags.NO_KEY_NULL_MAP : RowFlags.NO_VALUE_NULL_MAP)) == 0;
+        assert (flags & (baseOff == BinaryRow.KEY_CHUNK_OFFSET ? RowFlags.OMIT_KEY_NULL_MAP_FLAG : RowFlags.OMIT_VAL_NULL_MAP_FLAG)) == 0;
 
         int byteInMap = colIdx / 8;
         int bitInByte = colIdx % 8;
@@ -473,7 +476,7 @@ public class RowAssembler {
         curVarlenTblEntry = 0;
 
         nullMapOff = baseOff + BinaryRow.CHUNK_LEN_FIELD_SIZE;
-        varlenTblOff = nullMapOff + curCols.nullMapSize() + BinaryRow.VARLEN_TABLE_SIZE_FIELD_SIZE;
+        varlenTblOff = nullMapOff + curCols.nullMapSize();
 
         curOff = varlenTblOff + varlenTableSize(nonNullVarlenCols);
     }