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

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

icexelloss commented on a change in pull request #1492: ARROW-633/634: Add 
FixedSizeBinary support in Java and integration tests (Updated)
URL: https://github.com/apache/arrow/pull/1492#discussion_r162478060
 
 

 ##########
 File path: 
java/vector/src/main/java/org/apache/arrow/vector/FixedSizeBinaryVector.java
 ##########
 @@ -0,0 +1,401 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.arrow.vector;
+
+import io.netty.buffer.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.complex.impl.FixedSizeBinaryReaderImpl;
+import org.apache.arrow.vector.complex.reader.FieldReader;
+import org.apache.arrow.vector.holders.FixedSizeBinaryHolder;
+import org.apache.arrow.vector.holders.NullableFixedSizeBinaryHolder;
+import org.apache.arrow.vector.types.Types;
+import org.apache.arrow.vector.types.pojo.ArrowType.FixedSizeBinary;
+import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.util.TransferPair;
+
+
+/**
+ * FixedSizeBinaryVector implements a fixed width vector of
+ * binary values which could be null. A validity buffer (bit vector) is
+ * maintained to track which elements in the vector are null.
+ */
+public class FixedSizeBinaryVector extends BaseFixedWidthVector {
+  private final int byteWidth;
+  private final FieldReader reader;
+
+  /**
+   * Instantiate a FixedSizeBinaryVector. This doesn't allocate any memory for
+   * the data in vector.
+   *
+   * @param name      name of the vector
+   * @param allocator allocator for memory management.
+   * @param byteWidth byte width of the binary values
+   */
+  public FixedSizeBinaryVector(String name, BufferAllocator allocator, int 
byteWidth) {
+    this(name, FieldType.nullable(new FixedSizeBinary(byteWidth)), allocator);
+  }
+
+  /**
+   * Instantiate a FixedSizeBinaryVector. 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 FixedSizeBinaryVector(String name, FieldType fieldType, 
BufferAllocator allocator) {
+    super(name, allocator, fieldType, ((FixedSizeBinary) 
fieldType.getType()).getByteWidth());
+    reader = new FixedSizeBinaryReaderImpl(FixedSizeBinaryVector.this);
+    byteWidth = ((FixedSizeBinary) fieldType.getType()).getByteWidth();
+  }
+
+  /**
+   * Get a reader that supports reading values from this vector
+   *
+   * @return Field Reader for this vector
+   */
+  @Override
+  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 Types.MinorType getMinorType() {
+    return Types.MinorType.FIXEDSIZEBINARY;
+  }
+
+
+  /******************************************************************
+   *                                                                *
+   *          vector value retrieval methods                        *
+   *                                                                *
+   ******************************************************************/
+
+
+  /**
+   * Get the element at the given index from the vector.
+   *
+   * @param index position of element
+   * @return element at given index
+   */
+  public byte[] get(int index) {
+    if (isSet(index) == 0) {
+      throw new IllegalStateException("Value at index is null");
+    }
+    assert index >= 0;
+    final byte[] dst = new byte[byteWidth];
+    valueBuffer.getBytes(index * byteWidth, dst, 0, byteWidth);
+    return dst;
+  }
+
+  /**
+   * Get the element at the given index from the vector and
+   * sets the state in holder. If element at given index
+   * is null, holder.isSet will be zero.
+   *
+   * @param index position of element
+   * @param holder nullable holder to carry the buffer
+   */
+  public void get(int index, NullableFixedSizeBinaryHolder holder) {
+    if (isSet(index) == 0) {
+      holder.isSet = 0;
+      return;
+    }
+    holder.isSet = 1;
+    holder.buffer = valueBuffer.slice(index * byteWidth, byteWidth);
+  }
+
+  /**
+   * Same as {@link #get(int)}.
+   *
+   * @param index position of element
+   * @return element at given index
+   */
+  @Override
+  public byte[] getObject(int index) {
+    if (isSet(index) == 0) {
+      return null;
+    } else {
+      return get(index);
 
 Review comment:
   Unroll this function to avoid duplicate check?

----------------------------------------------------------------
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:
[email protected]


> [Java] Add support for FixedSizeBinary type
> -------------------------------------------
>
>                 Key: ARROW-633
>                 URL: https://issues.apache.org/jira/browse/ARROW-633
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: Java - Vectors
>            Reporter: Wes McKinney
>            Assignee: Jingyuan Wang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to