docs: @SuppressWarnings({ "unchecked", "rawtypes" })
      private static Schema getSchemaFromPath(FileSystem fs, Path path) {
  
          try {
              if(fs.isFile(path)) {
                  BufferedInputStream inStream = null;
                  try {
                      inStream = new BufferedInputStream(fs.open(path));
                  } catch(IOException e1) {
                      throw new RuntimeException("Unable to open " + path, e1);
                  }
                  GenericDatumReader datum = new GenericDatumReader();
  
                  DataFileStream reader = null;
                  try {
                      reader = new DataFileStream(inStream, datum);
                  } catch(IOException e) {
                      throw new RuntimeException("Invalid avro format, path " + path, e);
                  }
                  return reader.getSchema();
              } else {
                  FileStatus[] statuses = null;
                  if(fs.isDirectory(path)) {
                      // this is a directory, get schemas from all subfiles
                      statuses = fs.listStatus(path);
                      if(statuses == null || statuses.length == 0)
                          throw new IllegalArgumentException("No files in directory " + path);
                  } else {
                      // this is wildcard path, get schemas from all matched files
                      statuses = fs.globStatus(path);
                      if(statuses == null || statuses.length == 0)
                          throw new IllegalArgumentException("No matches for path pattern " + path);
                  }
                  List<Schema> schemas = new ArrayList<Schema>();
                  for(FileStatus status: statuses) {
                      if(!HadoopUtils.shouldPathBeIgnored(status.getPath())) {
                          schemas.add(getSchemaFromPath(fs, status.getPath()));
                      }
                  }
  
                  // now check that all the schemas are the same
                  if(schemas.size() > 0) {
                      Schema schema = schemas.get(0);
                      for(int i = 1; i < schemas.size(); i++)
                          if(!schema.equals(schemas.get(i)))
                              throw new IllegalArgumentException("The directory "
                                                                 + path
                                                                 + " contains heterogeneous schemas: found both '"
                                                                 + schema + "' and '"
                                                                 + schemas.get(i) + "'.");
  
                      return schema;
                  } else {
                      throw new IllegalArgumentException("No valid metadata file found for path " + path);
                  }
              }
          } catch(Exception e) {
              throw new RuntimeException("Error getting schema for path " + path, e);
          }
      }