protected void setValueCountAndPopulatePartitionVectors(int recordCount) { for (ValueVector v : vectors) { v.getMutator().setValueCount(recordCount); } if (partition != null) { populatePartitionVectors(recordCount); } }
public RepeatedMapTransferPair(RepeatedMapVector from, RepeatedMapVector to, boolean allocate) { this.from = from; this.to = to; this.pairs = new TransferPair[from.size()]; this.to.ephPair = null; int i = 0; ValueVector vector; for (final String child : from.getChildFieldNames()) { final int preSize = to.size(); vector = from.getChild(child); if (vector == null) { continue; } final ValueVector newVector = to.addOrGet(child, vector.getField().getType(), vector.getClass()); if (to.size() != preSize) { newVector.allocateNew(); } pairs[i++] = vector.makeTransferPair(newVector); } }
private boolean nullFilled(ValueVector vector) { for (int r = 0; r < vector.getAccessor().getValueCount(); r++) { if (! vector.getAccessor().isNull(r)) { return false; } } return true; }
@Override public DrillBuf[] getBuffers(boolean clear) { final List<DrillBuf> buffers = Lists.newArrayList(); for (final ValueVector vector : vectors.values()) { for (final DrillBuf buf : vector.getBuffers(false)) { buffers.add(buf); if (clear) { buf.retain(1); } } if (clear) { vector.clear(); } } return buffers.toArray(new DrillBuf[buffers.size()]); }
@Override public void exchange(ValueVector other) { AbstractMapVector otherMap = (AbstractMapVector) other; if (vectors.size() != otherMap.vectors.size()) { throw new IllegalStateException("Maps have different column counts"); } for (int i = 0; i < vectors.size(); i++) { assert vectors.getByOrdinal(i).getField().isEquivalent( otherMap.vectors.getByOrdinal(i).getField()); vectors.getByOrdinal(i).exchange(otherMap.vectors.getByOrdinal(i)); } } }
/** * Allocates the exact amount if v is fixed width, otherwise falls back to dynamic allocation * @param vector value vector we are trying to allocate * @param valueCount size we are trying to allocate * @throws org.apache.drill.exec.memory.OutOfMemoryException if it can't allocate the memory */ public static void allocateNew(ValueVector vector, int valueCount) { if (vector instanceof FixedWidthVector) { ((FixedWidthVector) vector).allocateNew(valueCount); } else { vector.allocateNew(); } } }
protected void replaceDataVector(ValueVector v) { vector.clear(); vector = v; }
@Override public MajorType type() { return vector.getField().getType(); }
v.clear(); v.allocateNew();
public ValueVector setFirstType(ValueVector v, int newValueCount) { // We can't check that this really is the first subtype since // the subtypes can be declared before vectors are added. Preconditions.checkState(accessor.getValueCount() == 0); final ValueVector vv = addVector(v); MinorType type = v.getField().getType().getMinorType(); ValueVector.Accessor vAccessor = vv.getAccessor(); for (int i = 0; i < newValueCount; i++) { if (! vAccessor.isNull(i)) { mutator.setType(i, type); } else { mutator.setNull(i); } } mutator.setValueCount(newValueCount); return vv; }
@Override public UInt1Writer uInt1(String name) { FieldWriter writer = fields.get(name.toLowerCase()); if(writer == null) { ValueVector vector; ValueVector currentVector = container.getChild(name); if (unionEnabled){ NullableUInt1Vector v = container.addOrGet(name, UINT1_TYPE, NullableUInt1Vector.class); writer = new PromotableWriter(v, container); vector = v; } else { NullableUInt1Vector v = container.addOrGet(name, UINT1_TYPE, NullableUInt1Vector.class); writer = new NullableUInt1WriterImpl(v, this); vector = v; } if (currentVector == null || currentVector != vector) { vector.allocateNewSafe(); } writer.setPosition(currentChildIndex); fields.put(name.toLowerCase(), writer); } return writer; }
/** * Add a vector that matches the argument. Transfer the buffer from the argument * to the new vector. * * @param v the vector to clone and add * @return the cloned vector that now holds the data from the argument */ public ValueVector addVector(ValueVector v) { String name = v.getField().getType().getMinorType().name().toLowerCase(); MajorType type = v.getField().getType(); MinorType minorType = type.getMinorType(); Preconditions.checkState(internalMap.getChild(name) == null, String.format("%s vector already exists", name)); final ValueVector newVector = internalMap.addOrGet(name, type, BasicTypeHelper.getValueVectorClass(minorType, type.getMode())); v.makeTransferPair(newVector).transfer(); internalMap.putChild(name, newVector); cachedSubtypes[minorType.ordinal()] = newVector; addSubType(minorType); return newVector; }
public void getFieldById(int fieldId, ComplexHolder holder) { holder.isSet = vectors[fieldId].getAccessor().isNull(currentIndex) ? 1 : 0; holder.reader = (vectors[fieldId]).getReader(); holder.reader.setPosition(currentIndex); }
/** * Clears out all underlying child vectors. */ @Override public void close() { for (ValueVector vector : this) { vector.close(); } }
@Override public void load(SerializedField metadata, DrillBuf buf) { final List<SerializedField> fields = metadata.getChildList(); valueCount = metadata.getValueCount(); int bufOffset = 0; for (final SerializedField child : fields) { final MaterializedField fieldDef = MaterializedField.create(child); ValueVector vector = getChild(fieldDef.getName()); if (vector == null) { // if we arrive here, we didn't have a matching vector. vector = BasicTypeHelper.getNewVector(fieldDef, allocator); putChild(fieldDef.getName(), vector); } if (child.getValueCount() == 0) { vector.clear(); } else { vector.load(child, buf.slice(bufOffset, child.getBufferLength())); } bufOffset += child.getBufferLength(); } // We should have consumed all bytes written into the buffer // during deserialization. assert bufOffset == buf.writerIndex(); }
@Override public void collectLedgers(Set<BufferLedger> ledgers) { offsets.collectLedgers(ledgers); vector.collectLedgers(ledgers); }
public static void allocatePrecomputedChildCount(ValueVector vector, int valueCount, int bytesPerValue, int childValCount) { // Don't fail if given a 0-sized array. Assume at least one value. childValCount = Math.max(1, childValCount); valueCount = Math.max(1, valueCount); bytesPerValue = Math.max(1, bytesPerValue); if (vector instanceof FixedWidthVector) { ((FixedWidthVector) vector).allocateNew(valueCount); } else if (vector instanceof VariableWidthVector) { ((VariableWidthVector) vector).allocateNew(valueCount * bytesPerValue, valueCount); } else if (vector instanceof RepeatedFixedWidthVectorLike) { ((RepeatedFixedWidthVectorLike) vector).allocateNew(valueCount, childValCount); } else if (vector instanceof RepeatedVariableWidthVectorLike) { // Assertion thrown if byte count is zero in the full allocateNew, // so use default version instead. ((RepeatedVariableWidthVectorLike) vector).allocateNew(childValCount * bytesPerValue, valueCount, childValCount); } else { vector.allocateNew(); } }
@Override public void clear() { for (final ValueVector v : getChildren()) { v.clear(); } valueCount = 0; }
/** * Inserts the vector with the given name if it does not exist else replaces it with the new value. * * Note that this method does not enforce any vector type check nor throws a schema change exception. */ public void putChild(String name, ValueVector vector) { putVector(name, vector); field.addChild(vector.getField()); }