/** * Get child vectors. * @return a sequence of underlying child vectors. */ protected List<FieldVector> getChildren() { int size = vectors.size(); List<FieldVector> children = new ArrayList<>(); for (int i = 0; i < size; i++) { children.add(vectors.getByOrdinal(i)); } return children; }
public List<K> keyList() { int size = size(); Set<K> keys = keySet(); List<K> children = new ArrayList<>(size); for (K key : keys) { children.add(getOrdinal(key), key); } return children; }
@Override public Iterator<ValueVector> iterator() { return Collections.<ValueVector>unmodifiableCollection(vectors.values()).iterator(); }
/** * Get a child vector by name. * @param name the name of the child to return * @return a vector with its corresponding ordinal mapping if field exists or null. */ @Override public VectorWithOrdinal getChildVectorWithOrdinal(String name) { final int ordinal = vectors.getOrdinal(name); if (ordinal < 0) { return null; } final ValueVector vector = vectors.getByOrdinal(ordinal); return new VectorWithOrdinal(vector, ordinal); }
/** * Returns a {@link org.apache.arrow.vector.ValueVector} corresponding to the given ordinal identifier. * * @param id the ordinal of the child to return * @return the corresponding child */ public ValueVector getChildByOrdinal(int id) { return vectors.getByOrdinal(id); }
/** * Get the number of child vectors. * @return the number of underlying child vectors. */ @Override public int size() { return vectors.size(); }
/** * Returns a {@link org.apache.arrow.vector.ValueVector} instance of subtype of T corresponding to the given * field name if exists or null. * * @param name the name of the child to return * @param clazz the expected type of the child * @return the child corresponding to this name */ @Override public <T extends FieldVector> T getChild(String name, Class<T> clazz) { final ValueVector v = vectors.get(name); if (v == null) { return null; } return typeify(v, clazz); }
/** * Inserts the input vector into the map if it does not exist, replaces if it exists already. * * @param name field name * @param vector vector to be inserted */ protected void putVector(String name, FieldVector vector) { final ValueVector old = vectors.put( Preconditions.checkNotNull(name, "field name cannot be null"), Preconditions.checkNotNull(vector, "vector cannot be null") ); if (old != null && old != vector) { logger.debug("Field [{}] mutated from [{}] to [{}]", name, old.getClass().getSimpleName(), vector.getClass().getSimpleName()); } }
@Override public void reAlloc() { for (final ValueVector v : vectors.values()) { v.reAlloc(); } }
/** * Get primitive child vectors. * @return a list of scalar child vectors recursing the entire vector hierarchy. */ public List<ValueVector> getPrimitiveVectors() { final List<ValueVector> primitiveVectors = new ArrayList<>(); for (final ValueVector v : vectors.values()) { if (v instanceof AbstractStructVector) { AbstractStructVector structVector = (AbstractStructVector) v; primitiveVectors.addAll(structVector.getPrimitiveVectors()); } else { primitiveVectors.add(v); } } return primitiveVectors; }
@Override public int getBufferSize() { int actualBufSize = 0; for (final ValueVector v : vectors.values()) { for (final ArrowBuf buf : v.getBuffers(false)) { actualBufSize += buf.writerIndex(); } } return actualBufSize; } }
@Override public ArrowBuf[] getBuffers(boolean clear) { final List<ArrowBuf> buffers = new ArrayList<>(); for (final ValueVector vector : vectors.values()) { for (final ArrowBuf buf : vector.getBuffers(false)) { buffers.add(buf); if (clear) { buf.retain(1); } } if (clear) { vector.clear(); } } return buffers.toArray(new ArrowBuf[buffers.size()]); }
@Override public boolean allocateNewSafe() { /* boolean to keep track if all the memory allocation were successful * Used in the case of composite vectors when we need to allocate multiple * buffers for multiple vectors. If one of the allocations failed we need to * clear all the memory that we allocated */ boolean success = false; try { for (final ValueVector v : vectors.values()) { if (!v.allocateNewSafe()) { return false; } } success = true; } finally { if (!success) { clear(); } } return true; }