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;
}
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());
}
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);
}
}
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);
}
}
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;
}
Aggregations