Search in sources :

Example 11 with CatalogEntity

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

the class StarTreeMetaStore method persist.

@Override
public void persist(CubeMetadata cubeMetadata) {
    CatalogEntity catalogEntity = catalogEntity();
    if (!metastore.getCatalog(catalogEntity.getName()).isPresent()) {
        metastore.createCatalog(catalogEntity);
    }
    DatabaseEntity databaseEntity = databaseEntity();
    if (!metastore.getDatabase(catalogEntity.getName(), databaseEntity.getName()).isPresent()) {
        metastore.createDatabase(databaseEntity);
    }
    String cubeNameDelimited = cubeMetadata.getCubeName().replace(".", "_");
    TableEntity table = getTableEntity((StarTreeMetadata) cubeMetadata);
    if (metastore.getTable(CUBE_CATALOG, CUBE_DATABASE, cubeNameDelimited).isPresent()) {
        // update flow
        metastore.alterTable(CUBE_CATALOG, CUBE_DATABASE, cubeNameDelimited, table);
    } else {
        // create flow
        metastore.createTable(table);
    }
    cubeCache.invalidate(cubeMetadata.getSourceTableName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity)

Example 12 with CatalogEntity

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

the class TestHetuFsMetastore method testDropCatalog.

/**
 * test drop dropCatalog
 */
@Test
public void testDropCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive1.metastore", "129.0.0.1").put("hive1.config", "core-site.xml").build();
    CatalogEntity hive = CatalogEntity.builder().setCatalogName("hive").setOwner("root3").setComment(Optional.of("hive database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(hive);
    // drop not exist catalog
    try {
        metastore.dropCatalog("noExistCatalog");
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
    }
    // drop catalog not empty
    DatabaseEntity db1 = DatabaseEntity.builder().setCatalogName(hive.getName()).setDatabaseName("db1").setOwner("root4").build();
    metastore.createDatabase(db1);
    try {
        metastore.dropCatalog(hive.getName());
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), CATALOG_NOT_EMPTY.toErrorCode());
    }
    metastore.dropDatabase(db1.getCatalogName(), db1.getName());
    metastore.dropCatalog(hive.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test)

Example 13 with CatalogEntity

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

the class TestJdbcHetuMetastore method testGetAllCatalogs.

/**
 * test get All catalogs
 */
@Test
public void testGetAllCatalogs() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive.metastore", "130.0.0.1").put("hive.config", "hdfs-site.xml").build();
    CatalogEntity catalog2 = CatalogEntity.builder().setCatalogName("catalog2").setOwner("root6").setComment(Optional.of("mysql database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog2);
    CatalogEntity catalog3 = CatalogEntity.builder().setCatalogName("catalog3").setOwner("root7").setComment(Optional.of("mysql1 database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog3);
    CatalogEntity catalog4 = CatalogEntity.builder().setCatalogName("catalog4").setOwner("root8").setComment(Optional.of("oracle database source")).setParameters(emptyMap()).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog4);
    final int catalogNumer = 3;
    assertTrue(metastore.getCatalogs().size() > catalogNumer);
    ImmutableList.Builder<CatalogEntity> catalogs = ImmutableList.builder();
    metastore.getCatalogs().stream().forEach(catalog -> {
        String name = catalog.getName();
        if (name.equals(catalog2.getName()) || name.equals(catalog3.getName()) || name.equals(catalog4.getName())) {
            catalogs.add(catalog);
        }
    });
    assertEquals(catalogs.build(), ImmutableList.of(catalog2, catalog3, catalog4));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) Test(org.testng.annotations.Test)

Example 14 with CatalogEntity

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

the class TestJdbcHetuMetastore method testCreateCatalogParallel.

/**
 * test create catalog parallel
 */
@Test
public void testCreateCatalogParallel() throws InterruptedException {
    Map<String, String> properties = ImmutableMap.<String, String>builder().build();
    CatalogEntity catalog = CatalogEntity.builder().setCatalogName("catalog100").setOwner("root1").setComment(Optional.of("create catalog parallel")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    testResult = true;
    Thread[] threads = new Thread[5];
    for (int i = 0; i < 5; i++) {
        threads[i] = new Thread(() -> {
            try {
                metastore.createCatalogIfNotExist(catalog);
            } catch (PrestoException e) {
                testResult = false;
            }
        });
        threads[i].start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    assertTrue(testResult);
    metastore.dropCatalog(catalog.getName());
}
Also used : CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) PrestoException(io.prestosql.spi.PrestoException) Test(org.testng.annotations.Test)

Example 15 with CatalogEntity

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

the class TestJdbcHetuMetastore method testGetCatalog.

/**
 * test get catalog
 */
@Test
public void testGetCatalog() {
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("hive.metastore", "126.0.0.1").put("hive.config", "hdfs-site.xml").build();
    CatalogEntity catalog1 = CatalogEntity.builder().setCatalogName("hive2").setOwner("root5").setComment(Optional.of("hive database source")).setParameters(properties).setCreateTime(System.currentTimeMillis()).build();
    metastore.createCatalog(catalog1);
    Optional<CatalogEntity> catalogInfo = metastore.getCatalog(catalog1.getName());
    assertTrue(catalogInfo.isPresent());
    assertEquals(catalog1.getParameters(), catalogInfo.get().getParameters());
    assertEquals(catalogInfo.get(), catalog1);
    Optional<CatalogEntity> catalogInfo1 = metastore.getCatalog("mysql");
    assertFalse(catalogInfo1.isPresent());
}
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