Search in sources :

Example 1 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class IndexRecordManager method addIndexRecord.

/**
 * Add IndexRecord into record file. If the method is called with a name that already exists,
 *
 * it will OVERWRITE the existing entry but COMBINE the partition columns (if it previously was partitioned)
 */
public synchronized void addIndexRecord(String name, String user, String table, String[] columns, String indexType, long indexSize, List<String> indexProperties, List<String> partitions) {
    IndexRecord record = new IndexRecord(name, user, table, columns, indexType, indexSize, indexProperties, partitions);
    IndexRecord old = lookUpIndexRecord(name);
    if (old != null) {
        record.partitions.addAll(0, old.partitions);
    }
    Optional<CatalogEntity> oldCatalog = metastore.getCatalog(record.catalog);
    if (!oldCatalog.isPresent()) {
        CatalogEntity newCatalog = CatalogEntity.builder().setCatalogName(record.catalog).build();
        metastore.createCatalogIfNotExist(newCatalog);
    }
    Optional<DatabaseEntity> oldSchema = metastore.getDatabase(record.catalog, record.schema);
    if (!oldSchema.isPresent()) {
        DatabaseEntity newSchema = DatabaseEntity.builder().setCatalogName(record.catalog).setDatabaseName(record.schema).build();
        metastore.createDatabaseIfNotExist(newSchema);
    }
    Optional<TableEntity> oldTable = metastore.getTable(record.catalog, record.schema, record.table);
    if (!oldTable.isPresent()) {
        TableEntity newTable = TableEntity.builder().setCatalogName(record.catalog).setDatabaseName(record.schema).setTableName(record.table).setTableType(TableEntityType.TABLE.toString()).build();
        metastore.createTableIfNotExist(newTable);
    }
    metastore.alterTableParameter(record.catalog, record.schema, record.table, record.serializeKey(), record.serializeValue());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) IndexRecord(io.prestosql.spi.heuristicindex.IndexRecord) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity)

Example 2 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreCacheLocal method testDropCatalog.

/**
 * test drop dropCatalog with metastore cache
 */
@Test
public void testDropCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root2").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalogEntity);
    metastore.dropCatalog(catalogEntity.getName());
    assertEquals(catalogCache.getIfPresent("catalog2"), null);
    assertEquals(catalogsCache.getIfPresent(""), null);
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Example 3 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreCacheLocal method testGetCatalog.

/**
 * test get catalog with metastore cache
 */
@Test
public void testGetCatalog() throws JsonProcessingException {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalogEntity = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root3").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalogEntity);
    Optional<CatalogEntity> catalogInfo = metastore.getCatalog("catalog3");
    assertTrue(catalogInfo.isPresent());
    actual = mapper.writeValueAsString(catalogInfo.get());
    expected = mapper.writeValueAsString(catalogEntity);
    assertEquals(actual, expected);
    assertEquals(catalogInfo.get(), catalogEntity);
    metastore.dropCatalog(catalogEntity.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Example 4 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreCacheLocal method testGetAllCatalogs.

/**
 * test get All catalogs with metastore cache
 */
@Test
public void testGetAllCatalogs() throws JsonProcessingException {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("catalog4").setOwner("root4").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog1);
    CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog5").setOwner("root5").setComment(Optional.of("Hetu create catalog")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog2);
    List<CatalogEntity> catalogEntities = metastore.getCatalogs();
    actual = mapper.writeValueAsString(catalogsCache.getIfPresent(""));
    expected = mapper.writeValueAsString(catalogEntities);
    assertEquals(actual, expected);
    metastore.dropCatalog(catalog1.getName());
    metastore.dropCatalog(catalog2.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Example 5 with CatalogEntity

use of io.prestosql.spi.metastore.model.CatalogEntity in project hetu-core by openlookeng.

the class TestHetuMetastoreCacheLocal method testAlterCatalog.

/**
 * test alter catalog with metastore cache
 */
@Test
public void testAlterCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("root6").setComment(Optional.of("Hetu create catalog")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog1);
    CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog6").setOwner("hive").setComment(Optional.of("Hetu alter catalog")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.alterCatalog("catalog6", catalog2);
    assertEquals(catalogsCache.getIfPresent(""), null);
    metastore.dropCatalog(catalog2.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Aggregations

CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)34 Test (org.testng.annotations.Test)24 PrestoException (io.prestosql.spi.PrestoException)15 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)7 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 TableEntity (io.prestosql.spi.metastore.model.TableEntity)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 List (java.util.List)3 Logger (io.airlift.log.Logger)2 Path (java.nio.file.Path)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 CharStreams (com.google.common.io.CharStreams)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1