You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/04/09 16:15:52 UTC

[GitHub] [ignite-3] AMashenkov commented on a change in pull request #73: IGNITE-14330: Implement table binary views.

AMashenkov commented on a change in pull request #73:
URL: https://github.com/apache/ignite-3/pull/73#discussion_r610752303



##########
File path: modules/schema/src/main/java/org/apache/ignite/internal/schema/Row.java
##########
@@ -17,167 +17,217 @@
 
 package org.apache.ignite.internal.schema;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
 import java.util.BitSet;
 import java.util.UUID;
 
 /**
+ * Schema-aware row.
+ *
  * 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.
  */
-public abstract class Row {
-    /** */
-    public static final int SCHEMA_VERSION_OFFSET = 0;
-
-    /** */
-    public static final int FLAGS_FIELD_OFFSET = SCHEMA_VERSION_OFFSET + 2;
-
-    /** */
-    public static final int KEY_HASH_FIELD_OFFSET = FLAGS_FIELD_OFFSET + 2;
-
-    /** */
-    public static final int KEY_CHUNK_OFFSET = KEY_HASH_FIELD_OFFSET + 4;
-
-    /** */
-    public static final int TOTAL_LEN_FIELD_SIZE = 4;
-
-    /** */
-    public static final int VARLEN_TABLE_SIZE_FIELD_SIZE = 2;
-
-    /** */
-    public static final int VARLEN_COLUMN_OFFSET_FIELD_SIZE = 2;
+public class Row implements BinaryRow {
+    /** Schema descriptor. */
+    private final SchemaDescriptor schema;
 
-    /** */
-    public static final class RowFlags {
-        /** Tombstone flag. */
-        public static final int TOMBSTONE = 1;
+    /** Binary row. */
+    private final BinaryRow row;
 
-        /** Null-value flag. */
-        public static final int NULL_VALUE = 1 << 1;
+    /**
+     * Constructor.
+     *
+     * @param schema Schema.
+     * @param row Binary row representation.
+     */
+    public Row(SchemaDescriptor schema, BinaryRow row) {
+        assert row.schemaVersion() == schema.version();
 
-        /** Stub. */
-        private RowFlags() {
-        }
+        this.row = row;
+        this.schema = schema;
     }
 
-    /** Schema descriptor for which this row was created. */
-    private final SchemaDescriptor schema;
-
     /**
-     * @param schema Schema instance.
+     * @return Row schema.
      */
-    protected Row(SchemaDescriptor schema) {
-        this.schema = schema;
+    public SchemaDescriptor rowSchema() {
+        return schema;
     }
 
     /**
      * @return {@code True} if row has non-null value, {@code false} otherwise.
      */
-    public boolean hasValue() {
-        short flags = readShort(FLAGS_FIELD_OFFSET);
-
-        return (flags & (RowFlags.NULL_VALUE | RowFlags.TOMBSTONE)) == 0;
+    @Override public boolean hasValue() {
+        return row.hasValue();
     }
 
     /**
+     * Reads value for specified column.
+     *
+     * @param col Column index.
+     * @return Column value.
+     * @throws InvalidTypeException If actual column type does not match the requested column type.
      */
-    public byte byteValue(int col) {
+    public byte byteValue(int col) throws InvalidTypeException {
         long off = findColumn(col, NativeTypeSpec.BYTE);
 
         return off < 0 ? 0 : readByte(offset(off));
     }
 
     /**
+     * Reads value for specified column.
+     *
+     * @param col Column index.
+     * @return Column value.
+     * @throws InvalidTypeException If actual column type does not match the requested column type.
      */
-    public Byte byteValueBoxed(int col) {
+    public Byte byteValueBoxed(int col) throws InvalidTypeException {
         long off = findColumn(col, NativeTypeSpec.BYTE);
 
         return off < 0 ? null : readByte(offset(off));
     }
 
     /**
+     * Reads value for specified column.
+     *
+     * @param col Column index.
+     * @return Column value.
+     * @throws InvalidTypeException If actual column type does not match the requested column type.
      */
-    public short shortValue(int col) {
+    public short shortValue(int col) throws InvalidTypeException {
         long off = findColumn(col, NativeTypeSpec.SHORT);
 
         return off < 0 ? 0 : readShort(offset(off));
     }
 
     /**
+     * Reads value for specified column.
+     *
+     * @param col Column index.
+     * @return Column value.
+     * @throws InvalidTypeException If actual column type does not match the requested column type.
      */
-    public Short shortValueBoxed(int col) {
+    public Short shortValueBoxed(int col) throws InvalidTypeException {

Review comment:
       "shortValue()" can't return 'null' but column can be NULLABLE.
   But we can't leave "shortValueBoxed()" only to avoid unwanted boxing/unboxing in some scenarios.
   E.g. to read a value from Row and write it directly to user POJO via reflection/VahHandle.




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

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