Search in sources :

Example 6 with Catalog

use of org.apache.iceberg.catalog.Catalog in project hive by apache.

the class Catalogs method loadTable.

private static Table loadTable(Configuration conf, String tableIdentifier, String tableLocation, String catalogName) {
    Optional<Catalog> catalog = loadCatalog(conf, catalogName);
    if (catalog.isPresent()) {
        Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
        return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
    }
    Preconditions.checkArgument(tableLocation != null, "Table location not set");
    return new HadoopTables(conf).load(tableLocation);
}
Also used : HadoopTables(org.apache.iceberg.hadoop.HadoopTables) Catalog(org.apache.iceberg.catalog.Catalog)

Example 7 with Catalog

use of org.apache.iceberg.catalog.Catalog in project hive by apache.

the class TestCatalogs method testLoadCatalogHadoopWithLegacyWarehouseLocation.

@Test
public void testLoadCatalogHadoopWithLegacyWarehouseLocation() {
    String catalogName = "barCatalog";
    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogUtil.ICEBERG_CATALOG_TYPE), CatalogUtil.ICEBERG_CATALOG_TYPE_HADOOP);
    conf.set(InputFormatConfig.HADOOP_CATALOG_WAREHOUSE_LOCATION, "/tmp/mylocation");
    Optional<Catalog> hadoopCatalog = Catalogs.loadCatalog(conf, catalogName);
    Assert.assertTrue(hadoopCatalog.isPresent());
    Assertions.assertThat(hadoopCatalog.get()).isInstanceOf(HadoopCatalog.class);
    Assert.assertEquals("HadoopCatalog{name=barCatalog, location=/tmp/mylocation}", hadoopCatalog.get().toString());
    Properties properties = new Properties();
    properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
    Assert.assertFalse(Catalogs.hiveCatalog(conf, properties));
}
Also used : CatalogProperties(org.apache.iceberg.CatalogProperties) Properties(java.util.Properties) Catalog(org.apache.iceberg.catalog.Catalog) HadoopCatalog(org.apache.iceberg.hadoop.HadoopCatalog) HiveCatalog(org.apache.iceberg.hive.HiveCatalog) Test(org.junit.Test)

Example 8 with Catalog

use of org.apache.iceberg.catalog.Catalog in project hive by apache.

the class TestCatalogs method testLoadCatalogDefault.

@Test
public void testLoadCatalogDefault() {
    String catalogName = "barCatalog";
    Optional<Catalog> defaultCatalog = Catalogs.loadCatalog(conf, catalogName);
    Assert.assertTrue(defaultCatalog.isPresent());
    Assertions.assertThat(defaultCatalog.get()).isInstanceOf(HiveCatalog.class);
    Properties properties = new Properties();
    properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
    Assert.assertTrue(Catalogs.hiveCatalog(conf, properties));
}
Also used : CatalogProperties(org.apache.iceberg.CatalogProperties) Properties(java.util.Properties) Catalog(org.apache.iceberg.catalog.Catalog) HadoopCatalog(org.apache.iceberg.hadoop.HadoopCatalog) HiveCatalog(org.apache.iceberg.hive.HiveCatalog) Test(org.junit.Test)

Example 9 with Catalog

use of org.apache.iceberg.catalog.Catalog in project hive by apache.

the class TestCatalogs method testLoadCatalogHive.

@Test
public void testLoadCatalogHive() {
    String catalogName = "barCatalog";
    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogUtil.ICEBERG_CATALOG_TYPE), CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE);
    Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf, catalogName);
    Assert.assertTrue(hiveCatalog.isPresent());
    Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class);
    Properties properties = new Properties();
    properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
    Assert.assertTrue(Catalogs.hiveCatalog(conf, properties));
}
Also used : CatalogProperties(org.apache.iceberg.CatalogProperties) Properties(java.util.Properties) Catalog(org.apache.iceberg.catalog.Catalog) HadoopCatalog(org.apache.iceberg.hadoop.HadoopCatalog) HiveCatalog(org.apache.iceberg.hive.HiveCatalog) Test(org.junit.Test)

Example 10 with Catalog

use of org.apache.iceberg.catalog.Catalog in project hive by apache.

the class TestCatalogs method testLoadCatalogCustom.

@Test
public void testLoadCatalogCustom() {
    String catalogName = "barCatalog";
    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogProperties.CATALOG_IMPL), CustomHadoopCatalog.class.getName());
    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, CatalogProperties.WAREHOUSE_LOCATION), "/tmp/mylocation");
    Optional<Catalog> customHadoopCatalog = Catalogs.loadCatalog(conf, catalogName);
    Assert.assertTrue(customHadoopCatalog.isPresent());
    Assertions.assertThat(customHadoopCatalog.get()).isInstanceOf(CustomHadoopCatalog.class);
    Properties properties = new Properties();
    properties.put(InputFormatConfig.CATALOG_NAME, catalogName);
    Assert.assertFalse(Catalogs.hiveCatalog(conf, properties));
}
Also used : CatalogProperties(org.apache.iceberg.CatalogProperties) Properties(java.util.Properties) Catalog(org.apache.iceberg.catalog.Catalog) HadoopCatalog(org.apache.iceberg.hadoop.HadoopCatalog) HiveCatalog(org.apache.iceberg.hive.HiveCatalog) Test(org.junit.Test)

Aggregations

Catalog (org.apache.iceberg.catalog.Catalog)10 Test (org.junit.Test)7 HadoopCatalog (org.apache.iceberg.hadoop.HadoopCatalog)6 Properties (java.util.Properties)5 CatalogProperties (org.apache.iceberg.CatalogProperties)5 HiveCatalog (org.apache.iceberg.hive.HiveCatalog)5 HadoopTables (org.apache.iceberg.hadoop.HadoopTables)3 PartitionSpec (org.apache.iceberg.PartitionSpec)2 Schema (org.apache.iceberg.Schema)2 Table (org.apache.iceberg.Table)2 TableIdentifier (org.apache.iceberg.catalog.TableIdentifier)2 CachingCatalog (org.apache.iceberg.CachingCatalog)1 Record (org.apache.iceberg.data.Record)1