Search in sources :

Example 6 with TableEntity

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

the class HetuHBaseMetastore method hBaseTableToTableEntity.

private TableEntity hBaseTableToTableEntity(HBaseTable hBaseTable) {
    TableEntity tableEntity = new TableEntity();
    tableEntity.setCatalogName(catalogName);
    tableEntity.setDatabaseName(hBaseTable.getSchema());
    tableEntity.setName(hBaseTable.getTable());
    tableEntity.setType(TABLE_TYPE);
    List<ColumnEntity> columns = new ArrayList<>();
    for (HBaseColumnHandle columnHandle : hBaseTable.getColumns()) {
        ColumnEntity columnEntity = new ColumnEntity();
        columnEntity.setName(columnHandle.getColumnName());
        columnEntity.setType(columnHandle.getType().getClass().getName());
        columnEntity.setComment(columnHandle.getComment());
        Map<String, String> columnParam = new HashMap<>();
        columnParam.put(Constants.S_FAMILY, columnHandle.getFamily().orElse(null));
        columnParam.put(Constants.S_QUALIFIER, columnHandle.getQualifier().orElse(null));
        columnParam.put(Constants.S_ORDINAL, String.valueOf(columnHandle.getOrdinal()));
        columnParam.put(Constants.S_INDEXED, String.valueOf(columnHandle.isIndexed()).toLowerCase(Locale.ENGLISH));
        columnEntity.setParameters(columnParam);
        columns.add(columnEntity);
    }
    tableEntity.setColumns(columns);
    Map<String, String> tableParam = new HashMap<>();
    tableParam.put(Constants.S_EXTERNAL, String.valueOf(hBaseTable.isExternal()).toLowerCase(Locale.ENGLISH));
    tableParam.put(Constants.S_SERIALIZER_CLASS_NAME, hBaseTable.getSerializerClassName());
    tableParam.put(Constants.S_ROWID, hBaseTable.getRowId());
    tableParam.put(Constants.S_INDEX_COLUMNS, hBaseTable.getIndexColumns());
    tableParam.put(Constants.S_HBASE_TABLE_NAME, hBaseTable.getHbaseTableName().orElse(null));
    tableParam.put(Constants.S_SPLIT_BY_CHAR, hBaseTable.getSplitByChar().orElse(null));
    tableEntity.setParameters(tableParam);
    return tableEntity;
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TableEntity(io.prestosql.spi.metastore.model.TableEntity)

Example 7 with TableEntity

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

the class VdmMetadata method listViews.

@Override
public List<SchemaTableName> listViews(ConnectorSession session, Optional<String> schemaName) {
    ImmutableList.Builder<SchemaTableName> tableNames = ImmutableList.builder();
    List<String> schemaNames = schemaName.<List<String>>map(ImmutableList::of).orElseGet(() -> listSchemaNames(session));
    for (String schema : schemaNames) {
        List<TableEntity> views = metastore.getAllTables(vdmName, schema);
        for (TableEntity view : views) {
            tableNames.add(new SchemaTableName(view.getDatabaseName(), view.getName()));
        }
    }
    return tableNames.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableEntity(io.prestosql.spi.metastore.model.TableEntity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName)

Example 8 with TableEntity

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

the class TestHetuMetastoreCacheLocal method testGetTable.

/**
 * test get table with metastore cache
 */
@Test
public void testGetTable() throws JsonProcessingException {
    String tableName = "table3";
    SchemaTableName schemaTableName = new SchemaTableName(defaultDatabase.getName(), tableName);
    TableEntity tableEntity = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(schemaTableName.getTableName()).setTableType(TableEntityType.TABLE.toString()).build();
    metastore.createTable(tableEntity);
    Optional<TableEntity> tableEntity2 = metastore.getTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
    String tableKey = defaultDatabase.getCatalogName() + "." + defaultDatabase.getName() + "." + tableName;
    actual = mapper.writeValueAsString(tableCache.getIfPresent(tableKey).get());
    expected = mapper.writeValueAsString(tableEntity2.get());
    assertEquals(actual, expected);
    metastore.dropTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 9 with TableEntity

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

the class TestHetuMetastoreCacheLocal method testCreateTable.

/**
 * testCreateView with metastore cache
 */
@Test
public void testCreateTable() {
    String tableName = "table1";
    SchemaTableName schemaTableName = new SchemaTableName(defaultDatabase.getName(), tableName);
    TableEntity tableEntity = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(schemaTableName.getTableName()).setTableType(TableEntityType.TABLE.toString()).build();
    metastore.createTable(tableEntity);
    String tablesKey = defaultDatabase.getCatalogName() + "." + defaultDatabase.getName();
    assertEquals(tablesCache.getIfPresent(tablesKey), null);
    metastore.dropTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 10 with TableEntity

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

the class TestHetuMetastoreCacheLocal method testGetAllTables.

/**
 * test get all table with metastore cache
 */
@Test
public void testGetAllTables() throws JsonProcessingException {
    String tableName = "table4";
    SchemaTableName schemaTableName = new SchemaTableName(defaultDatabase.getName(), tableName);
    TableEntity tableEntity = TableEntity.builder().setCatalogName(defaultDatabase.getCatalogName()).setDatabaseName(defaultDatabase.getName()).setTableName(schemaTableName.getTableName()).setTableType(TableEntityType.TABLE.toString()).build();
    metastore.createTable(tableEntity);
    List<TableEntity> tableEntities = metastore.getAllTables(defaultDatabase.getCatalogName(), defaultDatabase.getName());
    String tablesKey = defaultDatabase.getCatalogName() + "." + defaultDatabase.getName();
    actual = mapper.writeValueAsString(tablesCache.getIfPresent(tablesKey));
    expected = mapper.writeValueAsString(tableEntities);
    assertEquals(actual, expected);
    metastore.dropTable(defaultDatabase.getCatalogName(), defaultDatabase.getName(), tableName);
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Aggregations

TableEntity (io.prestosql.spi.metastore.model.TableEntity)53 Test (org.testng.annotations.Test)31 PrestoException (io.prestosql.spi.PrestoException)25 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)22 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)20 ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)11 IOException (java.io.IOException)9 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)8 ImmutableList (com.google.common.collect.ImmutableList)7 CatalogEntity (io.prestosql.spi.metastore.model.CatalogEntity)7 ArrayList (java.util.ArrayList)7 Logger (io.airlift.log.Logger)5 List (java.util.List)5 Optional (java.util.Optional)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 BeforeTest (org.testng.annotations.BeforeTest)4 SchemaNotFoundException (io.prestosql.spi.connector.SchemaNotFoundException)3 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)3 HETU_METASTORE_CODE (io.prestosql.spi.metastore.HetuErrorCode.HETU_METASTORE_CODE)3 HetuMetastore (io.prestosql.spi.metastore.HetuMetastore)3