class Catalogs {

  @VisibleForTesting
  static Optional<Catalog> loadCatalog(Configuration conf) {
    String catalogLoaderClass = conf.get(InputFormatConfig.CATALOG_LOADER_CLASS);

    if (catalogLoaderClass != null) {
      CatalogLoader loader = (CatalogLoader) DynConstructors.builder(CatalogLoader.class)
              .impl(catalogLoaderClass)
              .build()
              .newInstance();
      Catalog catalog = loader.load(conf);
      LOG.info("Loaded catalog {} using {}", catalog, catalogLoaderClass);
      return Optional.of(catalog);
    }

    String catalogName = conf.get(InputFormatConfig.CATALOG);

    if (catalogName != null) {
      Catalog catalog;
      switch (catalogName.toLowerCase()) {
        case HADOOP:
          String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION);

          catalog = (warehouseLocation != null) ? new HadoopCatalog(conf, warehouseLocation) : new HadoopCatalog(conf);
          LOG.info("Loaded Hadoop catalog {}", catalog);
          return Optional.of(catalog);
        case HIVE:
          catalog = HiveCatalogs.loadCatalog(conf);
          LOG.info("Loaded Hive Metastore catalog {}", catalog);
          return Optional.of(catalog);
        default:
          throw new NoSuchNamespaceException("Catalog %s is not supported.", catalogName);
      }
    }

    LOG.info("Catalog is not configured");
    return Optional.empty();
  }

  private  Catalogs();

}