use of io.prestosql.spi.metastore.model.ColumnEntity 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;
}
use of io.prestosql.spi.metastore.model.ColumnEntity 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;
}
use of io.prestosql.spi.metastore.model.ColumnEntity in project hetu-core by openlookeng.
the class TestHetuFsMetastore method testAlterView.
/**
* test alter view
*/
@Test
public void testAlterView() {
String dbName15 = "db150";
DatabaseEntity db15 = DatabaseEntity.builder().setCatalogName(defaultCatalog.getName()).setDatabaseName(dbName15).build();
metastore.createDatabase(db15);
// alter view
String table131 = "table131";
TableEntity view = TableEntity.builder().setCatalogName(db15.getCatalogName()).setDatabaseName(db15.getName()).setTableName(table131).setTableType(TableEntityType.VIRTUAL_VIEW.toString()).setViewOriginalText(Optional.of(viewData)).setColumns(ImmutableList.of(new ColumnEntity(table131, parseTypeSignature(typeInt).toString(), "table131 column", emptyMap()))).build();
metastore.createTable(view);
String newViewName = "new131";
TableEntity newView = TableEntity.builder(view).setTableName(newViewName).setOwner(owner).setComment("alter view").setViewOriginalText(Optional.of("select * from t1")).setColumns(ImmutableList.of(new ColumnEntity(newViewName, parseTypeSignature(typeVarchar).toString(), "new131 column", emptyMap()))).build();
metastore.alterTable(view.getCatalogName(), view.getDatabaseName(), table131, newView);
Optional<TableEntity> newView1 = metastore.getTable(newView.getCatalogName(), newView.getDatabaseName(), newView.getName());
assertTrue(newView1.isPresent());
assertTableEquals(newView1.get(), newView);
assertEquals(newView1.get().getCreateTime(), view.getCreateTime());
}
use of io.prestosql.spi.metastore.model.ColumnEntity in project hetu-core by openlookeng.
the class JdbcHetuMetastore method getTableColumns.
private void getTableColumns(List<Map.Entry<Long, TableEntity>> tableEntries, ImmutableList.Builder<TableEntity> tables, JdbcMetadataDao transactionDao) {
tableEntries.forEach(entry -> {
TableEntity table = entry.getValue();
List<ColumnEntity> columns = transactionDao.getAllColumns(entry.getKey());
table.setColumns(columns);
tables.add(table);
});
}
use of io.prestosql.spi.metastore.model.ColumnEntity in project hetu-core by openlookeng.
the class StarTreeMetaStore method convertTablesToMetadata.
private List<CubeMetadata> convertTablesToMetadata(List<TableEntity> tableEntities) {
List<CubeMetadata> cubeMetadataList = new ArrayList<>();
tableEntities.forEach(table -> {
List<ColumnEntity> cols = table.getColumns();
StarTreeMetadataBuilder builder = new StarTreeMetadataBuilder(table.getParameters().get(STAR_TABLE_NAME), table.getParameters().get(SOURCE_TABLE_NAME));
cols.forEach(col -> {
if (col.getType().equals("aggregate")) {
builder.addAggregationColumn(col.getName(), col.getParameters().get("aggregateFunction"), col.getParameters().get(ORIGINAL_COLUMN), Boolean.parseBoolean(col.getParameters().get("distinct")));
} else if (col.getType().equals("dimension")) {
builder.addDimensionColumn(col.getName(), col.getParameters().get(ORIGINAL_COLUMN));
}
});
String groupingString = table.getParameters().get(GROUPING_STRING);
// Create empty set to support Empty Group
builder.addGroup((groupingString == null || groupingString.isEmpty()) ? new HashSet<>() : Sets.newHashSet(groupingString.split(COLUMN_DELIMITER)));
String sourceTablePredicate = table.getParameters().get(SOURCE_FILTER_STRING);
String cubePredicate = table.getParameters().get(PREDICATE_STRING);
if (sourceTablePredicate != null || cubePredicate != null) {
builder.withCubeFilter(new CubeFilter(sourceTablePredicate, cubePredicate));
}
builder.setCubeStatus(CubeStatus.forValue(Integer.parseInt(table.getParameters().get(CUBE_STATUS))));
builder.setTableLastUpdatedTime(Long.parseLong(table.getParameters().get(SOURCE_TABLE_LAST_UPDATED_TIME)));
builder.setCubeLastUpdatedTime(Long.parseLong(table.getParameters().get(CUBE_LAST_UPDATED_TIME)));
cubeMetadataList.add(builder.build());
});
return cubeMetadataList;
}
Aggregations