boolean schemaChanged = schema == null;
// logger.info("Load, ThreadID: {}", Thread.currentThread().getId(), new RuntimeException("For Stack Trace Only"));
// System.out.println("Load, ThreadId: " + Thread.currentThread().getId());
Map<MaterializedField, ValueVector> oldFields = Maps.newHashMap();
for(VectorWrapper<?> w : container){
ValueVector v = w.getValueVector();
oldFields.put(v.getField(), v);
}
VectorContainer newVectors = new VectorContainer();
List<SerializedField> fields = def.getFieldList();
int bufOffset = 0;
for (SerializedField fmd : fields) {
MaterializedField fieldDef = MaterializedField.create(fmd);
ValueVector v = oldFields.remove(fieldDef);
if(v == null) {
// if we arrive here, we didn't have a matching vector.
schemaChanged = true;
v = TypeHelper.getNewVector(fieldDef, allocator);
}
if (fmd.getValueCount() == 0){
// v.clear();
v.load(fmd, new EmptyByteBuf(allocator.getUnderlyingAllocator()));
} 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;