Search in sources :

Example 21 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class MySqlTagService method rename.

@Override
public Void rename(final QualifiedName name, final String newTableName) {
    try {
        final Connection conn = getDataSource().getConnection();
        try {
            final QualifiedName newName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), newTableName);
            new QueryRunner().update(conn, SQL_UPDATE_TAG_ITEM, newName.toString(), name.toString());
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
    } catch (SQLException e) {
        final String message = String.format("Failed to rename item name %s", name);
        log.error(message, e);
        throw new UserMetadataServiceException(message, e);
    }
    return null;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) SQLException(java.sql.SQLException) QualifiedName(com.netflix.metacat.common.QualifiedName) Connection(java.sql.Connection) QueryRunner(org.apache.commons.dbutils.QueryRunner) SQLException(java.sql.SQLException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)

Example 22 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class HiveConvertersImpl method metacatToHiveTable.

/**
     * {@inheritDoc}
     */
@Override
public Table metacatToHiveTable(final TableDto dto) {
    final Table table = new Table();
    String tableName = "";
    String databaseName = "";
    final QualifiedName name = dto.getName();
    if (name != null) {
        tableName = name.getTableName();
        databaseName = name.getDatabaseName();
    }
    table.setTableName(tableName);
    table.setDbName(databaseName);
    final StorageDto storageDto = dto.getSerde();
    String owner = "";
    if (storageDto != null && storageDto.getOwner() != null) {
        owner = storageDto.getOwner();
    }
    table.setOwner(owner);
    final AuditDto auditDto = dto.getAudit();
    if (auditDto != null && auditDto.getCreatedDate() != null) {
        table.setCreateTime(dateToEpochSeconds(auditDto.getCreatedDate()));
    }
    Map<String, String> params = new HashMap<>();
    if (dto.getMetadata() != null) {
        params = dto.getMetadata();
    }
    table.setParameters(params);
    // TODO get this
    table.setTableType("EXTERNAL_TABLE");
    table.setSd(fromStorageDto(storageDto));
    final StorageDescriptor sd = table.getSd();
    final List<FieldDto> fields = dto.getFields();
    if (fields == null) {
        table.setPartitionKeys(Collections.emptyList());
        sd.setCols(Collections.emptyList());
    } else {
        final List<FieldSchema> nonPartitionFields = Lists.newArrayListWithCapacity(fields.size());
        final List<FieldSchema> partitionFields = Lists.newArrayListWithCapacity(fields.size());
        for (FieldDto fieldDto : fields) {
            final FieldSchema f = metacatToHiveField(fieldDto);
            if (fieldDto.isPartition_key()) {
                partitionFields.add(f);
            } else {
                nonPartitionFields.add(f);
            }
        }
        table.setPartitionKeys(partitionFields);
        sd.setCols(nonPartitionFields);
    }
    return table;
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) AuditDto(com.netflix.metacat.common.dto.AuditDto) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) StorageDto(com.netflix.metacat.common.dto.StorageDto) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Example 23 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class HiveConvertersImpl method metacatToHiveDatabase.

/**
     * {@inheritDoc}
     */
@Override
@SuppressWarnings("unchecked")
public Database metacatToHiveDatabase(final DatabaseDto dto) {
    final Database database = new Database();
    String name = "";
    String description = "";
    final QualifiedName databaseName = dto.getName();
    if (databaseName != null) {
        name = databaseName.getDatabaseName();
        // Since this is required setting it to the same as the DB name for now
        description = databaseName.getDatabaseName();
    }
    database.setName(name);
    database.setDescription(description);
    String dbUri = dto.getUri();
    if (Strings.isNullOrEmpty(dbUri)) {
        dbUri = "";
    }
    database.setLocationUri(dbUri);
    Map<String, String> metadata = dto.getMetadata();
    if (metadata == null) {
        metadata = Collections.EMPTY_MAP;
    }
    database.setParameters(metadata);
    return database;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) Database(org.apache.hadoop.hive.metastore.api.Database)

Example 24 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class CatalogThriftHiveMetastore method alter_table_with_environment_context.

/**
     * {@inheritDoc}
     */
@Override
public void alter_table_with_environment_context(final String dbname, final String tblName, final Table newTbl, @Nullable final EnvironmentContext environmentContext) throws TException {
    requestWrapper("alter_table_with_environment_context", new Object[] { dbname, tblName, newTbl, environmentContext }, () -> {
        final String databaseName = normalizeIdentifier(dbname);
        final String tableName = normalizeIdentifier(tblName);
        final QualifiedName oldName = QualifiedName.ofTable(catalogName, databaseName, tableName);
        final QualifiedName newName = QualifiedName.ofTable(catalogName, newTbl.getDbName(), newTbl.getTableName());
        final TableDto dto = hiveConverters.hiveToMetacatTable(newName, newTbl);
        if (!oldName.equals(newName)) {
            v1.renameTable(catalogName, oldName.getDatabaseName(), oldName.getTableName(), newName.getTableName());
        }
        v1.updateTable(catalogName, dbname, newName.getTableName(), dto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 25 with QualifiedName

use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.

the class CatalogThriftHiveMetastore method create_table_with_environment_context.

/**
     * {@inheritDoc}
     */
@Override
public void create_table_with_environment_context(final Table tbl, @Nullable final EnvironmentContext environmentContext) throws TException {
    requestWrapper("create_table_with_environment_context", new Object[] { tbl, environmentContext }, () -> {
        final String dbname = normalizeIdentifier(tbl.getDbName());
        final String tblName = normalizeIdentifier(tbl.getTableName());
        final QualifiedName name = QualifiedName.ofTable(catalogName, dbname, tblName);
        final TableDto dto = hiveConverters.hiveToMetacatTable(name, tbl);
        v1.createTable(catalogName, dbname, tblName, dto);
        return null;
    });
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Aggregations

QualifiedName (com.netflix.metacat.common.QualifiedName)85 List (java.util.List)31 Lists (com.google.common.collect.Lists)25 Collectors (java.util.stream.Collectors)24 Map (java.util.Map)23 Nonnull (javax.annotation.Nonnull)23 Strings (com.google.common.base.Strings)20 Slf4j (lombok.extern.slf4j.Slf4j)20 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)19 TableDto (com.netflix.metacat.common.dto.TableDto)19 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)17 Pageable (com.netflix.metacat.common.dto.Pageable)16 Sort (com.netflix.metacat.common.dto.Sort)16 Maps (com.google.common.collect.Maps)14 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)14 NonNull (lombok.NonNull)14 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)13 Nullable (javax.annotation.Nullable)13 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)12