Search in sources :

Example 1 with ColumnEntity

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

Example 2 with ColumnEntity

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;
}
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 3 with ColumnEntity

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());
}
Also used : ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) Test(org.testng.annotations.Test)

Example 4 with ColumnEntity

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);
    });
}
Also used : ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) TableEntity(io.prestosql.spi.metastore.model.TableEntity)

Example 5 with ColumnEntity

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;
}
Also used : StarTreeMetadataBuilder(io.hetu.core.cube.startree.tree.StarTreeMetadataBuilder) ColumnEntity(io.prestosql.spi.metastore.model.ColumnEntity) ArrayList(java.util.ArrayList) CubeFilter(io.hetu.core.spi.cube.CubeFilter) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) HashSet(java.util.HashSet)

Aggregations

ColumnEntity (io.prestosql.spi.metastore.model.ColumnEntity)14 TableEntity (io.prestosql.spi.metastore.model.TableEntity)11 DatabaseEntity (io.prestosql.spi.metastore.model.DatabaseEntity)8 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)5 PrestoException (io.prestosql.spi.PrestoException)4 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)4 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Throwables.throwIfUnchecked (com.google.common.base.Throwables.throwIfUnchecked)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Injector (com.google.inject.Injector)2 Bootstrap (io.airlift.bootstrap.Bootstrap)2 Logger (io.airlift.log.Logger)2 LOCAL (io.hetu.core.metastore.MetaStoreConstants.LOCAL)2 HBaseColumnHandle (io.hetu.core.plugin.hbase.connector.HBaseColumnHandle)2 MBeanServerModule (io.prestosql.plugin.base.jmx.MBeanServerModule)2