liyafan82 commented on a change in pull request #6912: URL: https://github.com/apache/arrow/pull/6912#discussion_r416559338
########## File path: java/vector/src/main/java/org/apache/arrow/vector/util/ValueVectorUtility.java ########## @@ -82,4 +89,43 @@ public static String getToString(ValueVector vector, int start, int end) { return sb.toString(); } + + /** + * Validate field vector. + */ + public static void validate(FieldVector vector) { + Preconditions.checkNotNull(vector); + + ArrowType arrowType = vector.getField().getType(); + int typeBufferCount = TypeLayout.getTypeBufferCount(arrowType); + TypeLayout typeLayout = TypeLayout.getTypeLayout(arrowType); + + if (vector.getValueCount() < 0) { + throw new RuntimeException("vector valueCount is negative"); + } + + if (vector.getFieldBuffers().size() != typeBufferCount) { + throw new RuntimeException(String.format("Expected %s buffers in vector of type %s, got %s", + typeBufferCount, vector.getField().getType().toString(), vector.getBufferSize())); + } + + for (int i = 0; i < typeBufferCount; i++) { + ArrowBuf buffer = vector.getFieldBuffers().get(i); + BufferLayout bufferLayout = typeLayout.getBufferLayouts().get(i); + if (buffer == null) { + continue; + } + int minBufferSize = vector.getValueCount() * bufferLayout.getTypeBitWidth(); + + if (buffer.capacity() < minBufferSize / 8) { Review comment: for offset buffers, we need to have: int minBufferSize = (vector.getValueCount() + 1) * bufferLayout.getTypeBitWidth(); ---------------------------------------------------------------- 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: us...@infra.apache.org