* @param conf configuration object
* @return Set of element descriptors for all metadata files associated with the files on the path.
*/
protected Set<ElementDescriptor> findMetaFile(String path, String prefix, Configuration conf)
throws IOException {
DataStorage storage = new HDataStorage(ConfigurationUtil.toProperties(conf));
String fullPath = FileLocalizer.fullPath(path, storage);
Set<ElementDescriptor> metaFileSet = new HashSet<ElementDescriptor>();
if(storage.isContainer(fullPath)) {
ElementDescriptor metaFilePath = storage.asElement(fullPath, prefix);
if (metaFilePath.exists()) {
metaFileSet.add(metaFilePath);
}
} else {
ElementDescriptor[] descriptors = storage.asCollection(path);
for(ElementDescriptor descriptor : descriptors) {
String fileName = null, parentName = null;
ContainerDescriptor parentContainer = null;
if (descriptor instanceof HFile) {
Path descriptorPath = ((HFile) descriptor).getPath();
fileName = descriptorPath.getName();
Path parent = descriptorPath.getParent();
parentName = parent.toString();
parentContainer = new HDirectory((HDataStorage)storage,parent);
}
ElementDescriptor metaFilePath = storage.asElement(parentName, prefix+"."+fileName);
// if the file has a custom schema, use it
if (metaFilePath.exists()) {
metaFileSet.add(metaFilePath);
continue;
}
// if no custom schema, try the parent directory
metaFilePath = storage.asElement(parentContainer, prefix);
if (metaFilePath.exists()) {
metaFileSet.add(metaFilePath);
}
}
}