[ 
https://issues.apache.org/jira/browse/ARROW-1710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16262948#comment-16262948
 ] 

ASF GitHub Bot commented on ARROW-1710:
---------------------------------------

BryanCutler commented on a change in pull request #1341: [WIP] ARROW-1710: 
[Java] Remove Non-Nullable Vectors
URL: https://github.com/apache/arrow/pull/1341#discussion_r152630603
 
 

 ##########
 File path: java/vector/src/main/java/org/apache/arrow/vector/BitVector.java
 ##########
 @@ -18,342 +18,469 @@
 
 package org.apache.arrow.vector;
 
+import io.netty.buffer.ArrowBuf;
 import org.apache.arrow.memory.BufferAllocator;
-import org.apache.arrow.memory.BaseAllocator;
-import org.apache.arrow.memory.OutOfMemoryException;
+import org.apache.arrow.vector.complex.impl.BitReaderImpl;
 import org.apache.arrow.vector.complex.reader.FieldReader;
 import org.apache.arrow.vector.holders.BitHolder;
 import org.apache.arrow.vector.holders.NullableBitHolder;
-import org.apache.arrow.vector.schema.ArrowFieldNode;
-import org.apache.arrow.vector.types.Types.MinorType;
-import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.Types;
+import org.apache.arrow.vector.types.pojo.FieldType;
 import org.apache.arrow.vector.util.OversizedAllocationException;
 import org.apache.arrow.vector.util.TransferPair;
 
-import io.netty.buffer.ArrowBuf;
-
 /**
- * Bit implements a vector of bit-width values. Elements in the vector are 
accessed by position from the logical start
- * of the vector. The width of each element is 1 bit. The equivalent Java 
primitive is an int containing the value '0'
- * or '1'.
+ * BitVector implements a fixed width (1 bit) vector of
+ * boolean values which could be null. Each value in the vector corresponds
+ * to a single bit in the underlying data stream backing the vector.
  */
-public final class BitVector extends BaseDataValueVector implements 
FixedWidthVector {
-  static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(BitVector.class);
-
-  private final Accessor accessor = new Accessor();
-  private final Mutator mutator = new Mutator();
-
-  int valueCount;
-  private int allocationSizeInBytes = 
getSizeFromCount(INITIAL_VALUE_ALLOCATION);
-  private int allocationMonitor = 0;
+public class BitVector extends BaseFixedWidthVector {
+  private final FieldReader reader;
 
+  /**
+   * Instantiate a BitVector. This doesn't allocate any memory for
+   * the data in vector.
+   *
+   * @param name      name of the vector
+   * @param allocator allocator for memory management.
+   */
   public BitVector(String name, BufferAllocator allocator) {
-    super(name, allocator);
+    this(name, FieldType.nullable(Types.MinorType.BIT.getType()),
+            allocator);
   }
 
-  @Override
-  public void load(ArrowFieldNode fieldNode, ArrowBuf data) {
-    // When the vector is all nulls or all defined, the content of the buffer 
can be omitted
-    if (data.readableBytes() == 0 && fieldNode.getLength() != 0) {
-      int count = fieldNode.getLength();
-      allocateNew(count);
-      int n = getSizeFromCount(count);
-      if (fieldNode.getNullCount() == 0) {
-        // all defined
-        // create an all 1s buffer
-        // set full bytes
-        int fullBytesCount = count / 8;
-        for (int i = 0; i < fullBytesCount; ++i) {
-          this.data.setByte(i, 0xFF);
-        }
-        int remainder = count % 8;
-        // set remaining bits
-        if (remainder > 0) {
-          byte bitMask = (byte) (0xFFL >>> ((8 - remainder) & 7));
-          this.data.setByte(fullBytesCount, bitMask);
-        }
-      } else if (fieldNode.getNullCount() == fieldNode.getLength()) {
-        // all null
-        // create an all 0s buffer
-        zeroVector();
-      } else {
-        throw new IllegalArgumentException("The buffer can be empty only if 
there's no data or it's all null or all defined");
-      }
-      this.data.writerIndex(n);
-    } else {
-      super.load(fieldNode, data);
-    }
-    this.valueCount = fieldNode.getLength();
+  /**
+   * Instantiate a BitVector. This doesn't allocate any memory for
+   * the data in vector.
+   *
+   * @param name      name of the vector
+   * @param fieldType type of Field materialized by this vector
+   * @param allocator allocator for memory management.
+   */
+  public BitVector(String name, FieldType fieldType, BufferAllocator 
allocator) {
+    super(name, allocator, fieldType, (byte) 0);
+    reader = new BitReaderImpl(BitVector.this);
   }
 
+  /**
+   * Get a reader that supports reading values from this vector
+   *
+   * @return Field Reader for this vector
+   */
   @Override
-  public Field getField() {
-    throw new UnsupportedOperationException("internal vector");
+  public FieldReader getReader() {
+    return reader;
   }
 
+  /**
+   * Get minor type for this vector. The vector holds values belonging
+   * to a particular type.
+   *
+   * @return {@link org.apache.arrow.vector.types.Types.MinorType}
+   */
   @Override
-  public MinorType getMinorType() {
-    return MinorType.BIT;
+  public Types.MinorType getMinorType() {
 
 Review comment:
   Hmm, I think this must have been auto-corrected, let me check on it

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Java] Decide what to do with non-nullable vectors in new vector class 
> hierarchy 
> ---------------------------------------------------------------------------------
>
>                 Key: ARROW-1710
>                 URL: https://issues.apache.org/jira/browse/ARROW-1710
>             Project: Apache Arrow
>          Issue Type: Sub-task
>          Components: Java - Vectors
>            Reporter: Li Jin
>            Assignee: Bryan Cutler
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> So far the consensus seems to be remove all non-nullable vectors. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to