@Test public void testLoadCatalog() throws IOException { Assert.assertFalse(Catalogs.loadCatalog(conf).isPresent()); conf.set(InputFormatConfig.CATALOG, "foo"); AssertHelpers.assertThrows( "Should complain about catalog not supported", NoSuchNamespaceException.class, "is not supported", () -> Catalogs.loadCatalog(conf)); conf.set(InputFormatConfig.CATALOG, "hadoop"); Optional<Catalog> hadoopCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(hadoopCatalog.isPresent()); Assert.assertTrue(hadoopCatalog.get() instanceof HadoopCatalog); conf.set(InputFormatConfig.CATALOG, "hive"); Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(hiveCatalog.isPresent()); Assert.assertTrue(hiveCatalog.get() instanceof HiveCatalog); conf.set("warehouse.location", temp.newFolder("hadoop", "warehouse").toString()); conf.setClass(InputFormatConfig.CATALOG_LOADER_CLASS, CustomHadoopCatalogLoader.class, CatalogLoader.class); Optional<Catalog> customHadoopCatalog = Catalogs.loadCatalog(conf); Assert.assertTrue(customHadoopCatalog.isPresent()); Assert.assertTrue(customHadoopCatalog.get() instanceof CustomHadoopCatalog); }
@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(); return Optional.of(loader.load(conf)); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); if (warehouseLocation != null) { return Optional.of(new HadoopCatalog(conf, warehouseLocation)); } return Optional.of(new HadoopCatalog(conf)); case HIVE: return Optional.of(HiveCatalogs.loadCatalog(conf)); default: throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported."); } } return Optional.empty(); }
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(); return Optional.of(loader.load(conf)); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); if (warehouseLocation != null) { return Optional.of(new HadoopCatalog(conf, warehouseLocation)); } return Optional.of(new HadoopCatalog(conf)); case HIVE: return Optional.of(HiveCatalogs.loadCatalog(conf)); default: throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported."); } } return Optional.empty(); } }
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(); return Optional.of(loader.load(conf)); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); if (warehouseLocation != null) { return Optional.of(new HadoopCatalog(conf, warehouseLocation)); } return Optional.of(new HadoopCatalog(conf)); case HIVE: return Optional.of(HiveCatalogs.loadCatalog(conf)); default: throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported."); } } return Optional.empty(); } private  Catalogs(); }
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(); return Optional.of(loader.load(conf)); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); if (warehouseLocation != null) { return Optional.of(new HadoopCatalog(conf, warehouseLocation)); } return Optional.of(new HadoopCatalog(conf)); case HIVE: return Optional.of(HiveCatalogs.loadCatalog(conf)); default: throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported."); } } return Optional.empty(); } private  Catalogs(); static Table loadTable(Configuration conf); static Table loadTable(Configuration conf, Properties props); }
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(); return Optional.of(loader.load(conf)); } String catalogName = conf.get(InputFormatConfig.CATALOG); if (catalogName != null) { switch (catalogName.toLowerCase()) { case HADOOP: String warehouseLocation = conf.get(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION); if (warehouseLocation != null) { return Optional.of(new HadoopCatalog(conf, warehouseLocation)); } return Optional.of(new HadoopCatalog(conf)); case HIVE: return Optional.of(HiveCatalogs.loadCatalog(conf)); default: throw new NoSuchNamespaceException("Catalog " + catalogName + " is not supported."); } } return Optional.empty(); } private  Catalogs(); static Table loadTable(Configuration conf); static Table loadTable(Configuration conf, Properties props);  }