[ https://issues.apache.org/jira/browse/ARROW-1476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16253553#comment-16253553 ]
ASF GitHub Bot commented on ARROW-1476: --------------------------------------- icexelloss commented on a change in pull request #1316: ARROW-1476: [JAVA] Implement Final ValueVector Updates URL: https://github.com/apache/arrow/pull/1316#discussion_r151147307 ########## File path: java/vector/src/main/java/org/apache/arrow/vector/file/json/JsonFileReader.java ########## @@ -218,16 +190,310 @@ public VectorSchemaRoot read() throws IOException { } } - /** - * TODO: A better way of implementing this function is to use `loadFieldBuffers` methods in - * FieldVector to set the inner-vector data as done in `ArrowFileReader`. - */ - private void readVector(Field field, FieldVector vector) throws JsonParseException, IOException { - List<ArrowVectorType> vectorTypes = field.getTypeLayout().getVectorTypes(); - List<BufferBacked> fieldInnerVectors = vector.getFieldInnerVectors(); - if (vectorTypes.size() != fieldInnerVectors.size()) { - throw new IllegalArgumentException("vector types and inner vectors are not the same size: " + vectorTypes.size() + " != " + fieldInnerVectors.size()); + private abstract class BufferReader { + abstract protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException; + + ArrowBuf readBuffer(BufferAllocator allocator, int count) throws IOException { + readToken(START_ARRAY); + ArrowBuf buf = read(allocator, count); + readToken(END_ARRAY); + return buf; } + } + + private class BufferHelper { + BufferReader BIT = new BufferReader() { + @Override + protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException { + final int bufferSize = BitVectorHelper.getValidityBufferSize(count); + ArrowBuf buf = allocator.buffer(bufferSize); + + // C++ integration test fails without this. + buf.setZero(0, bufferSize); + + for (int i = 0; i < count; i++) { + parser.nextToken(); + BitVectorHelper.setValidityBit(buf, i, parser.readValueAs(Boolean.class) ? 1 : 0); + } + + buf.writerIndex(bufferSize); + return buf; + } + }; + + BufferReader INT1 = new BufferReader() { + @Override + protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException { + final int size = count * NullableTinyIntVector.TYPE_WIDTH; + ArrowBuf buf = allocator.buffer(size); + + for (int i = 0; i < count; i++) { + parser.nextToken(); + buf.writeByte(parser.getByteValue()); + } + + buf.writerIndex(size); Review comment: Do we need this? `buf.writeByte` seems to update writerIndex already. ---------------------------------------------------------------- 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] Implement final ValueVector updates > ------------------------------------------ > > Key: ARROW-1476 > URL: https://issues.apache.org/jira/browse/ARROW-1476 > Project: Apache Arrow > Issue Type: Sub-task > Reporter: Jacques Nadeau > Assignee: Siddharth Teotia > Labels: pull-request-available > -- This message was sent by Atlassian JIRA (v6.4.14#64029)