Search in sources :

Example 1 with TableEntity

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

the class MemoryMetadata method getViewDef.

private ConnectorViewDefinition getViewDef(SchemaTableName viewName) {
    // cache view def in the map to avoid deserializing it on every visit
    ConnectorViewDefinition view = views.get(viewName);
    if (view == null) {
        try {
            TableEntity tableEntity = getTableEntity(viewName, true);
            if (isView(tableEntity)) {
                view = VIEW_CODEC.fromJson(Base64.getDecoder().decode(tableEntity.getViewOriginalText()));
                views.put(viewName, view);
            }
        } catch (Exception e) {
            views.remove(viewName);
        }
    }
    return view;
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) ViewNotFoundException(io.prestosql.spi.connector.ViewNotFoundException) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) PrestoException(io.prestosql.spi.PrestoException) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition)

Example 2 with TableEntity

use of io.prestosql.spi.metastore.model.TableEntity 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 3 with TableEntity

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

the class HetuHBaseMetastore method addHBaseTable.

@Override
public void addHBaseTable(HBaseTable hBaseTable) {
    synchronized (hbaseTables) {
        TableEntity tableEntity = hBaseTableToTableEntity(hBaseTable);
        if (!hetuMetastore.getDatabase(catalogName, hBaseTable.getSchema()).isPresent()) {
            DatabaseEntity databaseEntity = DatabaseEntity.builder().setCatalogName(catalogName).setDatabaseName(hBaseTable.getSchema()).setCreateTime(new Date().getTime()).build();
            hetuMetastore.createDatabase(databaseEntity);
        }
        hetuMetastore.createTable(tableEntity);
        hbaseTables.put(hBaseTable.getFullTableName(), hBaseTable);
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Date(java.util.Date)

Example 4 with TableEntity

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

the class HetuHBaseMetastore method renameHBaseTable.

@Override
public void renameHBaseTable(HBaseTable newTable, String oldTable) {
    synchronized (hbaseTables) {
        String[] table = oldTable.split(Constants.SPLITPOINT);
        if (table.length != SPLIT_NUM) {
            return;
        }
        TableEntity tableEntity = hBaseTableToTableEntity(newTable);
        hetuMetastore.alterTable(catalogName, table[0], table[1], tableEntity);
        hbaseTables.remove(oldTable);
        hbaseTables.put(newTable.getFullTableName(), newTable);
    }
}
Also used : TableEntity(io.prestosql.spi.metastore.model.TableEntity)

Example 5 with TableEntity

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

the class HetuHBaseMetastore method getHBaseTableFromHetuMetastore.

private HBaseTable getHBaseTableFromHetuMetastore(String catalog, String schema, String table) {
    TableEntity tableEntity = hetuMetastore.getTable(catalog, schema, table).orElse(null);
    if (tableEntity == null) {
        return null;
    }
    Map<String, ColumnHandle> columnsMap = new HashMap<>();
    List<HBaseColumnHandle> columns = new ArrayList<>();
    for (ColumnEntity entity : tableEntity.getColumns()) {
        Map<String, String> columnParam = entity.getParameters();
        HBaseColumnHandle columnHandle = new HBaseColumnHandle(entity.getName(), Optional.ofNullable(columnParam.get(Constants.S_FAMILY)), Optional.ofNullable(columnParam.get(Constants.S_QUALIFIER)), Utils.createTypeByName(entity.getType()), Integer.parseInt(columnParam.get(Constants.S_ORDINAL)), entity.getComment(), Constants.S_TRUE.equals(columnParam.get(Constants.S_INDEXED).toLowerCase(Locale.ENGLISH)));
        columns.add(columnHandle);
        columnsMap.put(entity.getName(), columnHandle);
    }
    Map<String, String> tableParam = tableEntity.getParameters();
    HBaseTable hBaseTable = new HBaseTable(tableEntity.getDatabaseName(), tableEntity.getName(), columns, tableParam.get(Constants.S_ROWID), Constants.S_TRUE.equals(tableParam.get(Constants.S_EXTERNAL).toLowerCase(Locale.ENGLISH)), Optional.ofNullable(tableParam.get(Constants.S_SERIALIZER_CLASS_NAME)), Optional.ofNullable(tableParam.get(Constants.S_INDEX_COLUMNS)), Optional.ofNullable(tableParam.get(Constants.S_HBASE_TABLE_NAME)), Optional.ofNullable(tableParam.get(Constants.S_SPLIT_BY_CHAR)));
    hBaseTable.setColumnsToMap(columnsMap);
    return hBaseTable;
}
Also used : HBaseColumnHandle(io.hetu.core.plugin.hbase.connector.HBaseColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) 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)

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