@Override public boolean isEmptyStruct() { return 0 == container.size(); }
@Override public int getBufferSize() { if (valueCount == 0 || size() == 0) { return 0; } long buffer = 0; for (final ValueVector v : (Iterable<ValueVector>) this) { buffer += v.getBufferSize(); } return (int) buffer; }
@Override public ArrowBuf[] getBuffers(boolean clear) { List<ArrowBuf> list = new java.util.ArrayList<>(); setReaderAndWriterIndex(); if (getBufferSize() != 0) { list.add(typeBuffer); list.addAll(java.util.Arrays.asList(internalStruct.getBuffers(clear))); } if (clear) { valueCount = 0; typeBuffer.retain(); typeBuffer.release(); typeBuffer = allocator.getEmpty(); } return list.toArray(new ArrowBuf[list.size()]); }
@Override public int getValueCapacity() { if (size() == 0) { return 0; } return getChildren().stream() .mapToInt(child -> child.getValueCapacity()) .min() .getAsInt(); }
@Override public Field getField() { List<org.apache.arrow.vector.types.pojo.Field> childFields = new ArrayList<>(); List<FieldVector> children = internalStruct.getChildren(); int[] typeIds = new int[children.size()]; for (ValueVector v : children) { typeIds[childFields.size()] = v.getMinorType().ordinal(); childFields.add(v.getField()); } return new Field(name, FieldType.nullable(new ArrowType.Union(Sparse, typeIds)), childFields); }
protected StructTransferPair(NonNullableStructVector from, NonNullableStructVector to, boolean allocate) { this.from = from; this.to = to; this.pairs = new TransferPair[from.size()]; this.to.ephPair = null; int i = 0; FieldVector vector; for (String child : from.getChildFieldNames()) { int preSize = to.size(); vector = from.getChild(child); if (vector == null) { continue; } //DRILL-1872: we add the child fields for the vector, looking up the field by name. For a map vector, // the child fields may be nested fields of the top level child. For example if the structure // of a child field is oa.oab.oabc then we add oa, then add oab to oa then oabc to oab. // But the children member of a Materialized field is a HashSet. If the fields are added in the // children HashSet, and the hashCode of the Materialized field includes the hash code of the // children, the hashCode value of oa changes *after* the field has been added to the HashSet. // (This is similar to what happens in ScanBatch where the children cannot be added till they are // read). To take care of this, we ensure that the hashCode of the MaterializedField does not // include the hashCode of the children but is based only on MaterializedField$key. final FieldVector newVector = to.addOrGet(child, vector.getField().getFieldType(), vector.getClass()); if (allocate && to.size() != preSize) { newVector.allocateNew(); } pairs[i++] = vector.makeTransferPair(newVector); } }
@Override public ListWriter rootAsList() { switch (mode) { case INIT: int vectorCount = container.size(); // TODO allow dictionaries in complex types ListVector listVector = container.addOrGetList(name); if (container.size() > vectorCount) { listVector.allocateNew(); } listRoot = new UnionListWriter(listVector, nullableStructWriterFactory); listRoot.setPosition(idx()); mode = Mode.LIST; break; case LIST: break; default: check(Mode.INIT, Mode.STRUCT); } return listRoot; }
@Override public ListWriter list(String name) { String finalName = handleCase(name); FieldWriter writer = fields.get(finalName); int vectorCount = container.size(); if(writer == null) { writer = new PromotableWriter(container.addOrGet(name, FieldType.nullable(MinorType.LIST.getType()), ListVector.class), container, getNullableStructWriterFactory()); if (container.size() > vectorCount) { writer.allocate(); } writer.setPosition(idx()); fields.put(finalName, writer); } else { if (writer instanceof PromotableWriter) { // ensure writers are initialized ((PromotableWriter)writer).getWriter(MinorType.LIST); } } return writer; }
@Override public StructWriter struct(String name) { String finalName = handleCase(name); FieldWriter writer = fields.get(finalName); if(writer == null){ int vectorCount=container.size(); StructVector vector = container.addOrGet(name, FieldType.nullable(MinorType.STRUCT.getType()), StructVector.class); writer = new PromotableWriter(vector, container, getNullableStructWriterFactory()); if(vectorCount != container.size()) { writer.allocate(); } writer.setPosition(idx()); fields.put(finalName, writer); } else { if (writer instanceof PromotableWriter) { // ensure writers are initialized ((PromotableWriter)writer).getWriter(MinorType.STRUCT); } } return writer; }