this.valueCount = def.getRecordCount();
boolean schemaChanged = schema == null;
Map<MaterializedField, ValueVector> oldFields = Maps.newHashMap();
for(VectorWrapper<?> w : container){
ValueVector v = w.getValueVector();
oldFields.put(v.getField(), v);
}
VectorContainer newVectors = new VectorContainer();
List<FieldMetadata> fields = def.getFieldList();
int bufOffset = 0;
for (FieldMetadata fmd : fields) {
FieldDef fieldDef = fmd.getDef();
ValueVector v = oldFields.remove(fieldDef);
if(v != null){
container.add(v);
continue;
}
// if we arrive here, we didn't have a matching vector.
schemaChanged = true;
MaterializedField m = new MaterializedField(fieldDef);
v = TypeHelper.getNewVector(m, allocator);
if (fmd.getValueCount() == 0){
v.clear();
} else {
v.load(fmd, buf.slice(bufOffset, fmd.getBufferLength()));
}
bufOffset += fmd.getBufferLength();
newVectors.add(v);
}
if(!oldFields.isEmpty()){
schemaChanged = true;
for(ValueVector v : oldFields.values()){
v.close();
}
}
// rebuild the schema.
SchemaBuilder b = BatchSchema.newBuilder();
for(VectorWrapper<?> v : newVectors){
b.addField(v.getField());
}
b.setSelectionVectorMode(BatchSchema.SelectionVectorMode.NONE);
this.schema = b.build();
newVectors.buildSchema(BatchSchema.SelectionVectorMode.NONE);
container = newVectors;