this.entry = entry;
setColumns(columns);
}
public static MessageType getProjection(MessageType schema, Collection<SchemaPath> columns) {
MessageType projection = null;
for (SchemaPath path : columns) {
List<String> segments = Lists.newArrayList();
PathSegment rootSegment = path.getRootSegment();
PathSegment seg = rootSegment;
String messageName = schema.getName();
while(seg != null){
if(seg.isNamed()) {
segments.add(seg.getNameSegment().getPath());
}
seg = seg.getChild();
}
String[] pathSegments = new String[segments.size()];
segments.toArray(pathSegments);
Type type = null;
try {
type = schema.getType(pathSegments);
} catch (InvalidRecordException e) {
logger.warn("Invalid record" , e);
}
if (type != null) {
Type t = getType(pathSegments, 0, schema);
if (projection == null) {
projection = new MessageType(messageName, t);
} else {
projection = projection.union(new MessageType(messageName, t));
}
}
}
return projection;
}